CocoaPods project setup
Create a Podfile at the root of your project
platform :ios, '5.0'
pod 'AFNetworking'
pod 'OHAttributedLabel'| /* Read this comment first: https://gist.github.com/tonious/1377667#gistcomment-2277101 | |
| * 2017-12-05 | |
| * | |
| * -- T. | |
| */ | |
| #define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */ | |
| #include <stdlib.h> | |
| #include <stdio.h> |
| Latency Comparison Numbers (~2012) | |
| ---------------------------------- | |
| L1 cache reference 0.5 ns | |
| Branch mispredict 5 ns | |
| L2 cache reference 7 ns 14x L1 cache | |
| Mutex lock/unlock 25 ns | |
| Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
| Compress 1K bytes with Zippy 3,000 ns 3 us | |
| Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
| Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
Create a Podfile at the root of your project
platform :ios, '5.0'
pod 'AFNetworking'
pod 'OHAttributedLabel'| #import <Foundation/Foundation.h> | |
| @interface MyCalendar : NSObject | |
| + (void)requestAccess:(void (^)(BOOL granted, NSError *error))success; | |
| + (BOOL)addEventAt:(NSDate*)eventDate withTitle:(NSString*)title inLocation:(NSString*)location; | |
| @end |
| // Imagine shooting an arrow to a point | |
| CGMutablePathRef path = CGPathCreateMutable(); | |
| // This will move an invisible path marker to a starting point | |
| // In my case, the node is a child node of a sprite, so it is the local coords and not the screen coords | |
| CGPathMoveToPoint(path, NULL, 10, 0); | |
| // The 3-8th parameters are x/y coords. The arrow iwll first hit x:100 and y:50. | |
| // It will then raise up a bit as it keeps going and finally drop to the target at x:300 y:0 | |
| CGPathAddCurveToPoint(path, NULL, |
| //Copyright (c) 2014 Tilman Schmidt (@KeyMaster_) | |
| //Permission is hereby granted, free of charge, to any person obtaining a copy | |
| //of this software and associated documentation files (the "Software"), to deal | |
| //in the Software without restriction, including without limitation the rights | |
| //to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
| //copies of the Software, and to permit persons to whom the Software is | |
| //furnished to do so, subject to the following conditions: | |
| //The above copyright notice and this permission notice shall be included in |
Suppose we want to add support for a new iOS 8 API in our framework that replaces an older iOS 7 API. There are a few problems we might face:
These three problems require three different technical solutions:
respondsToSelector:)__IPHONE_OS_VERSION_MAX_ALLOWED macro| func loopTrack(musicTrack:MusicTrack) { | |
| var trackLength = getTrackLength(musicTrack) | |
| println("track length is \(trackLength)") | |
| setTrackLoopDuration(musicTrack, duration: trackLength) | |
| } | |
| func getTrackLength(musicTrack:MusicTrack) -> MusicTimeStamp { | |
| //The time of the last music event in a music track, plus time required for note fade-outs and so on. |
| func generateRandomColor() -> UIColor { | |
| let hue : CGFloat = CGFloat(arc4random() % 256) / 256 // use 256 to get full range from 0.0 to 1.0 | |
| let saturation : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from white | |
| let brightness : CGFloat = CGFloat(arc4random() % 128) / 256 + 0.5 // from 0.5 to 1.0 to stay away from black | |
| return UIColor(hue: hue, saturation: saturation, brightness: brightness, alpha: 1) | |
| } |
| func checkShouldDownloadFileAtLocation(urlString:String, completion:((shouldDownload:Bool) -> ())?) { | |
| var request = NSMutableURLRequest(URL: NSURL(string: urlString)!) | |
| request.HTTPMethod = "HEAD" | |
| var session = NSURLSession.sharedSession() | |
| var err: NSError? | |
| var task = session.dataTaskWithRequest(request, completionHandler: { [weak self] data, response, error -> Void in | |
| if let strongSelf = self { | |
| var isModified = false |