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
Objective-C入門
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Yusuke Fujiki
October 23, 2013
Programming
0
190
Objective-C入門
プログラミング初心者向け
Yusuke Fujiki
October 23, 2013
Tweet
Share
More Decks by Yusuke Fujiki
See All by Yusuke Fujiki
Siri Shortcuts を試してみた! / Tried to Siri Shortcuts
fujikky
0
1.2k
13ヶ国語対応のアプリで やっていること
fujikky
3
790
Other Decks in Programming
See All in Programming
AI Schema Enrichment for your Oracle AI Database
thatjeffsmith
0
280
15年続くIoTサービスのSREエンジニアが挑む分散トレーシング導入
melonps
2
200
AIエージェント、”どう作るか”で差は出るか? / AI Agents: Does the "How" Make a Difference?
rkaga
4
2k
Implementation Patterns
denyspoltorak
0
290
Oxlintはいいぞ
yug1224
5
1.3k
AIによるイベントストーミング図からのコード生成 / AI-powered code generation from Event Storming diagrams
nrslib
2
1.9k
SourceGeneratorのススメ
htkym
0
200
Rust 製のコードエディタ “Zed” を使ってみた
nearme_tech
PRO
0
180
CSC307 Lecture 05
javiergs
PRO
0
500
AIフル活用時代だからこそ学んでおきたい働き方の心得
shinoyu
0
130
CSC307 Lecture 06
javiergs
PRO
0
690
Apache Iceberg V3 and migration to V3
tomtanaka
0
160
Featured
See All Featured
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
359
30k
Why Our Code Smells
bkeepers
PRO
340
58k
Color Theory Basics | Prateek | Gurzu
gurzu
0
200
Between Models and Reality
mayunak
1
190
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
A Soul's Torment
seathinner
5
2.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.7k
Docker and Python
trallard
47
3.7k
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
0
170
Designing Experiences People Love
moore
144
24k
Evolving SEO for Evolving Search Engines
ryanjones
0
120
The Curse of the Amulet
leimatthew05
1
8.5k
Transcript
Objective-C入門 iOS勉強会
Objective-C
Objective + C
C言語にオブジェクト指向の機能を 追加したもの +
オブジェクト指向とは
オブジェクト指向とは 名前 性別 職業 「人」設計図 名前:Aさん 性別:男 職業:エンジニア 名前:Bさん 性別:女
職業:デザイナー 名前:Cさん 性別:男 職業:警備
オブジェクト指向とは 名前 性別 職業 「人」設計図 名前:Aさん 性別:男 職業:エンジニア 名前:Bさん 性別:女
職業:デザイナー 名前:Cさん 性別:男 職業:警備
オブジェクト指向とは 名前 性別 職業 「人」設計図 名前:Aさん 性別:男 職業:エンジニア 名前:Bさん 性別:女
職業:デザイナー 名前:Cさん 性別:男 職業:警備 クラス
オブジェクト指向とは 名前 性別 職業 「人」設計図 名前:Aさん 性別:男 職業:エンジニア 名前:Bさん 性別:女
職業:デザイナー 名前:Cさん 性別:男 職業:警備 インスタンス クラス
オブジェクト指向とは 同じ属性をもつオブジェクト の設計図をクラスという クラス(設計図)を元に作った ものをインスタンスという
Image From http:/ /forums.tigsource.com/index.php?topic=3630.0
オブジェクト指向とは あるクラスからその属性を 引き継いだ新しいクラスを作る ことができる これを継承という
Objective-Cでは ほぼすべてのオブジェクトは NSObjectを継承してい る
例えば UIImageView UILabel UISwitch UIView NSObject
interface(設計図) @interface Animal : NSObject @property (nonatomic) NSString *name; @property
(nonatomic) NSInteger legs; - (void)sayMyName; @end
interface(設計図) @interface Animal : NSObject @property (nonatomic) NSString *name; @property
(nonatomic) NSInteger legs; - (void)sayMyName; @end クラス名
interface(設計図) @interface Animal : NSObject @property (nonatomic) NSString *name; @property
(nonatomic) NSInteger legs; - (void)sayMyName; @end クラス名 継承元
interface(設計図) @interface Animal : NSObject @property (nonatomic) NSString *name; @property
(nonatomic) NSInteger legs; - (void)sayMyName; @end クラス名 継承元 属性
interface(設計図) @interface Animal : NSObject @property (nonatomic) NSString *name; @property
(nonatomic) NSInteger legs; - (void)sayMyName; @end クラス名 継承元 属性 メソッド
implementation(実装) @implementation Animal - (void)sayMyName { NSLog(@"%@", self.name); } @end
implementation(実装) @implementation Animal - (void)sayMyName { NSLog(@"%@", self.name); } @end
name属性を出力する
クラスの使い方 Animal *animal = [[Animal alloc] init]; animal.name = @"Stud";
[animal sayMyName];
クラスの使い方 Animal *animal = [[Animal alloc] init]; animal.name = @"Stud";
[animal sayMyName]; クラスからインスタンスを作る
クラスの使い方 Animal *animal = [[Animal alloc] init]; animal.name = @"Stud";
[animal sayMyName]; 属性を設定 クラスからインスタンスを作る
クラスの使い方 Animal *animal = [[Animal alloc] init]; animal.name = @"Stud";
[animal sayMyName]; 属性を設定 クラスからインスタンスを作る sayMyNameメソッドを 実行
継承する @interface Human : Animal - (void)sayHello; @end @implementation Human
- (void)sayHello { NSLog(@"%@ : Hello!", self.name); } @end
継承する @interface Human : Animal - (void)sayHello; @end @implementation Human
- (void)sayHello { NSLog(@"%@ : Hello!", self.name); } @end Animalクラスを 継承
継承する @interface Human : Animal - (void)sayHello; @end @implementation Human
- (void)sayHello { NSLog(@"%@ : Hello!", self.name); } @end Animalクラスを 継承 HumanクラスにはsayHelloメソッドをもたせる
継承する @interface Human : Animal - (void)sayHello; @end @implementation Human
- (void)sayHello { NSLog(@"%@ : Hello!", self.name); } @end Animalクラスを 継承 sayHelloメソッドの実装 HumanクラスにはsayHelloメソッドをもたせる
メソッドの定義 - (void)sayHello; - (NSString *)helloMessage; - (void)sayHelloToSomeone: (NSString *)someone;
- (NSString *)helloToSomeoneMessage: (NSString *)someone;
メソッドの定義 - (void)sayHello; - (NSString *)helloMessage; - (void)sayHelloToSomeone: (NSString *)someone;
- (NSString *)helloToSomeoneMessage: (NSString *)someone; 通常のメソッド
メソッドの定義 - (void)sayHello; - (NSString *)helloMessage; - (void)sayHelloToSomeone: (NSString *)someone;
- (NSString *)helloToSomeoneMessage: (NSString *)someone; 通常のメソッド 返り値ありのメソッド
メソッドの定義 - (void)sayHello; - (NSString *)helloMessage; - (void)sayHelloToSomeone: (NSString *)someone;
- (NSString *)helloToSomeoneMessage: (NSString *)someone; 通常のメソッド 返り値ありのメソッド 引数があるメソッド
メソッドの定義 - (void)sayHello; - (NSString *)helloMessage; - (void)sayHelloToSomeone: (NSString *)someone;
- (NSString *)helloToSomeoneMessage: (NSString *)someone; 通常のメソッド 返り値ありのメソッド 引数があるメソッド 返り値と引数があるメソッド
メソッドの実装 - (void)sayHello { NSLog(@"%@ : Hello!", self.name); } -
(NSString *)helloMessage { return [NSString stringWithFormat: @"%@ : Hello!", self.name]; }
メソッドの実装 - (void)sayHello { NSLog(@"%@ : Hello!", self.name); } -
(NSString *)helloMessage { return [NSString stringWithFormat: @"%@ : Hello!", self.name]; } 通常のメソッド
メソッドの実装 - (void)sayHello { NSLog(@"%@ : Hello!", self.name); } -
(NSString *)helloMessage { return [NSString stringWithFormat: @"%@ : Hello!", self.name]; } 通常のメソッド 返り値ありのメソッド
メソッドの実装 - (void)sayHelloToSomeone:(NSString *)someone { NSLog(@"%@ : Hello, %@!", self.name,
someone); } - (NSString *)helloToSomeoneMessage: (NSString *)someone { return [NSString stringWithFormat:@"%@ : Hello, %@!", self.name, someone]; }
メソッドの実装 - (void)sayHelloToSomeone:(NSString *)someone { NSLog(@"%@ : Hello, %@!", self.name,
someone); } - (NSString *)helloToSomeoneMessage: (NSString *)someone { return [NSString stringWithFormat:@"%@ : Hello, %@!", self.name, someone]; } 引数があるメソッド
メソッドの実装 - (void)sayHelloToSomeone:(NSString *)someone { NSLog(@"%@ : Hello, %@!", self.name,
someone); } - (NSString *)helloToSomeoneMessage: (NSString *)someone { return [NSString stringWithFormat:@"%@ : Hello, %@!", self.name, someone]; } 引数があるメソッド 返り値と引数があるメソッド
メソッドを実行 [animal sayMyName]; インスタンス名
メソッドを実行 [animal sayMyName]; インスタンス名 メソッドを実行
メソッドを実行 [animal sayHelloToSomeone:@"Levi"]; NSString *msg = [animal helloToSomeoneMessage:@"Levi"]; NSLog(@"msg =
%@", msg);
メソッドを実行 [animal sayHelloToSomeone:@"Levi"]; NSString *msg = [animal helloToSomeoneMessage:@"Levi"]; NSLog(@"msg =
%@", msg); 引数があるメソッド
メソッドを実行 [animal sayHelloToSomeone:@"Levi"]; NSString *msg = [animal helloToSomeoneMessage:@"Levi"]; NSLog(@"msg =
%@", msg); 引数があるメソッド 返り値と引数があるメソッド