Share
Embed
Transcript
110 slides
-
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #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 + (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 + (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ͷϓϩύςΟΛ͏ ͏ - (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 ࣍͜͜ -
ͭ·Γ͜͏ͳΔ #define Log NSLog(@"ίίϮτΦολϤʔ") - (void)someMethod { Log; // ίίϮτΦολϤʔ
} ͕͜͜ /4-PH !lίίϮτΦολϤʔ ஔ͞ΕΔ -
ຊ جຊ Ϋϥεͷએݴ ϝιου એݴ ࣮ ݺͼग़͠ #MPDLT .BDSP Ԡ༻
- Type inference. - Method chain. - The strongest Objective-C I thought ͔͜͜Β͕ຊʹ͔ͨͬͨ͠༰ͩ͊ʂ -
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
ීஈܕΛએݴ͢Δॴʹ @@BVUP@UZQF -
@@BVUP@UZQF - (void)someMethod { __auto_type string = @"hogehoge"; string.length; }
/44USJOHͷMFOHUI ϓϩύςΟʹΞΫηεͰ͖Δ ͭ·ΓܕਪΛͯ͘͠ΕΔ -
ΕͨਓޙͰεϥΠυݟͯ͠Ͷ @interface CustomClass : NSObject @property (nonatomic, copy) CustomClass* (^method)();
@property (nonatomic, copy) CustomClass* (^chain)(); @end ฦΓ͖ͭCMPDLTͷϓϩύςΟΛએݴ͢Δ -
#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ϓϨϑΟοΫεͱΔʂ