Skip to content

Instantly share code, notes, and snippets.

View damodarnamala's full-sized avatar

Damodar damodarnamala

  • Hyderabad
View GitHub Profile
@damodarnamala
damodarnamala / AVPlayer+Scrubbing.swift
Created September 16, 2022 04:24 — forked from shaps80/AVPlayer+Scrubbing.swift
Enables smooth frame-by-frame scrubbing (in both directions) – similar to Apple's applications.
public enum Direction {
case forward
case backward
}
internal var player: AVPlayer?
private var isSeekInProgress = false
private var chaseTime = kCMTimeZero
private var preferredFrameRate: Float = 23.98
@damodarnamala
damodarnamala / NotesApp.swift
Created September 16, 2022 04:06 — forked from jnewc/NotesApp.swift
A notes app written in >100 lines of swift using SwiftUI
import SwiftUI
let dateFormatter = DateFormatter()
struct NoteItem: Codable, Hashable, Identifiable {
let id: Int
let text: String
var date = Date()
var dateText: String {
dateFormatter.dateFormat = "MMM d yyyy, h:mm a"
import XCTest
struct Scenario: ScenarioGivenContinuation, ScenarioWhenContinuation {
init(_ description: String) {
print("Scenario: \(description)")
}
struct Given: ScenarioWhenContinuation {
fileprivate init(description: String, setup: () throws -> Void) rethrows {
@damodarnamala
damodarnamala / Channel.swift
Created September 16, 2022 03:53 — forked from gokselkoksal/Channel.swift
Channel implementation
public class Channel<Value> {
private class Subscription {
weak var object: AnyObject?
private let notifyBlock: (Value) -> Void
private let queue: DispatchQueue
var isValid: Bool {
return object != nil
@damodarnamala
damodarnamala / Makefile
Created September 16, 2022 03:52 — forked from oleander/Makefile
How to use the Swift Package Manager and CocoaPods within the same XCode application
APP="MyApp"
CONSTRUCT=xcodebuild -workspace $(APP).xcworkspace -scheme $(APP) clean
install_deps:
pod install
create_config:
swift package fetch
swift package generate-xcodeproj
wipe:
rm -rf .build $(APP).xcodeproj $(APP).xcworkspace Package.pins Pods Podfile.lock
@damodarnamala
damodarnamala / FormattedTextField.swift
Created September 16, 2022 03:51 — forked from darrarski/FormattedTextField.swift
SwiftUI FormattedTextField - TextField with custom display/edit formatters
import SwiftUI
public struct FormattedTextField<Formatter: TextFieldFormatter>: View {
public init(_ title: String,
value: Binding<Formatter.Value>,
formatter: Formatter) {
self.title = title
self.value = value
self.formatter = formatter
}
@damodarnamala
damodarnamala / TrimVideo.swift
Created September 16, 2022 03:50 — forked from acj/TrimVideo.swift
Trim video using AVFoundation in Swift
//
// TrimVideo.swift
// VideoLab
//
// Created by Adam Jensen on 3/28/15.
// Updated for Swift 5 (tested with Xcode 10.3) on 7/30/19.
// MIT license
//
import AVFoundation
@damodarnamala
damodarnamala / Delegate.swift
Created September 16, 2022 03:49 — forked from onevcat/Delegate.swift
An auto-weak delegate for handle modern delegate pattern.
import Foundation
/// A class that keeps a weakly reference for `self` when implementing `onXXX` behaviors.
/// Instead of remembering to keep `self` as weak in a stored closure:
///
/// ```swift
/// // MyClass.swift
/// var onDone: (() -> Void)?
/// func done() {
/// onDone?()
@damodarnamala
damodarnamala / cross-view-lines.swift
Created September 16, 2022 03:47 — forked from bjhomer/cross-view-lines.swift
Creating cross-view lines in SwiftUI
//
// ContentView.swift
// SwiftUIPlayground
//
// Created by BJ Homer on 4/26/21.
//
import SwiftUI
@damodarnamala
damodarnamala / CombineFetcher.swift
Created September 16, 2022 03:47 — forked from stinger/CombineFetcher.swift
Combine - fetching data using URLSession publishers
import Foundation
import Combine
enum APIError: Error, LocalizedError {
case unknown, apiError(reason: String)
var errorDescription: String? {
switch self {
case .unknown:
return "Unknown error"