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
// example for http://stackoverflow.com/a/26261978/1271826 | |
// create scroll view | |
UIScrollView *scrollView = [[UIScrollView alloc] init]; | |
scrollView.translatesAutoresizingMaskIntoConstraints = NO; | |
[scrollViewSuperView addSubview:scrollView]; | |
// create container 1 |
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 NSMutableURLRequest { | |
/// Populate the HTTPBody of `application/x-www-form-urlencoded` request | |
/// | |
/// :param: contentMap A dictionary of keys and values to be added to the request | |
func setBodyContent(contentMap: [String : String]) { | |
let parameters = map(contentMap) { (key, value) -> String in | |
return "\(key)=\(value.stringByAddingPercentEscapesForQueryValue()!)" | |
} |
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 manager = AFHTTPSessionManager() | |
manager.GET("http://example.com/resources.json", parameters: nil, progress: nil, success: { (task: NSURLSessionDataTask, responseObject: AnyObject?) -> Void in | |
print("JSON: \(responseObject!)") | |
}, failure: { (task: NSURLSessionDataTask?, error: NSError) -> Void in | |
print("Error: %@", error) | |
}) |
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
// original class | |
class A { | |
var x: String | |
init(x: String) { | |
self.x = x | |
} | |
} | |
// new class |
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
func myFunction() -> NSArray { | |
var array: NSArray | |
Synchronized(someObject) { | |
// Stuff to do. | |
// don't "return" the array, here, but just set that local var above | |
} | |
return array // you can only "return" the `NSArray` object from outside the `Synchronized` closure | |
} |
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
var text: String! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
let url = NSBundle.mainBundle().URLForResource("test", withExtension: "json")! | |
var files = [String : NSFileWrapper]() | |
var error: NSError? | |
files["file.json"] = NSFileWrapper(URL: url, options: nil, error: &error) |
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
var thing = 0 | |
func hi() { | |
// Do something | |
thing++ | |
print(thing) | |
} | |
@IBAction func somethingHi(sender: AnyObject) { | |
hi() |
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
lazy var locationManager: CLLocationManager = { | |
let manager = CLLocationManager() | |
manager.requestWhenInUseAuthorization() | |
return manager | |
}() |
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
@IBAction func calculateButton(sender: AnyObject) { | |
if let value = Int(number.text!) { | |
var isPrime = true | |
if value == 1 { | |
isPrime = false | |
} | |
for var i = 2; i < value; i++ { | |
if value % i == 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
override func didMoveToView(view: SKView) { | |
let sprite = SKSpriteNode(imageNamed:"Spaceship") | |
sprite.xScale = 0.25 | |
sprite.yScale = 0.25 | |
addChild(sprite) | |
let origin = view.convertPoint(view.bounds.origin, toScene: self) | |
let lowerRight = view.convertPoint(CGPoint(x: CGRectGetMaxX(view.bounds), y:CGRectGetMaxY(view.bounds)), toScene: self) | |
let visibleFrame = CGRect(x: origin.x, y: origin.y, width: lowerRight.x - origin.x, height: lowerRight.y - origin.y) | |
let path = sinePathInRect(visibleFrame) |
OlderNewer