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
override func viewDidLoad() { | |
super.viewDidLoad() | |
setText() | |
NSNotificationCenter.defaultCenter().addObserver(self, selector: "setText", name: LCLLanguageChangeNotification, object: nil) | |
} | |
@IBAction func IndexChanged(sender: UISegmentedControl) { | |
let language: String | |
switch self.LangChoser.selectedSegmentIndex | |
{ |
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
// Apple's previewing API | |
viewController.registerForPreviewingWithDelegate(self, sourceView: sourceView) | |
func previewingContext(previewingContext: UIViewControllerPreviewing, viewControllerForLocation location: CGPoint) -> UIViewController? | |
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) | |
// PeekPop's previewing API |
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
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
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
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
// 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) |
OlderNewer