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
250
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
Deoptimization: How YJIT Speeds Up Ruby by Slowing Down / RubyKaigi 2025
k0kubun
2
1.9k
Orleans + Sekiban + SignalR でリアルタイムWeb作ってみた
tomohisa
0
230
Bedrock×MCPで社内ブログ執筆文化を育てたい!
har1101
7
1.4k
ComposeでのPicture in Picture
takathemax
0
130
オープンソースコントリビュート入門
_katsuma
0
120
Enterprise Web App. Development (1): Build Tool Training Ver. 5
knakagawa
1
120
Golangci-lint v2爆誕: 君たちはどうすべきか
logica0419
1
230
KawaiiLT 登壇資料 キャリアとモチベーション
hiiragi
0
160
エンジニアが挑む、限界までの越境
nealle
1
320
By the way Google Cloud Next 2025に行ってみてどうだった
ymd65536
0
110
Improve my own Ruby
sisshiki1969
0
100
Jakarta EE Meets AI
ivargrimstad
0
810
Featured
See All Featured
Code Review Best Practice
trishagee
67
18k
How to Think Like a Performance Engineer
csswizardry
23
1.6k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
13
830
Art, The Web, and Tiny UX
lynnandtonic
298
20k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
23
2.7k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Side Projects
sachag
453
42k
Writing Fast Ruby
sferik
628
61k
Done Done
chrislema
184
16k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
32
5.5k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
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