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
260
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.5k
Other Decks in Programming
See All in Programming
Effect の双対、Coeffect
yukikurage
5
1.4k
C++20 射影変換
faithandbrave
0
520
Is Xcode slowly dying out in 2025?
uetyo
1
190
Claude Codeの使い方
ttnyt8701
1
130
LINEヤフー データグループ紹介
lycorp_recruit_jp
0
800
A2A プロトコルを試してみる
azukiazusa1
2
1.1k
レガシーシステムの機能調査・開発におけるAI利活用
takuya_ohtonari
0
610
エラーって何種類あるの?
kajitack
5
290
関数型まつり2025登壇資料「関数プログラミングと再帰」
taisontsukada
2
850
AIコーディング道場勉強会#2 君(エンジニア)たちはどう生きるか
misakiotb
1
240
Azure AI Foundryではじめてのマルチエージェントワークフロー
seosoft
0
130
つよそうにふるまい、つよい成果を出すのなら、つよいのかもしれない
irof
1
300
Featured
See All Featured
Building Flexible Design Systems
yeseniaperezcruz
328
39k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
Producing Creativity
orderedlist
PRO
346
40k
Product Roadmaps are Hard
iamctodd
PRO
53
11k
Navigating Team Friction
lara
187
15k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
How to train your dragon (web standard)
notwaldorf
92
6.1k
A designer walks into a library…
pauljervisheath
206
24k
What's in a price? How to price your products and services
michaelherold
246
12k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
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