Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swiftを少しだけ
Search
Shintaro Abe
July 14, 2014
Programming
0
230
Swiftを少しだけ
NDS meetup 1 の資料
Swift について Objective-C との文法比較。
Shintaro Abe
July 14, 2014
Tweet
Share
More Decks by Shintaro Abe
See All by Shintaro Abe
アルコールストーブの作り方
dictav
0
290
NDS36 Objective-C
dictav
0
1.5k
Ruby
dictav
0
1.4k
Other Decks in Programming
See All in Programming
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
860
cmp.Or に感動した
otakakot
2
130
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.3k
ECS Service Connectのこれまでのアップデートと今後のRoadmapを見てみる
tkikuc
2
250
ローコードSaaSのUXを向上させるためのTypeScript
taro28
1
610
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
880
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
イベント駆動で成長して委員会
happymana
1
320
聞き手から登壇者へ: RubyKaigi2024 LTでの初挑戦が 教えてくれた、可能性の星
mikik0
1
130
Better Code Design in PHP
afilina
PRO
0
120
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
TypeScriptでライブラリとの依存を限定的にする方法
tutinoko
2
660
Featured
See All Featured
Gamification - CAS2011
davidbonilla
80
5k
Agile that works and the tools we love
rasmusluckow
327
21k
Building Adaptive Systems
keathley
38
2.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
How To Stay Up To Date on Web Technology
chriscoyier
788
250k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Building Flexible Design Systems
yeseniaperezcruz
327
38k
Speed Design
sergeychernyshev
24
610
Rails Girls Zürich Keynote
gr2m
94
13k
Practical Orchestrator
shlominoach
186
10k
Transcript
NDS meetup #1 2014.07.13 Sun. dictav
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/
࡞ऀ • Chris Lattner • Apple Engineer • http://www.nondot.org/sabre/
Objective-C • 1983ੜ·ΕʢC++ͱಉ͡ʣ • C ͷεʔύʔηοτ • C++: better C
• Objective-C: C & Object System • runtime + Foundation framework (+ AppKit)
Objective-C #import <Foundation/Foundation.h> @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; }
Swift import Foundation class MyObject { func helloWorld() { println("hello,
World!") } } let obj = MyObject() obj.helloWorld() exit(0)
ΏΔͭͭ͞͠
Objective-C @interface NSString (MyMethod) @end @implementation NSString (MyMethod) - (void)url
{ [NSURL URLWithString:self]; } @end
Swift extension NSString { func url() -> NSURL { return
NSURL(string: self) } }
Cͷढറ͔Βͷղ์
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};
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]
࣌ʹݫ͘͠
Objective-C @protocol MyProtocol <NSObject> - (void)helloWorld; @end @interface MyObject :
NSObject <MyProtocol> @end @implementation MyObject - (void) helloWorld { NSLog(@"Hello, World! (TestLib)"); } @end
Objective-C NSMutableArray *array = [NSMutableArray new]; [array addObject:[MyObject new]]; [array
addObject:[NSObject new]]; // ΤϥʔʹͳΒͳ͍ʂ [array enumerateObjectsUsingBlock:^(id<MyProtocol> obj, NSUInteger idx, BOOL *stop) { [obj helloWorld];// ͜͜Ͱ࣮ߦ࣌Τϥʔʂ }]; MyObject *objects[2]; objects[0] = [MyObject new]; objects[1] = [NSObject new]; // warning
Swift protocol MyProtocol { func helloWorld() } class MyObject :
MyProtocol { func helloWorld() { println("hello,world") } } var objects = Array<MyObject>() objects.append(MyObject()) objects.append(NSObject()) // ίϯύΠϧΤϥʔ
มΘΒ͵GCD
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"); }];
Swift let queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) dispatch_async(queue){ println("hello") } let
opQueue = NSOperationQueue(); opQueue.addOperationWithBlock{ println("hello") }
Cͱྑ͠
Objective-C #import <stdio.h>
Swift -FUT(P4XJGU#SJEHJOH)FBEFSI /* Go ίϝϯτͰॻ͍ͨΓ͠·͢Ͷ // #include <stdio.h> // #include
<errno.h> import "C" */ #import <stdio.h>
SwiftίϚϯυԽͰ͖Δ
Swift #!/Applications/Xcode6-Beta3.app/Contents/Developer/ usr/bin/xcrun swift -i println("hello")
ͦ͏͍ try-catch ͳ͍ͳ
୭͕Swift͏ͷʁ • ΧδϡΞϧͳήʔϜϓϩάϥϛϯά • Objective-Cʹৄ͍͠ઌୡ
stackoverflow