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
// Set up your app's URL Types and URL schemes. | |
// Add the following to your AppDelegate: | |
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { | |
SpotifyLogin.shared.configure(clientID: <#T##String#>, clientSecret: <#T##String#>, redirectURL: <#T##URL#>) | |
return true | |
} | |
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { |
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 mapViewClass = ObjectiveClass<MKMapView>() | |
let selectors = mapViewClass.selectors // An array of selectors. | |
let properties = mapViewClass.properties // An array of properties. | |
mapViewClass.addSelector(#selector(testSelector), from: self.classForCoder) |
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 workItem = DispatchWorkItem(qos: .userInitiated, flags: .assignCurrentContext) { | |
// Do stuff | |
} | |
queue.async(execute: workItem) |
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 queue = DispatchQueue.global(attributes: .qosUserInitiated) | |
let mainQueue = DispatchQueue.main | |
mainQueue.async { | |
dispatchPrecondition(condition: .notOnQueue(mainQueue)) | |
// This code won't execute | |
} | |
queue.async { | |
dispatchPrecondition(condition: .onQueue(queue)) |
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 delay = DispatchTime.now() + .seconds(60) | |
DispatchQueue.main.after(when: delay) { | |
// Do something | |
} |
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
DispatchQueue.global(attributes: [.qosDefault]).async { | |
// Background thread | |
DispatchQueue.main.async(execute: { | |
// UI Updates | |
}) | |
} |
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
// Examples of dispatch_once replacements with global or static constants and variables. | |
// In all three, the initialiser is called only once. | |
// Static properties (useful for singletons). | |
class Object { | |
static let sharedInstance = Object() | |
} | |
// Global constant. | |
let constant = Object() |
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
// Create a UIViewPropertyAnimator object. Here's a simple one with a UIKit animation curve: | |
let colorChange = UIViewPropertyAnimator(duration: 0.3, curve: .easeIn, animations: { [weak self] in | |
self?.view.backgroundColor = UIColor(red: 255.0/255.0, green: 80.0/255.0, blue: 43.0/255.0, alpha: 1.0) | |
}) | |
// There's also support for easy spring-based animations - all you need to set is a damping ratio (a value between 0 and 1). Alternatively, you can create your own curves by adopting the UITimingCurveProvider protocol. | |
let alphaChange = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 0.6, animations: { [weak self] in | |
self?.circleView.alpha = 0.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
// Create interpolation object | |
let colorChange = Interpolate(from: UIColor.whiteColor(), to: UIColor.redColor(), apply: { [weak self] (color) in | |
self?.view.backgroundColor = color | |
}) | |
// For a gesture recognizer or delegate that reports every step of its progress (e.g. UIPanGestureRecognizer or a ScrollViewDidScroll) you can just apply the percentage directly to the Interpolate object | |
@IBAction func handlePan(recognizer: UIPanGestureRecognizer) { | |
let translation = recognizer.translationInView(self.view) | |
let translatedCenterY = view.center.y + translation.y | |
let progress = translatedCenterY / self.view.bounds.size.height |
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 altitude = distance*tan(M_PI*(75.0/180.0)) |
NewerOlder