int (^add)(int, int) = ^(int x, int y) {
return x + y;
};
add(1, 2);
@interface Hoge : NSObject
@property (copy) int (^block)(int, int);
@property (copy) NSString *title;
- (void)fuga:(int(^)(int, int))block;
@end
Objective-C
Slide 16
Slide 16 text
fuckingblocksyntax.com
Slide 17
Slide 17 text
Swift
let add = { (x: Int, y: Int) -> Int in
return x + y
}
add(1, 2)
class Hoge: NSObject {
var closure: (Int, Int) -> Int
var title: String
func fuga(closure: (Int, Int) -> Int) {
// ...
}
}
ૉʹΔͱ͜͏ͳΔ
let jsonObject : AnyObject! =
NSJSONSerialization.JSONObjectWithData(dataFromTwitter,
options: NSJSONReadingOptions.MutableContainers, error: nil)
if let statusesArray = jsonObject as? NSArray {
if let aStatus = statusesArray[0] as? NSDictionary {
if let user = aStatus["user"] as? NSDictionary {
if let userName = user["name"] as? NSString {
//Finally We Got The Name
}
}
}
}
Slide 33
Slide 33 text
MantleͳΒ͜͏
let entries =
MTLJSONAdapter.modelsOfClass(BookmarkEntry.self,
fromJSONArray: JSONEntries,
error: nil)
return entries as [BookmarkEntry]