Slide 1

Slide 1 text

NDS meetup #1 2014.07.13 Sun. dictav

Slide 2

Slide 2 text

Swift “Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility. ” Excerpt From: Apple Inc. “The Swift Programming Language.” iBooks. https://itun.es/jp/jEUH0.l Swift ެࣜ: https://developer.apple.com/swift/

Slide 3

Slide 3 text

࡞ऀ • Chris Lattner • Apple Engineer • http://www.nondot.org/sabre/

Slide 4

Slide 4 text

Objective-C • 1983೥ੜ·ΕʢC++ͱಉ͡ʣ • C ͷεʔύʔηοτ • C++: better C • Objective-C: C & Object System • runtime + Foundation framework (+ AppKit)

Slide 5

Slide 5 text

Objective-C #import @interface MyObject : NSObject @end @implementation MyObject - (void) helloWorld { printf("Hello, World!\n"); } @end int main(int argc, char **argv) { id obj = [MyObject new]; [obj helloWorld]; return 0; }

Slide 6

Slide 6 text

Swift import Foundation class MyObject { func helloWorld() { println("hello, World!") } } let obj = MyObject() obj.helloWorld() exit(0)

Slide 7

Slide 7 text

ΏΔ͞΋࢒ͭͭ͠

Slide 8

Slide 8 text

Objective-C @interface NSString (MyMethod) @end @implementation NSString (MyMethod) - (void)url { [NSURL URLWithString:self]; } @end

Slide 9

Slide 9 text

Swift extension NSString { func url() -> NSURL { return NSURL(string: self) } }

Slide 10

Slide 10 text

Cͷढറ͔Βͷղ์

Slide 11

Slide 11 text

Objective-C char *source = "I love Objective-C"; NSString *string = [NSString stringWithUTF8String:source]; NSString *string2 = @"I love Objective-C"; NSNumber *num = @1; for( int n = 0; n < 100; n++) { num = @(num.integerValue + n); } NSArray *array = @[string, string2, num]; NSDictionary *dict = @{ @"str":string, @"str2":string2, @"num":num};

Slide 12

Slide 12 text

Swift let string = "I love Swift" var num = 1 for (var n = 0; n < 100; n++) { num += n } let array = [string, num] let dict = ["string":string, "num":num]

Slide 13

Slide 13 text

࣌ʹ͸ݫ͘͠

Slide 14

Slide 14 text

Objective-C @protocol MyProtocol - (void)helloWorld; @end @interface MyObject : NSObject @end @implementation MyObject - (void) helloWorld { NSLog(@"Hello, World! (TestLib)"); } @end

Slide 15

Slide 15 text

Objective-C NSMutableArray *array = [NSMutableArray new]; [array addObject:[MyObject new]]; [array addObject:[NSObject new]]; // ΤϥʔʹͳΒͳ͍ʂ [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [obj helloWorld];// ͜͜Ͱ࣮ߦ࣌Τϥʔʂ }]; MyObject *objects[2]; objects[0] = [MyObject new]; objects[1] = [NSObject new]; // warning

Slide 16

Slide 16 text

Swift protocol MyProtocol { func helloWorld() } class MyObject : MyProtocol { func helloWorld() { println("hello,world") } } var objects = Array() objects.append(MyObject()) objects.append(NSObject()) // ίϯύΠϧΤϥʔ

Slide 17

Slide 17 text

มΘΒ͵GCD

Slide 18

Slide 18 text

Objective-C dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_async(queue, ^{ NSLog(@"hello"); }); NSOperationQueue *opQueue = [NSOperationQueue new]; [opQueue addOperationWithBlock:^{ NSLog(@"hello"); }];

Slide 19

Slide 19 text

Swift let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) dispatch_async(queue){ println("hello") } let opQueue = NSOperationQueue(); opQueue.addOperationWithBlock{ println("hello") }

Slide 20

Slide 20 text

Cͱ΋஥ྑ͠

Slide 21

Slide 21 text

Objective-C #import

Slide 22

Slide 22 text

Swift -FUT(P4XJGU#SJEHJOH)FBEFSI /* Go ͸ίϝϯτͰॻ͍ͨΓ͠·͢Ͷ // #include // #include import "C" */ #import

Slide 23

Slide 23 text

Swift͸ίϚϯυԽͰ͖Δ

Slide 24

Slide 24 text

Swift #!/Applications/Xcode6-Beta3.app/Contents/Developer/ usr/bin/xcrun swift -i println("hello")

Slide 25

Slide 25 text

ͦ͏͍΍ try-catch ͳ͍ͳ

Slide 26

Slide 26 text

୭͕Swift࢖͏ͷʁ • ΧδϡΞϧͳήʔϜϓϩάϥϛϯά • Objective-Cʹৄ͍͠ઌୡ

Slide 27

Slide 27 text

stackoverflow