This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AppstoreUpdateManager.swift | |
// AppStoreUpdateManager | |
// | |
// Created by Karthik on 7/27/18. | |
// Copyright © 2018 Karthik. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// AttachmentHandler.swift | |
// AttachmentHandler | |
// | |
// Created by Deepak on 25/01/18. | |
// Copyright © 2018 Deepak. All rights reserved. | |
// | |
import Foundation | |
import UIKit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { } | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]? |
NewerOlder