Skip to content

Instantly share code, notes, and snippets.

View karthikAdaptavant's full-sized avatar
🎯
Focusing

Karthik samy karthikAdaptavant

🎯
Focusing
  • 15:19 (UTC +05:30)
View GitHub Profile
@conradev
conradev / NavigationStackView.swift
Last active May 16, 2023 09:55
NavigationStackView
import SwiftUI
@main
struct ExampleApp: App {
var body: some Scene {
WindowGroup {
OnboardingView()
}
}
}
import UIKit
// According to article by John Sundell
// https://www.swiftbysundell.com/articles/caching-in-swift/
final class Cache<Key: Hashable, Value> {
private let wrapped = NSCache<WrappedKey, Entry>()
private let dateProvider: () -> Date
private let entryLifetime: TimeInterval
private let keyTracker = KeyTracker()
//
// AppstoreUpdateManager.swift
// AppStoreUpdateManager
//
// Created by Karthik on 7/27/18.
// Copyright © 2018 Karthik. All rights reserved.
//
import Foundation
import UIKit
/// Something that can be created in a core data context, usually an `NSManagedObject`.
public protocol CDCreatable {
/// Creates this object in the context given.
///
/// - Parameter context: Managed object context.
/// - Remarks: Default constructor generated by `NSManagedObject`.
/// - Warning: When creating objects, use `init(createIn:)` instead as it may contain additional initilization logic.
init(context: NSManagedObjectContext)
/// Creates this object in the context given.
@artemnovichkov
artemnovichkov / Optional+Operators.swift
Last active July 30, 2018 15:16
Addition and subtraction operators for Swift Optionals
func +=<T>(lhs: inout T?, rhs: T) where T: SignedNumeric {
switch lhs {
case .none:
break
case .some(let value):
lhs = .some(value + rhs)
}
}
func -=<T>(lhs: inout T?, rhs: T) where T: SignedNumeric {
@gokselkoksal
gokselkoksal / Channel.swift
Last active September 16, 2022 03:53
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
@deepakraj27
deepakraj27 / AttachmentHandler.swift
Last active November 1, 2023 08:40
Access Camera, Photo Library, Video and File from User device using Swift 4
//
// AttachmentHandler.swift
// AttachmentHandler
//
// Created by Deepak on 25/01/18.
// Copyright © 2018 Deepak. All rights reserved.
//
import Foundation
import UIKit
@mwrites
mwrites / JobQueueCenter.swift
Last active June 2, 2019 12:49
JobQueue Implementation in Swift
//MARK: -
//MARK: Private
class JobQueueCenter {
fileprivate let storageAccessQueue = DispatchQueue(label: "com.JobQueueCenter.storageAccessQueue")
fileprivate lazy var storage: JobQueueStorage = { ... }
fileprivate func serializeStorage() {}
fileprivate init() {
NotificationCenter.default.addObserver(self, selector: #selector(tryPersist), name: .UIApplicationDidReceiveMemoryWarning, object: nil)
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }
@jochenschoellig
jochenschoellig / ChatCollectionViewFlowLayout.swift
Created January 19, 2017 15:49
A subclass of UICollectionViewFlowLayout to get chat behavior without turning collection view upside-down. This layout is written in Swift 3 and absolutely usable with RxSwift and RxDataSources because UI is completely separated from any logic or binding.
import UIKit
class ChatCollectionViewFlowLayout: UICollectionViewFlowLayout {
private var topMostVisibleItem = Int.max
private var bottomMostVisibleItem = -Int.max
private var offset: CGFloat = 0.0
private var visibleAttributes: [UICollectionViewLayoutAttributes]?