This file contains hidden or 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
| function withHook(Component) { | |
| return function WrappedComponent(props) { | |
| const useReducer = React.useReducer(reducer, initialState); | |
| return <Component {...props} useReducer={useReducer}/> | |
| } | |
| } |
This file contains hidden or 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 | |
| extension UIColor { | |
| convenience init(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1.0) { | |
| self.init(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a) | |
| } | |
| convenience init(red: Int, green: Int, blue: Int, a: Int = 0xFF) { | |
| assert(red >= 0 && red <= 255, "Invalid red component") | |
| assert(green >= 0 && green <= 255, "Invalid green component") |
This file contains hidden or 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
| # Created by https://www.gitignore.io/api/osx,swift,objective-c,xcode | |
| # Edit at https://www.gitignore.io/?templates=osx,swift,objective-c,xcode | |
| ### Objective-C ### | |
| # Xcode | |
| # | |
| # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore | |
| ## Build generated |
This file contains hidden or 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
| extension String { | |
| public subscript (range: PartialRangeFrom<Int>) -> Substring { | |
| return self[index(startIndex, offsetBy: range.lowerBound)..<endIndex] | |
| } | |
| public subscript (range: PartialRangeUpTo<Int>) -> Substring { | |
| return self[startIndex..<index(endIndex, offsetBy: range.upperBound)] | |
| } | |
| public subscript (range: PartialRangeThrough<Int>) -> Substring { |
This file contains hidden or 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
| URLCache.shared = { | |
| let cacheDirectory = (NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] as String).appendingFormat("/\(Bundle.main.bundleIdentifier ?? "cache")/" ) | |
| return URLCache(memoryCapacity: /*your_desired_memory_cache_size*/, | |
| diskCapacity: /*your_desired_disk_cache_size*/, | |
| diskPath: cacheDirectory) | |
| }() |
This file contains hidden or 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 | |
| @UIApplicationMain | |
| class AppDelegate: UIResponder, UIApplicationDelegate { | |
| var window: UIWindow? | |
| func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| let diskCacheSize = 500*1024*1024 // 500MB |
This file contains hidden or 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
| extension URLCache { | |
| static func configSharedCache(directory: String? = Bundle.main.bundleIdentifier, memory: Int = 0, disk: Int = 0) { | |
| URLCache.shared = { | |
| let cacheDirectory = (NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true)[0] as String).appendingFormat("/\(directory ?? "cache")/" ) | |
| return URLCache(memoryCapacity: memory, diskCapacity: disk, diskPath: cacheDirectory) | |
| }() | |
| } | |
| } |
This file contains hidden or 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
| class UIAsyncImageView: UIImageView { | |
| // Associated Object property; implementation omitted. | |
| final private var imageUrl: URL? | |
| func loadImage(from urlString: String, placeholder: UIImage? = nil) { | |
| setImage(placeholder) | |
| guard let url = URL(string: urlString) else { | |
| return | |
| } |
This file contains hidden or 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
| class UIAsyncImageView: UIImageView { | |
| static let imageCache = NSCache<AnyObject, AnyObject>() | |
| // Associated Object property; implementation omitted. | |
| final private var imageUrl: URL? | |
| func loadImage(from urlString: String, placeholder: UIImage? = nil) { | |
| setImage(placeholder) | |
| guard let url = URL(string: urlString) else { |
This file contains hidden or 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
| class APIService: ServiceProtocol { | |
| func get( url: URL, callback: @escaping (_ data: Data?, _ error: Error?) -> Void ) { | |
| let request = URLRequest(url: url, cachePolicy: .returnCacheDataElseLoad, timeoutInterval: 30) | |
| URLSession.shared.dataTask(with: request) { (data, _, error) in | |
| callback(data, error) | |
| }.resume() | |
| } | |
| } |
NewerOlder