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
extension UISpringTimingParameters { | |
public convenience init(dampingRatio: CGFloat, frequencyResponse: CGFloat) { | |
precondition(dampingRatio >= 0) | |
precondition(frequencyResponse > 0) | |
let mass = 1 as CGFloat | |
let stiffness = pow(2 * .pi / frequencyResponse, 2) * mass | |
let damping = 4 * .pi * dampingRatio * mass / frequencyResponse | |
self.init(mass: mass, stiffness: stiffness, damping: damping, initialVelocity: .zero) |
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 ImageKit: NSObject { | |
private let group:DispatchGroup = DispatchGroup() | |
override init() { | |
super.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
let group:DispatchGroup = DispatchGroup() | |
group.enter() // entryCount = 1 | |
iAmLongRunningFunc { | |
group.leave() // entryCount = 0 | |
} | |
group.enter() // entryCount = 1 | |
iAmLongRunningFunc { | |
group.leave() // entryCount = 0 |
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
guard let jsonDct:[String:Any] = readJsonFile() , let arrCategoriesDct:[[String:Any]] = jsonDct["categories"] as? [[String:Any]] else { return } | |
let categories:[Category] = arrCategoriesDct.compactMap { dct -> Category? in | |
return Category(dct: dct) | |
} | |
var completedCount:Int = 0 | |
categories.forEach { category in | |
self.asyncTask(imageURL: category.thumbnailImage, completion: { image in | |
completedCount += 1 | |
if completedCount == categories.count { |
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
extension String { | |
static var documentsPath:String { | |
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask) | |
let documentsDirectory = paths[0] | |
return documentsDirectory.path | |
} | |
var filePathAtDocumentsDirectory:String { | |
let docPath = String.documentsPath |