ã¯ã©ã¹ã¡ã½ããã® . (ããã)ã¢ã¯ã»ã¹
å®ã¯ã¯ã©ã¹ã¡ã½ããã .(ããã)表è¨ãå¯è½ã«ãªã£ã。
[SomeClass sharedInstance] ↓ SomeClass.sharedInstanceå½ç¶ãªããããã«ã¡ã½ãããéãããã。
SomeClass.sharedInstance.localNameXcodeã§ã¯ã¯ã©ã¹ã¡ã½ããã®.表è¨ã¯è£å®ãå¹ããªãã®ãé£ç¹。ãã ããã以éã®ã¡ã½ããã¯è£å®ãã¦ããã。
ä¾ãã° SomeClass.share... ããã¾ã§ã¯è£å®ããªãã、SomeClass.sharedInstance.local.. ããã¾ã§æ¥ãã¨è£å®ã§ãã。
ã¤ã³ã¹ã¿ã³ã¹ä½æ (1)new
ã馴æã¿ã® alloc/init ã®ä»£ããã« new ã使ãã。SomeClass* obj = [[SomeClass] alloc] init]; ↓ SomeClass* obj = [SomeClass new];. ã使ãã°ããã«çããµã¯ã£ã¨æ¸ãã
SomeClass* obj = SompeClass.new;+new 㯠NSObjectã§å®ç¾©ããã¦ãã(new = alloc+initã¨ã®èª¬æããã)
This method is a combination of alloc and init.NSObject Class Reference
æããObj-Cã«ãã£ãã¡ã½ããã ã、ARCã«ãªã£ã¦ãã autoreleaseãä¸è¦ã«ãªã£ãã®ã§ä½¿ãããããªã£ã。
(åè)
objective c - What is difference between new and [[alloc]init] in iOS? - Stack Overflow
ã¤ã³ã¹ã¿ã³ã¹ä½æ (2)self
ã¯ã©ã¹ã¡ã½ããå ã§selfã¯ã¯ã©ã¹èªèº«ãæã。ãªã®ã§ã¤ã³ã¹ã¿ã³ã¹ã®ä½æã«ä½¿ãã。
+ (instancetype)sharedInstance { SomeClass* obj = [[self alloc] init]; : : }ããã« . 㨠new ã使ãã°ããæ¸ãã。
SomeClass* obj = self.new;
instancetype ã«ã¤ãã¦ã¯ä¸è¨ãåç §
Objective-Cã«ãããinstancetypeåã«ã¤ã㦠- Takebayashi.Asia
é å・ãã£ã¯ã·ã§ããªä½æ
githubã§ã½ã¼ã¹ã³ã¼ããèªãã§ã¦ç¥ã£ã。mutableãªé å・ãã£ã¯ã·ã§ããªããµã¯ã£ã¨æ¸ãã。NSDictionary* dict = @{} NSMutableDictionary* dict = @{}.mutableCopy;
NSArray* array = @[] NSMutableArray* array = @[].mutableCopy;
- - - -
å¤ãã¯githubã§ä»ã®äººã®ã³ã¼ããèªãã§ã¦ç¥ã£ããã®。ã³ã¼ããèªããã¨ã¯ã¢ã«ã´ãªãºã ãèªã¿è§£ãã ãã§ãªãã³ã¼ãã£ã³ã°ã®ãã¬ã³ããããããªã¼。
å¿å
2014å¹´9æ3æ¥ 14:24
Wonderful tips!
åèã«ãªãã¾ã^^
å¿å
2014å¹´9æ3æ¥ 14:24
Wonderful tips!
åèã«ãªãã¾ã^^