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
220
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.4k
Ruby
dictav
0
1.3k
Other Decks in Programming
See All in Programming
Node.js v22 で変わること
yosuke_furukawa
PRO
9
3.4k
PHP8.3の機能を振り返る / Review of PHP 8.3 features
seike460
PRO
1
110
Netty Chicago Java User Group 2024-04-17
sullis
0
170
大規模Reactアプリのリアーキテクチャ~8万行のTanStack Query移行の軌跡~
kj455
4
960
Elm 0.19.0 Changes
bkuhlmann
0
490
ONE WEDGE_company_guide
1wedge_one
0
480
Kotlin Multiplatform at Stable and Beyond (Android Makers 2024)
zsmb
0
220
What We Can Learn From OSS
inouehi
0
420
コーンフレークから始める モデリング会話入門
ogurotakayuki
0
370
GraphQLサーバの構成要素を整理する #ハッカー鮨 #tsukijigraphql / graphql server technology selection
izumin5210
4
840
検証も兼ねて個人開発でHonoとかと向き合った話
hanetsuki
1
910
見た目から始める生産性向上
ikumatadokoro
7
840
Featured
See All Featured
In The Pink: A Labor of Love
frogandcode
138
21k
Docker and Python
trallard
34
2.7k
Fontdeck: Realign not Redesign
paulrobertlloyd
76
4.9k
[RailsConf 2023] Rails as a piece of cake
palkan
23
3.9k
Reflections from 52 weeks, 52 projects
jeffersonlam
345
19k
What's new in Ruby 2.0
geeforr
337
31k
Designing for Performance
lara
601
67k
Producing Creativity
orderedlist
PRO
337
39k
Optimizing for Happiness
mojombo
370
69k
The MySQL Ecosystem @ GitHub 2015
samlambert
243
12k
Facilitating Awesome Meetings
lara
42
5.6k
Building Flexible Design Systems
yeseniaperezcruz
319
37k
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