@ã«ããçç¥
interfaceã¨ãã®@ãã¼ã¯ã®è©±ã§ã¯ãªãï¼@"æåå"ãªã©ã®ã¢ãããã¼ã¯ã®è©±ã§ãï¼
ãã®@ã¯æ®æ®µç¡æèã«ä½¿ã£ã¦ããããããã¾ãããï¼ããã¯@ã®ç´å¾ã«ããåãèªåã§å¤æãã¦ããªããã£ãåãããªãã¸ã§ã¯ããçæããçç¥è¨å·ã§ããï¼ã¤ã¾ã以ä¸ã®ãã¨ãè¨ããï¼
@1; // => [NSNumber numberWithInteger:1] @0.5; // => [NSNumber numberWithDouble:0.5]], @YES; // => [NSNumber numberWithBool:YES]], @"æåå" // => ãã£ã¹ã(ããããããªãã£ãã®ã§çç¥) @[@1]; // => [NSArray arrayWithObjects:{@1} count:1]; @{@"hoge": @"fuga"}; // [NSDictionary dictionaryWithObjects:{@"fuga"} forKeys:{@"hoge"} count:1]
@ã®å¾ãã®åãæ確ã§ããã°@ãç¨ãã¦çç¥ãã§ãã
int i = 0; NSNumber num = @(i);
ãã®ããã«ç°¡åã«ããªããã£ãåããªãã¸ã§ã¯ãã«å¤æã§ããï¼ã¡ãªã¿ã«æ¢åã®ã³ã¼ããæ¸ãæãããå ´åï¼ Edit -> Refactor -> Convert to Modern Objective-C Syntax... ã使ãã°ç´ã¡ã«çç¥ããå½¢ã«æ¸ãæãã¦ãããï¼
.(ããã)ã¢ã¯ã»ã¹
ç¹å®ã®å½¢å¼ã®ã¡ãã»ã¼ã¸ã¯ï¼ãããã¢ã¯ã»ã¹ãå¯è½ã§ããï¼ãããã¢ã¯ã»ã¹ã«ã¯getterã¨setterãããï¼ä¸ã¤ã®ã¡ãã»ã¼ã¸ã§ä¸¡æ¹ã®å½¹å²ãã¯ãããã¨ã¯ã§ããªãï¼
- getter
å¼æ°ãæããªãï¼
- setter
ã¡ãã»ã¼ã¸åã"set + 大æå + ä»»æã®æåå"ãã§ãã
ä¸ã¤ã®å¼æ°ããã¤
ãã®ã¨ãï¼æ»ãå¤ã¯åããªãï¼ãã ãï¼getterã®æ»ãå¤ãvoidã®å ´åè¦åãåºãï¼setterã®æ»ãå¤ãvoidã§ãªãå ´åæ»ãå¤ã¯æ¨ã¦ããã¦ãã¾ãï¼@propertyã§å®£è¨ãããã¡ã³ãå¤æ°ã¯èªåçã«getterã¨setterãçæãããï¼
ãã»ãã¿ã¼ã«é¢ãã¦ãããã¢ã¯ã»ã¹ããå ´åããã¤ãä¸æ¢ãã¹ãç¹ãããï¼
- æ§é ä½ãè¿ãgetterãéä¸ã«ã¯æã¾ã£ãå ´åã³ã³ãã¤ã«ã¨ã©ã¼ã¨ãªã
view.frame.size.height = 1; // ã³ã³ãã¤ã«ã¨ã©ã¼
ããã¯frameãè¿ãã¦ããå¤ã¯ãªãã¸ã§ã¯ãã®ãã¤ã³ã¿ã§ã¯ãªãï¼æ§é ä½ã®ã³ãã¼ã帰ã£ã¦ãã¦ããããã§ããï¼ããï¼ã³ã³ãã¤ã«ã¨ã©ã¼ã«ãªããªãã¦ãæ£ããè¨å®ãããªãï¼
- æ¬æ¥ä½¿ãããã¹ãmethodãé ãã¦ãã¾ã
button.title = @"ã»ãã»ã" // æ£ãã㯠[button setTitle:@"ã»ãã»ã" forState:UIControlStateNormal];
ã¾ã¨ã
Objective-Cã®è§æ¬å¼§ã ããã®ããã°ã©ã ã¯ããµãã¨æã