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
240
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
ある日突然あなたが管理しているサーバーにDDoSが来たらどうなるでしょう?知ってるようで何も知らなかったDDoS攻撃と対策 #phpcon.2024
akase244
2
7.7k
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
asdf-ecspresso作って 友達が増えた話 / Fujiwara Tech Conference 2025
koluku
0
1.4k
php-conference-japan-2024
tasuku43
0
440
Rubyでつくるパケットキャプチャツール
ydah
0
180
EC2からECSへ 念願のコンテナ移行と巨大レガシーPHPアプリケーションの再構築
sumiyae
3
600
カスタムエフェクトプラグインで Atom Craft をいい感じにする@ADX / ADX LE勉強会 vol.1
cox2
0
110
AWS Lambda functions with C# 用の Dev Container Template を作ってみた件
mappie_kochi
0
160
見えないメモリを観測する: PHP 8.4 `pg_result_memory_size()` とSQL結果のメモリ管理
kentaroutakeda
0
950
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
1.4k
アクターシステムに頼らずEvent Sourcingする方法について
j5ik2o
6
710
Оптимизируем производительность блока Казначейство
lamodatech
0
960
Featured
See All Featured
Adopting Sorbet at Scale
ufuk
74
9.2k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
Rails Girls Zürich Keynote
gr2m
94
13k
Building Better People: How to give real-time feedback that sticks.
wjessup
366
19k
For a Future-Friendly Web
brad_frost
176
9.5k
Unsuck your backbone
ammeep
669
57k
Java REST API Framework Comparison - PWX 2021
mraible
28
8.3k
Documentation Writing (for coders)
carmenintech
67
4.5k
Gamification - CAS2011
davidbonilla
80
5.1k
Mobile First: as difficult as doing things right
swwweet
222
9k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
2k
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