Skip to content

Instantly share code, notes, and snippets.

View marmelroy's full-sized avatar

Roy Marmelstein marmelroy

View GitHub Profile
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
{
// 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
@marmelroy
marmelroy / PeekPop.swift
Created March 15, 2016 05:14
PeekPop vs Peeking and Popping
// 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
// 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()
DispatchQueue.global(attributes: [.qosDefault]).async {
// Background thread
DispatchQueue.main.async(execute: {
// UI Updates
})
}
let delay = DispatchTime.now() + .seconds(60)
DispatchQueue.main.after(when: delay) {
// Do something
}
let workItem = DispatchWorkItem(qos: .userInitiated, flags: .assignCurrentContext) {
// Do stuff
}
queue.async(execute: workItem)
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))
@marmelroy
marmelroy / SpotifyLoginSample.swift
Created August 31, 2017 14:39
SpotifyLoginSample.swift
// 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 {
@marmelroy
marmelroy / objectiveKit.swift
Last active May 24, 2019 15:11
ObjectiveKit.swift
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)