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
hirose yudai
September 17, 2017
1
3.4k
詳解Objective-C
iOSDC 2017でお話しする内容です
https://iosdc.jp/2017/node/1364
Objective-Cについて熱く語ります
hirose yudai
September 17, 2017
Tweet
Share
More Decks by hirose yudai
See All by hirose yudai
Write swift macros
bannzai
1
230
Figma => SwiftUI
bannzai
0
150
爆速でクソリプを送る技術
bannzai
1
36
Tsukimi
bannzai
0
53
iOSDC_Reject_Conference_Day1
bannzai
0
220
iOSDC-2019.pdf
bannzai
0
1.2k
ios-de-kanpai
bannzai
0
47
waiwai-swiftc.pdf
bannzai
0
120
iosdcrc-conv.pdf
bannzai
4
560
Featured
See All Featured
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
48
2.2k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
A Philosophy of Restraint
colly
203
16k
For a Future-Friendly Web
brad_frost
175
9.4k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.5k
Automating Front-end Workflow
addyosmani
1366
200k
A better future with KSS
kneath
238
17k
Fireside Chat
paigeccino
34
3.1k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Building Better People: How to give real-time feedback that sticks.
wjessup
365
19k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
Transcript
Objective-C J04%$ IUUQTJPTEDKQOPEF ৄղ
ࣗݾհ ໊લኍ༤େ ৬छJ04&OHJOFFS ໊͋ͩ4UBSޤ৯ 4XJGUͷϥΠϒϥϦΛ͍͔ͭ͘࡞ͬͯެ։ͯ͠·͢ ελʔ͍ͩ͘͞ CBOO[BJ ZIJSPTF
ࠓ͓͢͠Δ͜ͱɾ͍ͨ͜͠ͱ IUUQTJPTEDKQOPEF
ࠓͷλʔήοτ IUUQTJPTEDKQOPEF
ࠓͷλʔήοτ IUUQTJPTEDKQOPEF ओʹ4XJGUͰJ04։ൃ͍ͯ͠Δํ
ࠓͷλʔήοτ IUUQTJPTEDKQOPEF 0CKFDUJWF$͕࿀͘͠ͳͬͯདྷͨํ
ࠓͷλʔήοτ IUUQTJPTEDKQOPEF 0CKFDUJWF$ͷ͜ͱΛ͋·ΓΒͳ͍ํ͚
ࠓͷλʔήοτ IUUQTJPTEDKQOPEF ͪΖΜͦ͏͡Όͳ͍ํָ͠ΜͰ͍ͩ͘͞
ͲͪΒ͔ͱ͍͏ͱද໘తͳ͜ͱͷ͓ IUUQTJPTEDKQOPEF جຊతͳػೳ͔ΒԠ༻·Ͱ ࣌ؒͷڐ͢ݶΓ͓͑͠·͢
͜ͷൃදͷ0CKFDUJWF$ J04։ൃͳͷͰ'PVOEBUJPOΛ༻͢Δ͜ͱલఏͰ͠·͢ "3$/PU.3$ 1VSF0CKFDUJWF$/PU0CKFDUJWF$ $ݴޠग़͖ͯ·͢
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #MPDLT .BDSP Ԡ༻
- Type inference. - Method chain. - The strongest Objective-C I thought
Ϋϥεͷએݴ CustomClass.h @interface CustomClass : NSObject @end CustomClass.m #import “CustomClass.h"
@implementation CustomClass @end
Ϋϥεͷએݴ CustomClass.h @interface CustomClass : NSObject // ͜͜ʹΠϯλʔϑΣʔε @end CustomClass.m
#import “CustomClass.h" @implementation CustomClass // ͜͜ʹ࣮ @end I ϔομʔϑΝΠϧ ͱ N ϝΠϯϑΝΠϧ Λ࡞Δ 9DPEFͰΫϥεΛ࡞ΔͱͰ͖͍ͯ·͢
Ϋϥεͷએݴ CustomClass.h @interface CustomClass : NSObject // ͜͜ʹΠϯλʔϑΣʔε @end CustomClass.m
#import “CustomClass.h" @implementation CustomClass // ͜͜ʹ࣮ @end IϑΝΠϧΠϯλʔϑΣʔεΛఆٛ͢Δ ͨΊͷϑΝΠϧ IϑΝΠϧʹΫϥεΛએݴ͠ͳ͍ͱଞͷΫ ϥε͔ΒݟΔ͜ͱ͕Ͱ͖ͳ͍
$MBTTͷએݴ CustomClass.h @interface CustomClass : NSObject // ͜͜ʹΠϯλʔϑΣʔε @end CustomClass.m
#import “CustomClass.h" @implementation CustomClass // ͜͜ʹ࣮ @end ͍͍ͩͨ/40CKFDU͘͠ /40CKFDUΛܧঝ͍ͯ͠ΔΫϥεΛ ܧঝ͓͚ͯ͠0,
Ϋϥεͷએݴ CustomClass.h @interface CustomClass : NSObject // ͜͜ʹΠϯλʔϑΣʔε @end CustomClass.m
#import “CustomClass.h" @implementation CustomClass // ͜͜ʹ࣮ @end NʹIͰએݴͨ͠༰Λ࣮͍ͯ͘͠
CustomClass.h @interface CustomClass : NSObject // ͜͜ʹΠϯλʔϑΣʔε @end ϝιουͷએݴ
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ͜Μͳײ͡
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ϝιουͷએݴ ͕͜͜ฦΓ
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ϝιουͷએݴ ϝιουͷ໊લ
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ϝιουͷએݴ ୈೋҾҎ߱ʹ-BCFM͕ͭ͘
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ϝιουͷએݴ A A͕Ϋϥεϝιου 4XJGUͩͱADMBTTGVODA AA͕Πϯελϯεϝιου 4XJGUͩͱAGVODA
CustomClass.h @interface CustomClass : NSObject + (instancetype)method; - (void)method:(NSObject *)hoge;
- (NSObject *)method:(NSObject *)hoge with:(NSObject *)fuga; @end ϝιουͷએݴ AJOTUBODFUZQFAࣗͷ ΠϯελϯεͷܕΛද͢એݴ ܧঝઌͰ͜ͷϝιουΛͭ߹ ܧঝઌͷܕͱͯ͠ฦΔ
@interface CustomClass : NSObject + (instancetype)method; @end @interface CustomClass2 :
CustomClass //- (instancetype)method; @end JOTUBODFUZQFʹ͍ͭͯ
@interface CustomClass : NSObject + (instancetype)method; @end @interface CustomClass2 :
CustomClass //- (instancetype)method; @end JOTUBODFUZQF ͜ͷ߹ͷAJOTUBODFUZQFA $VTUPN$MBTT
@interface CustomClass : NSObject + (instancetype)method; @end @interface CustomClass2 :
CustomClass //- (instancetype)method; @end JOTUBODFUZQF ͜ͷ߹ͷAJOTUBODFUZQFA $VTUPN$MBTT
CustomClass.m #import “CustomClass.h" @implementation CustomClass // ͜͜ʹ࣮ @end ϝιουͷ࣮
CustomClass.m #import “CustomClass.h" @implementation CustomClass + (instancetype)method1 { CustomClass *custom
= [[CustomClass alloc] init]; return custom; } - (void)method: (NSObject *)hoge { // do something... } @end ͜Μͳײ͡
CustomClass.m #import “CustomClass.h" @implementation CustomClass + (instancetype)method1 { CustomClass *custom
= [[CustomClass alloc] init]; return custom; } - (void)method: (NSObject *)hoge { // do something... } @end ϝιουͷ࣮ IͰॻ͔Ε͍ͯΔ௨Γʹએݴ͠ɺ \^είʔϓͷதͰϝιουͷ࣮
CustomClass.m #import “CustomClass.h" @implementation CustomClass + (instancetype)method1 { CustomClass *custom
= [[CustomClass alloc] init]; return custom; } - (void)method: (NSObject *)hoge { // do something... } @end ϝιουͷ࣮ ϩʔΧϧมASFUVSOAจͱ͔ࡉ͔͍͜ ͱʹׂ͍ͭͯѪ
@interface CustomClass : NSObject + (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end ϝιουͷݺͼग़͠
@interface CustomClass : NSObject + (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end $VTUPN$MBTT͔Β$VTUPN$MBTTΛ͏ ҧ͏Ϋϥε
@interface CustomClass : NSObject + (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end ϝιουͷݺͼग़͠ ͜ͷೋͭʹ
@interface CustomClass : NSObject - (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end ϝιουͷݺͼग़͠ 0CKFDUJWF$ͷϝιουͷݺͼग़͠ <A3FDFJWFSANFUIPE> ͷܗʹͳΔ
@interface CustomClass : NSObject - (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end ϝιουͷݺͼग़͠ ͜ͷ߹ A3FDFJWFSAA$VTUPN$MBTTA ΫϥεʹϝιουΛૹ͍ͬͯΔͷͰ ͜ΕΫϥεϝιουͷݺͼग़͠
@interface CustomClass : NSObject - (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [object method]; } @end ϝιουͷݺͼग़͠ ͜ͷ߹ A3FDFJWFSAAPCKFDUA $VTUPN$MBTTܕͷΠϯελϯεʹ ϝιουΛૹ͍ͬͯΔͷͰ Πϯελϯεϝιου
@interface CustomClass : NSObject - (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [[object method] method]; } @end ϝιουͷݺͼग़͠ ͪͳΈʹϝιουνΣΠϯΛ ͢Δͱ͜͏ͳΔ
@interface CustomClass : NSObject + (instancetype)method; @end @implementation CustomClass2 -
(void)someMethod { CustomClass* object = [[CustomClass alloc] init]; [[[[object method] method] method]; } @end ϝιουͷݺͼग़͠ ʜ
ʜ
[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[ [[[[[[[[[[[[object method] method] method] method] method] method] method] method]
method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] method] ; ϝιουνΣΠϯΛ͢Δͱ<>͕͍ͬͺ͍ʹ ͳΔ
ݟ͕ͨ
<>͚ͭ͗ͯ͢
Χοίѱ͍
ݴ͍͔͚ͨͬͨͩͰ͢
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #MPDLT .BDSP Ԡ༻
- Type inference. - Method chain. - The strongest Objective-C I thought ࣍͜͜
#MPDLTͱ 4XJGUͰ͍͏ͱ͜Ζͷ$MPTVSF ͬΆ͍ͷ $MPTVSFΑΓѻ͍ͮΒ͍ ॻ͖ํ͕ࡶ ॻ͖ํΛ͍ͭΕΔ IUUQGVDLJOHCMPDLTZOUBYDPNهࡌͷํ͔͜͜Β
#MPDLTͱ 4XJGUͰ͍͏ͱ͜Ζͷ$MPTVSF ͬΆ͍ͷ $MPTVSFΑΓѻ͍ͮΒ͍ ॻ͖ํ͕ࡶ ॻ͖ํΛ͍ͭΕΔ IUUQGVDLJOHCMPDLTZOUBYDPNهࡌͷํ͔͜͜Β એݴ͢ΔॴʹΑͬͯॻ͖ํ͕มΘΔ ৄ͍͠એݴͷํ͔͜͜ΒΈ͍ͯͩ͘͞
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end 0CKFDUJWF$ͷϓϩύςΟͷએݴ
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end ͜͜ʹଐੑ
ৄࡉলུ
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end $PQZΛ͚ͭΔඞཁ͕͋Δ
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end ฦΓͷܕ
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end #MPDLTͷ໊લ
ϓϩύςΟͷ໊લ
ࠓճϓϩύςΟͷΈհ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU @property (nonatomic, copy) NSObject* (^blocks)(NSInteger); @end Ҿͷܕ
#MPDLTͰͳ͍߹ એݴ !JOUFSGBDF$VTUPN$MBTT/40CKFDU !QSPQFSUZ OPOBUPNJD DPQZ /40CKFDU PCKFDU @end #MPDLTͰͳ͍߹͜Μͳײ͡
͜͜ʹอ࣋͢ΔܕͱϓϩύςΟ໊Λهࡌ
#MPDLTͷϓϩύςΟΛ͏ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %ld", integer); return [[NSObject alloc] init]; }; self.blocks(1); // log: 1 }
#MPDLTͷϓϩύςΟΛ͏ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %ld", integer); return [[NSObject alloc] init]; }; self.blocks(1); // log: 1 } ฦΓ
#MPDLTͷϓϩύςΟΛ͏ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %ld", integer); return [[NSObject alloc] init]; }; self.blocks(1); // log: 1 } Ҿ
#MPDLTͷϓϩύςΟΛ͏ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %ld", integer); return [[NSObject alloc] init]; }; self.blocks(1); // log: 1 } \^ͷத͕࣮
#MPDLTͷϓϩύςΟΛ͏ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %ld", integer); return [[NSObject alloc] init]; }; self.blocks(1); // log: 1 } ࣮ߦ͢Δͱ͖
4FMGΛΩϟϓνϟ͍ͨ͠ͱ͖ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %@", self); return [[NSObject alloc] init]; }; }
4FMGΛΩϟϓνϟ͍ͨ͠ͱ͖ ͏ - (void)someMethod { self.blocks = ^NSObject* (NSInteger integer)
{ NSLog(@"log: %@", self); return [[NSObject alloc] init]; }; } TFMGΛΩϟϓνϟ͢Δͱ ॥ࢀর͕ى͖ͯ͠·͏
ऑࢀরΛ͏ ͏ - (void)someMethod { __weak CustomClass *weakSelf = self;
self.blocks = ^NSObject* (NSInteger integer) { NSLog(@"log: %@", weakSelf); return [[NSObject alloc] init]; }; }
ऑࢀরΛ͏ ͏ - (void)someMethod { __weak CustomClass *weakSelf = self;
self.blocks = ^NSObject* (NSInteger integer) { NSLog(@"log: %@", weakSelf); return [[NSObject alloc] init]; }; } XFBLͷTFMGͷࢀরΛ࣋ͭ
ऑࢀরΛ͏ ͏ - (void)someMethod { __weak CustomClass *weakSelf = self;
self.blocks = ^NSObject* (NSInteger integer) { NSLog(@"log: %@", weakSelf); return [[NSObject alloc] init]; }; } CMPDLTͷதͰXFBL4FMGΛ͏
॥ࢀর͕ى͖Δ߹ؾΛ͚ͭΑ͏
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #MPDLT .BDSP Ԡ༻
- Type inference. - Method chain. - The strongest Objective-C I thought ࣍͜͜
.BDSPͱ ϓϩάϥϜதͷจࣈྻΛ͋Β͔͡Ίఆٛͨ͠نଇʹ͕ͨͬͯ͠ஔ ͢Δػೳͷ͜ͱΛ͍͍·͢ Ҿ༻$ݴޠͷϚΫϩͷجຊʹ͍ͭͯ IUUQXXXDMBOHPSHEFUBJMNBDSP@CBTJDIUNM
.BDSPͱ ϓϩάϥϜதͷจࣈྻΛ͋Β͔͡Ίఆٛͨ͠نଇʹ͕ͨͬͯ͠ஔ ͢Δػೳͷ͜ͱΛ͍͍·͢ Ҿ༻$ݴޠͷϚΫϩͷجຊʹ͍ͭͯ IUUQXXXDMBOHPSHEFUBJMNBDSP@CBTJDIUNM ͜Ε͚ͩݴΘΕͯΘ͔Βͳ͍ͱࢥ͏ͷͰ ͬͯΈ·͠ΐ͏
.BDSPͱ ϓϩάϥϜதͷจࣈྻΛ͋Β͔͡Ίఆٛͨ͠نଇʹ͕ͨͬͯ͠ஔ ͢Δػೳͷ͜ͱΛ͍͍·͢ Ҿ༻$ݴޠͷϚΫϩͷجຊʹ͍ͭͯ IUUQXXXDMBOHPSHEFUBJMNBDSP@CBTJDIUNM ·͔ͣ͜͜Β نଇͷఆٛΛ͢Δ
نଇΛఆٛ͢Δ #define Log NSLog(@"ίίϮτΦολϤʔ") ఆٛεϧϤʔએݴ
نଇΛఆٛ͢Δ #define Log NSLog(@"ίίϮτΦολϤʔ") ͜ͷఆٛͷ໊લ
.BDSPͱ ϓϩάϥϜதͷจࣈྻΛ͋Β͔͡Ίఆٛͨ͠نଇʹ͕ͨͬͯ͠ஔ ͢Δػೳͷ͜ͱΛ͍͍·͢ Ҿ༻$ݴޠͷϚΫϩͷجຊʹ͍ͭͯ IUUQXXXDMBOHPSHEFUBJMNBDSP@CBTJDIUNM ࣍͜͜Λ֬ೝ
نଇΛఆٛ͢Δ #define Log NSLog(@"ίίϮτΦολϤʔ") ஔ͢Δ༰
ஔ͢Δ༰ #define Log NSLog(@"ίίϮτΦολϤʔ") -PHͱϓϩάϥϜதʹॻ͘ͱ /4-PH !lίίϮτΦολϤʔ ʹஔ͞ΕΔ
ͭ·Γ͜͏ͳΔ #define Log NSLog(@"ίίϮτΦολϤʔ") - (void)someMethod { Log; }
ͭ·Γ͜͏ͳΔ #define Log NSLog(@"ίίϮτΦολϤʔ") - (void)someMethod { Log; // ίίϮτΦολϤʔ
} ͕͜͜ /4-PH !lίίϮτΦολϤʔ ஔ͞ΕΔ
.BDSPʹ͍ͭͯ ଞʹҾΛऔΔ͜ͱ͕Ͱ͖ͨΓ ఆͱͯ͠એݴ͢ΔΑ͏ͳ͍ํͩͬͨΓ τʔΫϯͱݺΕΔػೳͩͬͨΓ͕͋ΔͷͰ ௐͯΈΔͱ໘ന͍Ͱ͢ ඇৗʹڧྗͰ͕͍͗͢͢ʹ͝ҙ
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #MPDLT .BDSP Ԡ༻
- Type inference. - Method chain. - The strongest Objective-C I thought ͔͜͜Β͕ຊʹ͔ͨͬͨ͠༰ͩ͊ʂ
5ZQFJOGFSFODF
5ZQFJOGFSFODF ܕਪ
0CKFDUJWF$ͷܕ 0CKFDUJWF$ϓϩάϥϜதʹܕΛهड़͢Δ͜ͱ͕Ͱ͖·͕͢ɺ࣮ ࡍ3VOUJNFͰܕ͕ܾ·Δಈతܕ͚ݴޠͰ͢ɻ ϓϩάϥϜதʹܕΛએݴ͢Δ͜ͱͰ*%&ͷิ͕ޮ͖͍͢ͱݴͬ ͨར͕͋Γ·͢ɻ ࣮ࡍʹಈతܕ͚Ͱ͋Δ͜ͱʹมΘΒͳ͍ͷͰ͕͢ɺ*%&͕ղ ऍ͢ΔܕΛਪͤ͞Δ͜ͱ͕Ͱ͖·͢ɻ ͦ͏ɺ@@BVUP@UZQFͳΒͶ
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
ීஈܕΛએݴ͢Δॴʹ @@BVUP@UZQF
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
/44USJOHͷMFOHUI ϓϩύςΟʹΞΫηεͰ͖Δ ͭ·ΓܕਪΛͯ͘͠ΕΔ
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
ѹతਪ
.FUIPEDIBJO
.FUIPEDIBJO MJLF4XJGU
4XJGUͬΆ͘ .FUIPEDIBJO
4XJGUͬΆ͘ .FUIPEDIBJO ͑ʁ0CKFDUJWF$ͬͯ͋ͷϝιουݺͼग़͢ͱ͖ʹ<>͚ͭ͗ͯ͢Χοί ѱ͍ݴޠͰ͠ΐʁ ͦ͏ࢥͬͨͦ͜ͷ͋ͳͨਖ਼ղͰ͢ɻ ೦ͳ͕Βϝιουݺͼग़͠<>͚ͭΔͷ͕0CKFDUJWF$ ͜͜Ͱࠓ·ͰಘͨࣝͷதͰ<>͚ͭͣʹॲཧΛॻ͍͍͖ͯ ͞ΒʹͦΕΛͭͳ͍Ͱ͍͖·͢ɻ
ΕͨਓޙͰεϥΠυݟͯ͠Ͷ @interface CustomClass : NSObject @property (nonatomic, copy) CustomClass* (^method)();
@property (nonatomic, copy) CustomClass* (^chain)(); @end ฦΓ͖ͭCMPDLTͷϓϩύςΟΛએݴ͢Δ
͍ํ - (void)someMethod { self.chain(); }
͍ํ - (void)someMethod { self.method(); } ॲཧΛ໊લ Ͱݺͼग़ͤΔ
ϝιουνΣΠϯ self.method().chain().chain().chain().chain().chain().chain( ).chain().chain().chain().chain().chain().chain().chain().ch ain().chain().chain().chain().chain().chain().chain().chain( ).chain().chain().chain().chain().chain().chain().chain().ch ain().chain().chain().chain().chain();
͚ͭ͗ͯ͢
͔͍͍ͬ͜
࣍ߦ͖·͠ΐ͏
The strongest Objective-C I thought
ͷ͔Μ͕͑ͨ࠷ڧͷObjective-C
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld”, count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); }
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld”, count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); } ͷ͔Μ͕͑ͨ࠷ڧͷ0CKFDUJWF$
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld”, count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); } ࣮ߦ݁Ռ ίίϮτΦολϤʔ count: 0 count: 2
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld”, count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); } ܕਪ͕Ͱ͖Δʂ MFUͰఆΛ؆୯ʹએݴʂ
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld", count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); } ͬͱ؆୯ʹϩάΛు͘Α͏ʹʂ ϚΫϩذॲཧ͔͚ΔͷͰ ඞཁ͕͋Ε֦ு
#define let __auto_type const #define var __auto_type #define dump(count) NSLog(@“count:
%ld”, count) #define print() NSLog(@"ίίϮτΦολϤʔ") NSArray* Array() { return @[]; } - (instancetype)init { self = [super init]; if (self) { self.method = ^{ print(); }; } return self; } - (void)someMethod { let array = Array(); var array2 = Array(); array2 = @[@"hoge", @"fuga"]; // array = @[@"hoge", @"fuga"]; ίϯύΠϧΤϥʔ self.method(); dump(array.count); dump(array2.count); } $ݴޠͷTZOUBYΛͬͯ ؾܰʹJOJUJBMJ[FSΛ͑ΔΑ͏ʹʂ ͦͯ͠ɺ/4ϓϨϑΟοΫεͱΔʂ
ૉఢͰ͠ΐʁ
Ͳ͔͜ͰΈͨ͜ͱ͋Δʁ
None
ൃදͷ·ͱΊ ͷ͔Μ͕͑ͨ࠷ڧͷ0CKFDUJWF$ͱͯૉΒ͍͠ͷ͕ग़དྷ্͕Γ· ͨ͠ɻ ͔͠͠ɺνʔϜͰͷ։ൃͩͱΓࠞཚΛট͘Մೳੑ͕େ͖͍ͷͰ༻ Ί·͠ΐ͏ɻ ͪͳΈʹʮͷ͔Μ͕͑ͨ࠷ڧͷ0CKFDUJWF$ʯʹࣅͨ4XJGUͱ͍͏ݴޠͰ ࡞ͬͨϥΠϒϥϦΛ͍͔ͭ͘ެ։͍ͯ͠ΔͷͰɺΈͳ͞Μ શͯͷϦϙδτϦʹελʔ͍ͩ͘͞ IUUQTHJUIVCDPNCBOO[BJ
͓͠·͍a ?P?