{"id":1155,"date":"2014-11-14T18:25:12","date_gmt":"2014-11-14T09:25:12","guid":{"rendered":"https:\/\/ecoop.net\/memo\/?p=1155"},"modified":"2017-04-18T02:01:34","modified_gmt":"2017-04-17T17:01:34","slug":"objective-c-property-basics","status":"publish","type":"post","link":"https:\/\/www.ecoop.net\/memo\/archives\/objective-c-property-basics.html","title":{"rendered":"[iOS][Objective-C] @property \u306e\u57fa\u672c\u307e\u3068\u3081"},"content":{"rendered":"<p>Objective-C \u3067\u306a\u3093\u3068\u306a\u304f\u77e5\u3063\u3066\u3044\u308b\u3051\u3069\u5b9f\u306f\u3088\u304f\u77e5\u3089\u306a\u3044\u30d7\u30ed\u30d1\u30c6\u30a3(@property)\u307e\u308f\u308a\u306e<br \/>\n\u57fa\u672c\u7684\u306a\u4ed5\u69d8\u3092\u307e\u3068\u3081\u307e\u3057\u305f\u3002<\/p>\n<p>Xcode6.1\u304c\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3066<a href=\"https:\/\/developer.apple.com\/swift\/\" target=\"_blank\">Swift<\/a>\u306e\u03b2\u304c\u3068\u308c\u305f\u3057\u3001\u300cSwift\u4f7f\u3046\u304b\u3089\u3044\u3089\u306a\u3044\u3088\u300d\u306a\u3093\u3066\u8a00\u308f\u306a\u3044\u3067\u3001iOS\u958b\u767a\u306e\u304a\u4f9b\u306b\u3069\u3046\u305e\u3002<\/p>\n<p><!--more--><\/p>\n<h2>\u30d7\u30ed\u30d1\u30c6\u30a3(@property)\u3063\u3066\u4f55\uff1f<\/h2>\n<p>\u30e1\u30f3\u30d0\u5909\u6570(\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u5909\u6570)\u3092\u5916\u90e8\u304b\u3089\u53c2\u7167\u3001\u4ee3\u5165\u3059\u308b\u305f\u3081\u306e\u30a2\u30af\u30bb\u30b5(getter\/setter)\u3067\u3059\u3002<br \/>\n\u30e1\u30c3\u30bb\u30fc\u30b8([]\u30ab\u30c3\u30b3\u3067\u56f2\u3080\u30a2\u30ec)\u3067\u72ec\u81ea\u306egetter\/setter\u3092\u5b9f\u88c5\u3001\u4f7f\u7528\u3057\u3066\u3082\u3044\u3044\u3067\u3059\u304c\u3001<br \/>\n\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u3046\u4e8b\u3067 foo.name = @&#8221;John&#8221;; \u306e\u3088\u3046\u306a\u4ed6\u8a00\u8a9e\u3067\u3082\u99b4\u67d3\u307f\u306e\u3042\u308b\u30c9\u30c3\u30c8\u533a\u5207\u308a\u3067\u53c2\u7167\u30fb\u4ee3\u5165\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p>\u4f8b\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb(Foo.h)\n\n@interface Foo : NSObject\n\n@property (nonatomic, copy) NSString *name;\n @property (nonatomic, assign) NSUInteger age;\n\n@end \n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u5b9f\u88c5(Foo.m)\n\n#import &quot;Foo.h&quot;\n\n@implementation Foo\n@end \n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u5229\u7528\u5074\u30bd\u30fc\u30b9\nFoo *foo = &#x5B;&#x5B;Foo alloc] init];\nfoo.name = @&quot;Hanako&quot;; \/\/ \u4ee3\u5165\nfoo.age = 18; \/\/ \u4ee3\u5165\nNSLog(@&quot;name: %@ age:&quot;, foo.name, foo.age); \/\/ \u53c2\u7167\n<\/pre>\n<h2>\u30d7\u30ed\u30d1\u30c6\u30a3\u5ba3\u8a00(@property)\u304c\u4f55\u3092\u3057\u3066\u3044\u308b\u304b<\/h2>\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3(@property)\u306e\u5ba3\u8a00\u306f\u30b3\u30f3\u30d1\u30a4\u30eb\u6642\u306b\u305d\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u306egetter\/setter\u30b3\u30fc\u30c9\u306b\u5c55\u958b\u3055\u308c\u307e\u3059\u3002<br \/>\n\u524d\u9805\u306e\u30b3\u30fc\u30c9\u306f\u5b9f\u969b\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u5ba3\u8a00\u30fb\u5b9a\u7fa9\u3059\u308b\u306e\u3068\u540c\u7b49\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb(Foo.h)\n\n@interface Foo : NSObject\n\n&lt;ul&gt;\n&lt;li&gt;(NSString *)name;&lt;\/li&gt;\n&lt;li&gt;(void)setName: (NSString  *)value;&lt;\/li&gt;\n&lt;li&gt;&lt;p&gt;(NSUInteger)age;&lt;\/p&gt;&lt;\/li&gt;\n&lt;li&gt;(void)setAge: (NSUInteger)value;&lt;\/li&gt;\n&lt;\/ul&gt;\n\n&lt;p&gt;@end \n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u5b9f\u88c5(Foo.m)\n\n#import &quot;Foo.h&quot;\n\n@implementation Foo {\n  NSString *_name;\n  NSUInteger _age;\n}\n\n&lt;ul&gt;\n&lt;li&gt;(NSString *)name {\nreturn _name;\n}&lt;\/li&gt;&lt;\/ul&gt;&lt;\/p&gt;\n&lt;li&gt;&lt;p&gt;(void)setName: (NSString  *)value {\n\/\/ \u8a3b\uff1a@property\u3067copy\u5c5e\u6027(\u5f8c\u8ff0)\u3092\u6307\u5b9a\u3057\u3066\u3044\u308b\u306e\u3067\u3001\u30b3\u30d4\u30fc\u3057\u305f\u5024\u3092\u5185\u90e8\u306b\u6301\u3064\u51e6\u7406\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002\n_name = &#x5B;value copy]; \n}&lt;\/p&gt;&lt;\/li&gt;\n&lt;li&gt;&lt;p&gt;(NSUInteger)age {\nreturn _age;\n}&lt;\/p&gt;&lt;\/li&gt;\n&lt;li&gt;(void)setAge: (NSUInteger)value{\n_age = value;\n}&lt;\/li&gt;\n\n\n&lt;p&gt;@end \n<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001\u5b9f\u969b\u306b\u306f\u30d7\u30ed\u30d1\u30c6\u30a3\u306fsetter\/getter\u3068\u3057\u3066\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<br \/>\n\u9006\u306b\u3044\u3046\u3068\u3001\u3053\u306e\u66f8\u5f0f\u306b\u5f93\u3063\u305fsetter\/getter\u306f@property\u3068\u3057\u3066\u5ba3\u8a00\u3057\u3066\u3044\u306a\u304f\u3066\u3082\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u3088\u3046\u306b\u53c2\u7167\u30fb\u4ee3\u5165\u3067\u304d\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u3064\u307e\u308a\u3001value = [foo age] \u3068 value = foo.age \u306f\u540c\u3058\u3067\u3001<br \/>\n[foo setAge: 30] \u3068 foo.age = 30 \u306f\u540c\u3058\u51e6\u7406\u3067\u3059\u3002<\/p>\n<h2>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u5b9f\u88c5\u3001@synthesize<\/h2>\n<p>\u6700\u521d\u306e\u4f8b\u3067\u306f\u7701\u7565\u3057\u307e\u3057\u305f\u304c\u3001\u30d7\u30ed\u30d1\u30c6\u30a3(@property)\u306e\u5b9f\u88c5\u3068\u3057\u3066\u3001<br \/>\n\u30af\u30e9\u30b9\u5b9f\u88c5\u30d5\u30a1\u30a4\u30eb\u306b \u300c@synthesize \u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u300d\u3092\u8a18\u8ff0\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u5b9f\u88c5(Foo.m)\n\n#import &quot;Foo.h&quot;\n\n@implementation Foo\n\n@synthesize name, age; \/\/ @property name \u3068 age\u306e\u5b9f\u88c5\u3002\n\n@end \n<\/pre>\n<p>Xcode4.3\u4ee5\u524d\u306f\u4e0a\u8a18\u306e\u30b3\u30fc\u30c9\u304c\u306a\u3044\u3068\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u307e\u305b\u3093\u3067\u3057\u305f\u3002<\/p>\n<p>Xcode4.4(Apple LLVM compiler 3.0)\u4ee5\u964d\u306f@synthesize\u304c\u306a\u3044\u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u306f\u81ea\u52d5\u3067@synthesize\u304c\u88dc\u5b8c\u3055\u308c\u308b\u3088\u3046\u306b\u306a\u3063\u305f\u305f\u3081\u3001<br \/>\n@synthesize\u3068\u3044\u3046\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u660e\u793a\u3057\u306a\u304f\u3066\u3082\u3088\u304f\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n<p>@property\u306fgetter\/setter\u306e\u30d8\u30c3\u30c0\u5ba3\u8a00\u3092\u884c\u3046\u3082\u306e\u3067\u3042\u308b\u306e\u306b\u5bfe\u3057\u3066@synthesize\u306f\u5ba3\u8a00\u306b\u5408\u308f\u305b\u305f\u30e1\u30c3\u30bb\u30fc\u30b8\u5b9f\u88c5\u30fb\u30e1\u30f3\u30d0\u5909\u6570\u5ba3\u8a00\u306b\u7f6e\u304d\u63db\u3048\u3089\u308c\u308b\u3082\u306e\u3067\u3059\u3002<\/p>\n<p>\u4f7f\u7528\u3059\u308b\u30e1\u30f3\u30d0\u5909\u6570\u540d\u306f\u300c@synthesize \u30d7\u30ed\u30d1\u30c6\u30a3\u540d = \u30e1\u30f3\u30d0\u5909\u6570\u540d\u300d\u3068\u3044\u3046\u6307\u5b9a\u3092\u884c\u3046\u4e8b\u3067\u5909\u66f4\u3059\u308b\u4e8b\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u5b9f\u88c5(Foo.m)\n\n@implementation Foo \n@synthesize name = _myName; \/\/ \u30e1\u30f3\u30d0\u30fc\u5909\u6570\u3068\u3057\u3066 _name \u306e\u4ee3\u308f\u308a\u306b _myName \u3092\u4f7f\u3046\n@synthesize age = _myAge; \/\/ \u30e1\u30f3\u30d0\u30fc\u5909\u6570\u3068\u3057\u3066 _name \u306e\u4ee3\u308f\u308a\u306b _myName \u3092\u4f7f\u3046\n\n&lt;ul&gt;\n&lt;li&gt;(NSString *)description{\n\/\/ @synthesize\u3067\u751f\u6210\u3055\u308c\u305f\u30e1\u30f3\u30d0\u5909\u6570\u306f\u76f4\u63a5\u53c2\u7167\u3082\u53ef\u80fd\u3067\u3059\nreturn &#x5B;NSString stringWithFormat: @&quot;name: %@ age: %zd&quot;, _myName, _myAge];\n}\n@end \n<\/pre>\n<\/li>\n<\/ul>\n<h2>@property\u306b\u6307\u5b9a\u3067\u304d\u308b\u5c5e\u6027<\/h2>\n<h3>\u5c5e\u6027\u3068\u306f<\/h3>\n<p>@property (nonatomic, copy) \u306e\u3088\u3046\u306b\u3001\u30ab\u30c3\u30b3\u5185\u306b\u6307\u5b9a\u3059\u308b\u30ad\u30fc\u30ef\u30fc\u30c9\u3092\u5c5e\u6027\u3068\u3044\u3044\u307e\u3059\u3002<br \/>\n\u5c5e\u6027\u306f\u81ea\u52d5\u751f\u6210\u3055\u308c\u308bgetter\/setter\u306e\u6319\u52d5\u3092\u5b9a\u7fa9\u3059\u308b\u3082\u306e\u3067\u3001<\/p>\n<ul>\n<li>\u30a2\u30c8\u30df\u30c3\u30af\u6027\u3092\u6c7a\u3081\u308b\u5c5e\u6027<\/li>\n<li>\u5229\u7528\u3059\u308b\u30a2\u30af\u30bb\u30b5\u306e\u7a2e\u985e\u3084\u540d\u524d\u3092\u6c7a\u3081\u308b\u5c5e\u6027<\/li>\n<li>\u30e1\u30e2\u30ea\u7ba1\u7406\u5c5e\u6027<\/li>\n<\/ul>\n<p>\u306e3\u30bf\u30a4\u30d7\u306e\u5c5e\u6027\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<h3>\u30a2\u30c8\u30df\u30c3\u30af\u6027\u5c5e\u6027<br \/>\n\u30a2\u30c8\u30df\u30c3\u30af\u6027\u3092\u6c7a\u3081\u308b\u5c5e\u6027\u306f\uff12\u7a2e\u985e\u3057\u304b\u3042\u308a\u307e\u305b\u3093\u3002<\/p>\n<dl>\n<dt>atomic<\/dt>\n<dd>\u7701\u7565\u6642\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u3002synchronized\u3067\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u306b\u3057\u305fgetter,setter\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/dd>\n<dt>nonatomic<\/dt>\n<dd>\u30b9\u30ec\u30c3\u30c9\u30bb\u30fc\u30d5\u3067\u306a\u3044\u5358\u7d14\u306agetter,setter\u3092\u751f\u6210\u3057\u307e\u3059\u3002iOS\u3067\u306f\u30d1\u30d5\u30a9\u30fc\u30de\u30f3\u30b9\u306e\u554f\u984c\u304b\u3089\u307b\u3068\u3093\u3069\u306e\u5834\u5408nonatomic\u306b\u3059\u3079\u304d\u3067\u3059\u3002<\/dd>\n<\/dl>\n<\/h3>\n<h3>\u30a2\u30af\u30bb\u30b5\u5c5e\u6027<\/h3>\n<dl>\n<dt> readwrite<\/dt>\n<dd>\u30c7\u30d5\u30a9\u30eb\u30c8\u3002getter\/setter\u4e21\u65b9\u3092\u751f\u6210\u3057\u307e\u3059\u3002<\/dd>\n<dt> readonly<\/dt>\n<dd>getter\u306e\u307f\u751f\u6210\u3057\u307e\u3059\u3002<\/dd>\n<dt>geter=\u30e1\u30bd\u30c3\u30c9\u540d<\/dt>\n<dd>getter\u306e\u540d\u524d\u3092\u8a2d\u5b9a\u3059\u308b\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u3068\u540c\u3058\u3002BOOL \u578b\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u540d\u524d\u3092 is\u301c\u3068\u3059\u308b\u3068\u5206\u304b\u308a\u3084\u3059\u304f\u306a\u308a\u307e\u3059\u3002<\/dd>\n<dt>seter=\u30e1\u30bd\u30c3\u30c9\u540d<\/dt>\n<dd>setter\u306e\u540d\u524d\u3092\u8a2d\u5b9a\u3059\u308b\u3002\u30c7\u30d5\u30a9\u30eb\u30c8\u306f\u300cset\u30d7\u30ed\u30d1\u30c6\u30a3\u540d\u300d\u3002\u3042\u307e\u308a\u4f7f\u308f\u308c\u308b\u3053\u3068\u306f\u3042\u308a\u307e\u305b\u3093\u3002<\/dd>\n<\/dl>\n<h3>\u30e1\u30e2\u30ea\u7ba1\u7406\u5c5e\u6027<\/h3>\n<p>\u30e1\u30e2\u30ea\u7ba1\u7406\u5c5e\u6027\u306fARC\u304c\u6709\u52b9\u304b\u3069\u3046\u304b\u3001Objective-C\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8(NSObject)\u304b\u3069\u3046\u304b\u306b\u3088\u308a\u30c7\u30d5\u30a9\u30eb\u30c8\u304c\u7570\u306a\u308a\u307e\u3059\u3002<\/p>\n<dl>\n<dt> assign<\/dt>\n<dd>\u975e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306e\u30c7\u30d5\u30a9\u30eb\u30c8\u3002NSInteger\u306a\u3069\u5024\u578b\u3001C\u7531\u6765\u306e\u578b\u306a\u3069\u3001\u30e1\u30e2\u30ea\u7ba1\u7406\u304c\u5fc5\u8981\u306a\u3044\u3082\u306e\u306b\u4f7f\u7528\u3057\u307e\u3059\u3002\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306e\u5834\u5408\u306fassign\u3067\u306a\u304fweak\u304bunsafe_unretained\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/dd>\n<dt>strong<\/dt>\n<dd>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306eARC\u74b0\u5883\u30c7\u30d5\u30a9\u30eb\u30c8\u3002setter\u3067\u4ee3\u5165\u524d\u306e\u3082\u306e\u3092release\u3057\u3001\u65b0\u305f\u306b\u4ee3\u5165\u3059\u308b\u3082\u306e\u3092retain\u3057\u307e\u3059\u3002\u975e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306b\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/dd>\n<dt>retain<\/dt>\n<dd>strong\u3068\u5168\u304f\u540c\u3058\u3067\u3059(\u53c2\u8003\uff1a<a href=\"http:\/\/developer.apple.com\/library\/mac\/#releasenotes\/ObjectiveC\/RN-TransitioningToARC\/Introduction\/Introduction.html\">Transitioning to ARC Release Notes<\/a>)<\/dd>\n<dt> weak<\/dt>\n<dd>\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306e\u975eARC\u74b0\u5883\u30c7\u30d5\u30a9\u30eb\u30c8\u3002\u4ee3\u5165\u6642\u306bretain\/release\u3092\u884c\u3044\u307e\u305b\u3093\u3002\u30e1\u30e2\u30ea\u30a2\u30af\u30bb\u30b9\u30a8\u30e9\u30fc\u3092\u907f\u3051\u308b\u305f\u3081\u53c2\u7167\u5148\u304c\u89e3\u653e\u3055\u308c\u305f\u6642\u306fnil\u306b\u306a\u308a\u307e\u3059\u3002strong\u3068\u540c\u69d8\u3001\u975e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u306b\u306f\u4f7f\u7528\u3067\u304d\u307e\u305b\u3093\u3002<\/dd>\n<dt>unsafe_unretained<\/dt>\n<dd>weak\u3068\u4f3c\u3066\u3044\u307e\u3059\u304c\u3001release\u3055\u308c\u3066\u3082nil\u306b\u306a\u308a\u307e\u305b\u3093\u3002assign\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u3053\u3061\u3089\u306f\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u578b\u3092\u5bfe\u8c61\u3068\u3057\u3066\u3044\u307e\u3059\u3002<\/dd>\n<dt>copy<\/dt>\n<dd>retain\/release\u3059\u308b\u70b9\u306fstrong\u3068\u540c\u3058\u3067\u3059\u304c\u3001\u4ee3\u5165\u6642\u306bsetter\u3067\u5f15\u6570\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092retain\u305b\u305a\u306b\u3001\u65b0\u305f\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3068\u3057\u3066\u30b3\u30d4\u30fc(_value = [value copy])\u3057\u3066\u304b\u3089retain\u3057\u307e\u3059\u3002\u7528\u9014\u3068\u3057\u3066\u306fNSString\u306a\u3069mutable\u306a\u578b(NSMutableString)\u304c\u5b50\u30af\u30e9\u30b9\u3068\u3057\u3066\u5b58\u5728\u3059\u308b\u3082\u306e\u306b\u3064\u3044\u3066\u3001\u4ee3\u5165\u5f8c\u306b\u5916\u90e8\u304b\u3089\u306e\u5024\u306e\u5909\u66f4\u3092\u9632\u3050\u305f\u3081\u306bstrong\u306e\u4ee3\u308f\u308a\u306bcopy\u3092\u4f7f\u7528\u3057\u307e\u3059\u3002<\/dd>\n<\/dl>\n<h2>\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u30ab\u30b9\u30bf\u30e0\u5b9f\u88c5<\/h2>\n<p>\u30d7\u30ed\u30d1\u30c6\u30a3\u306f\u81ea\u52d5\u7684\u306a\u5b9f\u88c5\u306b\u4efb\u305b\u305a\u3001\u4efb\u610f\u306e\u5b9f\u88c5\u306b\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3059\u3002<\/p>\n<p>\u30ab\u30b9\u30bf\u30e0\u306egetter\/setter\u3092\u5b9f\u88c5\u3059\u308b\u5834\u5408\u3001\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u30a2\u30c8\u30df\u30c3\u30af\u6027\u5c5e\u6027\u6307\u5b9a\u3084\u30e1\u30e2\u30ea\u7ba1\u7406\u5c5e\u6027\u6307\u5b9a\u3092\u7121\u8996\u3057\u305f\u5b9f\u88c5\u3082\u53ef\u80fd\u3067\u3059\u304c\u3001<br \/>\n\u5229\u7528\u5074\u304b\u3089\u306f\u5c5e\u6027\u306b\u5408\u308f\u305b\u305f\u5b9f\u88c5\u3092\u671f\u5f85\u3055\u308c\u308b\u305f\u3081\u3001\u5c5e\u6027\u306b\u3088\u308b\u5951\u7d04\u306b\u3057\u305f\u304c\u3063\u3066\u9069\u5207\u306b\u5b9f\u88c5\u3059\u308b\u3053\u3068\u304c\u5927\u5207\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u30d8\u30c3\u30c0\u30d5\u30a1\u30a4\u30eb(Foo.h)\n\n@interface Foo : NSObject\n\n@property (nonatomic, copy) NSArray *source;\n\n@property (nonatomic, readonly) NSInteger count;\n\n@property (nonatomic, readonly, getter=isActive) BOOL active;\n\n@end \n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u30af\u30e9\u30b9\u5b9f\u88c5(Foo.m)\n\n#import &quot;Foo.h&quot;\n\n@implementation Foo{\n  NSMutableArray *_storage;\n}\n\n\/\/ source\u306egetter\u5b9f\u88c5\n-(NSArray *)source{\n  return _storage;\n}\n\n\/\/ source\u306esetter\u5b9f\u88c5\n-(void)setSource: (NSArray *)source{\n  _storage = &#x5B;&#x5B;NSMutableArray alloc] initWithArray: source]; \/\/ NSMutableArray\u306b\u3059\u308b\u306e\u3067copy\u306f\u4e0d\u8981\n}\n\n\/\/ count\u306egetter\u5b9f\u88c5\n- (NSInteger) count {\n  return &#x5B;_storage count];\n}\n\n\/\/ active\u306egetter\u5b9f\u88c5\n- (BOOL) isActive{\n  return &#x5B;_storage count] &gt; 0;\n}\n@end \n<\/pre>\n<h2>\u540c\u4e00\u30af\u30e9\u30b9\u304b\u3089\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u4f7f\u7528<\/h2>\n<p>\u540c\u4e00\u30af\u30e9\u30b9\u5185\u3067\u306f\u53c2\u7167\u306fgetter\u3067\u306f\u306a\u304f\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u76f4\u63a5\u53c2\u7167\u3001\u8a2d\u5b9a\u306f\u4ee3\u5165\u65b9\u6cd5\u306e\u7d71\u4e00\u306e\u305f\u3081setter\u3092\u4f7f\u7528\u3059\u308b\u3053\u3068\u304c\u63a8\u5968\u3055\u308c\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u5916\u3068\u3057\u3066\u3001init\u30e1\u30bd\u30c3\u30c9\u3067\u306fproperty\u4ee3\u5165(setter)\u3092\u4f7f\u3046\u3079\u304d\u3067\u306f\u3042\u308a\u307e\u305b\u3093\u3002<br \/>\nsetter\u306f\u5b50\u30af\u30e9\u30b9\u304c\u30aa\u30fc\u30d0\u30fc\u30e9\u30a4\u30c9\u3059\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u3001init\u5185\u3067\u306e\u521d\u671f\u5316\u5024(\u7a7a\u6587\u5b57\u306a\u3069)\u3092\u8a31\u5bb9\u3059\u308b\u3068\u306f\u9650\u3089\u306a\u3044\u305f\u3081\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/ \u89aa\u30af\u30e9\u30b9\n@interface Parent: NSObject\n\n@property (nonatomic) NSString *name;\n\n@end\n\n@implementation Parent\n\n-(id)init{\n  &#x5B;super init];\n  _name = @&quot;john&quot;; \n  \/\/ self.name = @&quot;john&quot;; \/\/ \u30d7\u30ed\u30d1\u30c6\u30a3\u306b\u4ee3\u5165\u3059\u308b\u3068Child\u3067\u6b63\u3057\u304f\u521d\u671f\u5316\u3055\u308c\u306a\u304f\u306a\u308b\u3002\n}\n\n@end\n\n\/\/ \u5b50\u30af\u30e9\u30b9\n@interface Child: Parent\n@end\n\n@implementation Child\n-(void)setName:(NSString *)name{\n    \/\/ \u30d0\u30ea\u30c7\u30fc\u30b7\u30e7\u30f3\u30c1\u30a7\u30c3\u30af\u3067NG\u306e\u5834\u5408\u306f\u30bb\u30c3\u30c8\u3057\u306a\u3044\n  if(!name || &#x5B;name isEqualToString:@&quot;&quot;]){\n    &#x5B;NSException raise: NSInvalidArgumentException format:@&quot;name must not be empty&quot;];\n  }\n  \/\/ \uff11\u6587\u5b57\u76ee\u306f\u82f1\u5927\u6587\u5b57\u306e\u307f\u8a31\u5bb9\u3059\u308b\n  char firstChar = &#x5B;name characterAtIndex:0];\n  if(firstChar &amp;lt; &#039;A&#039; || firstChar &gt; &#039;Z&#039;){\n    &#x5B;NSException raise: NSInvalidArgumentException format:@&quot;name must start with large character.&quot;];\n  }\n  _name = name;\n}\n@end\n<\/pre>\n<p>getter\u3092\u4f7f\u3046\u3079\u304d\u4f8b\u5916\u3068\u3057\u3066\u306f\u3001\u30b3\u30b9\u30c8\u306e\u9ad8\u3044\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u9045\u5ef6\u521d\u671f\u5316\u3059\u308b\u5834\u5408\u306a\u3069\u3001\u7279\u5225\u306a\u5951\u7d04\u304c\u3042\u308b\u5834\u5408\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@interface Foo: NSObject\n\n@property (nonatomic, readdonly) HeavyObject *object; \/\/ \u4f55\u304b\u5927\u304d\u306a\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\n\n@end\n\n@implementation Foo{\n  HeavyObject *_object;\n}\n\n-(void)doSomething{\n  \/\/ NSLog(@&quot;%@&quot;,_object); \/\/ \u521d\u671f\u5316\u3055\u308c\u3066\u3044\u306a\u3044\u304a\u305d\u308c\u304c\u3042\u308b\n  NSLog(@&quot;%@&quot;,self.object); \/\/ \u3053\u3061\u3089\u306e\u307b\u3046\u304c\u5b89\u5168\n}\n\n-(HeavyObject *)object{\n  if(!_object){\n    _object = &#x5B;&#x5B;HeavyObject alloc] init];\n  }\n  return _object;\n}\n\n@end\n<\/pre>\n<h2>\u304a\u307e\u3051 &#8211; IBOutlet \u3068 IBAction<\/h2>\n<p>Xcode\u3092\u4f7f\u3063\u3066\u3044\u308b\u3068\u52dd\u624b\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u306bIBOutlet\u304c\u3064\u3044\u305f\u308a\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u306bIBAction\u304c\u3064\u3044\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@interface Foo : NSObject\n@property (nonatomic) IBOutlet UIButton *button;\n\n-(IBAction)buttonTapped:(id)sender;\n@end\n<\/pre>\n<p>\u3053\u308c\u3089\u306f.storyboard, .xib\u306a\u3069\u306eIB(Interface Builder)\u3068\u63a5\u7d9a\u3057\u3066\u3044\u308b\u30d7\u30ed\u30d1\u30c6\u30a3(IBOutlet)\u3001\u30e1\u30c3\u30bb\u30fc\u30b8(IBAction)\u3092\u8868\u3059\u30ad\u30fc\u30ef\u30fc\u30c9\u3067\u3059\u3002<\/p>\n<p>IBOutlet, IBAction\u3068\u3082\u306b\u30a4\u30f3\u30bf\u30fc\u30d5\u30a7\u30a4\u30b9\u30d3\u30eb\u30c0\u30fc\u304b\u3089\u30b3\u30fc\u30c9\u3092\u751f\u6210\u3057\u305f\u6642\u306b\u81ea\u52d5\u3067\u8a2d\u5b9a\u3055\u308c\u307e\u3059\u304c\u3001<br \/>\n\u5b9f\u969b\u306b\u306fIBOutlet\u306f\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u306f\u4f55\u306e\u610f\u5473\u3082\u306a\u304f\u3001IBAction\u306fvoid\u306e\u5225\u540d\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\uff12\u3064\u3068\u3082\u3001UIKit\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af\u306eUINibDeclarations.h\u306b\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n\/\/\n\/\/  UINibDeclarations.h\n\/\/  UIKit\n\/\/\n\/\/  Copyright (c) 2005-2014 Apple Inc. All rights reserved.\n\/\/\n\n#ifndef IBOutlet\n#define IBOutlet\n#endif\n\n#ifndef IBOutletCollection\n#define IBOutletCollection(ClassName)\n#endif\n\n#ifndef IBAction\n#define IBAction void\n#endif\n\n#ifndef IBInspectable\n#define IBInspectable\n#endif\n\n#ifndef IB_DESIGNABLE\n#define IB_DESIGNABLE\n#endif\n<\/pre>\n<p>\u3053\u306e\u3088\u3046\u306bdefine\u3067\u5b9a\u7fa9\u3055\u308c\u3066\u3044\u308b\u3060\u3051\u3067\u3059\u306e\u3067\u3001<br \/>\n\u5192\u982d\u306e\u30b3\u30fc\u30c9\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b IBOutlet \u2192 (\u524a\u9664)\u3001IBAction \u2192 void\u306b\u7f6e\u304d\u63db\u3048\u305f\u3082\u306e\u3068\u7b49\u4fa1\u3067\u3059\u3002<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n@interface Foo : NSObject\n@property (nonatomic) UIButton *button;\n\n-(void)buttonTapped:(id)sender;\n@end\n<\/pre>\n<p>\u30d7\u30ed\u30b0\u30e9\u30e0\u4e0a\u306e\u610f\u5473\u306f\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u4eba\u306e\u53ef\u8aad\u6027\u3092\u9ad8\u3081\u308b\u305f\u3081\u306b\u3082NIB(\u30b9\u30c8\u30fc\u30ea\u30fc\u30dc\u30fc\u30c9\u3084XIB)\u3068\u9023\u52d5\u3057\u3066\u3044\u308b\u30d7\u30ed\u30d1\u30c6\u30a3\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u306b\u306fIBOutlet\u3084IBAction\u3092\u660e\u793a\u3059\u308b\u307b\u3046\u304c\u3088\u3044\u3067\u3057\u3087\u3046\u3002<\/p>\n<h2>\u6700\u5f8c\u306b<\/h2>\n<p>Xcode \u3084 AppCode \u304c\u81ea\u52d5\u751f\u6210\u3001\u88dc\u5b8c\u3057\u3066\u304f\u308c\u308b\u306e\u3067\u3042\u307e\u308a\u30d7\u30ed\u30d1\u30c6\u30a3\u3001\u30e1\u30f3\u30d0\u5909\u6570\u3001\u30e1\u30c3\u30bb\u30fc\u30b8\u7b49\u306e\u4ed5\u69d8\u3092\u305d\u308c\u307b\u3069\u6c17\u306b\u3057\u306a\u304f\u3066\u3082\u66f8\u3051\u308b\u3088\u3046\u306b\u306a\u3063\u3066\u304d\u3066\u3044\u307e\u3059\u304c\u3001<br \/>\nObjective-C\u306e\u57fa\u672c\u3092\u6291\u3048\u3066\u3069\u3046\u52d5\u3044\u3066\u3044\u308b\u306e\u304b\u7406\u89e3\u3059\u308b\u3053\u3068\u3067\u304d\u308c\u3044\u306a\u4e0d\u5177\u5408\u306e\u306a\u3044\u30b3\u30fc\u30c9\u3092\u66f8\u304f\u52a9\u3051\u306b\u306a\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306f\u66f8\u7c4d Effective Objective-C 2.0 \u3092\u53c2\u8003\u306b\u3057\u3066\u3044\u307e\u3059\u3002<br \/>\n\u3055\u3089\u306b Objective-C \u306e\u4e8b\u3092\u77e5\u308b\u305f\u3081\u306b\u304a\u3059\u3059\u3081\u306e\u4e00\u518a\u3067\u3059\u3002<\/p>\n<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\">\n<tr>\n<td valign=\"top\">\n<div style=\"border:1px solid;margin:0px;padding:6px 0px;width:320px;text-align:center;float:left\"><a href=\"http:\/\/hb.afl.rakuten.co.jp\/hgc\/135d6aa4.6536984a.135d6aa5.567bb1a6\/?pc=http%3a%2f%2fitem.rakuten.co.jp%2frakutenkobo-ebooks%2f45891e2b80263702aec1530667c9a004%2f%3fscid%3daf_link_tbl&amp;m=http%3a%2f%2fm.rakuten.co.jp%2frakutenkobo-ebooks%2fi%2f12076245%2f\" target=\"_blank\"><img decoding=\"async\" src=\"http:\/\/hbb.afl.rakuten.co.jp\/hgb\/?pc=http%3a%2f%2fthumbnail.image.rakuten.co.jp%2f%400_gold%2frakutenkobo-ebooks%2fimghb%2fa9%2f51%2f45891e2b80263702aec1530667c9a004.png%3f_ex%3d300x300&amp;m=http%3a%2f%2fthumbnail.image.rakuten.co.jp%2f%400_gold%2frakutenkobo-ebooks%2fimghb%2fa9%2f51%2f45891e2b80263702aec1530667c9a004.png%3f_ex%3d80x80\" alt=\"Effective Objective-C 2.0-\u3010\u96fb\u5b50\u66f8\u7c4d\u3011\" border=\"0\" style=\"margin:0px;padding:0px\"\/><\/a><\/p>\n<p style=\"font-size:12px;line-height:1.4em;text-align:left;margin:0px;padding:2px 6px\"><a href=\"http:\/\/hb.afl.rakuten.co.jp\/hgc\/135d6aa4.6536984a.135d6aa5.567bb1a6\/?pc=http%3a%2f%2fitem.rakuten.co.jp%2frakutenkobo-ebooks%2f45891e2b80263702aec1530667c9a004%2f%3fscid%3daf_link_tbl&amp;m=http%3a%2f%2fm.rakuten.co.jp%2frakutenkobo-ebooks%2fi%2f12076245%2f\" target=\"_blank\">Effective Objective-C 2.0-\u3010\u96fb\u5b50\u66f8\u7c4d\u3011<\/a><br \/><span style=\"\">\u4fa1\u683c\uff1a3,200\u5186<\/span><\/p>\n<\/div>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Objective-C \u3067\u306a\u3093\u3068\u306a\u304f\u77e5\u3063\u3066\u3044\u308b\u3051\u3069\u5b9f\u306f\u3088\u304f\u77e5\u3089\u306a\u3044\u30d7\u30ed\u30d1\u30c6\u30a3(@property)\u307e\u308f\u308a\u306e \u57fa\u672c\u7684\u306a\u4ed5\u69d8\u3092\u307e\u3068\u3081\u307e\u3057\u305f\u3002 Xcode6.1\u304c\u6b63\u5f0f\u30ea\u30ea\u30fc\u30b9\u3055\u308c\u3066Swift\u306e\u03b2\u304c\u3068\u308c\u305f\u3057\u3001\u300cSwift\u4f7f\u3046\u304b\u3089 &hellip; <a href=\"https:\/\/www.ecoop.net\/memo\/archives\/objective-c-property-basics.html\" class=\"more-link\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"screen-reader-text\">[iOS][Objective-C] @property \u306e\u57fa\u672c\u307e\u3068\u3081<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":1256,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[117],"tags":[],"class_list":["post-1155","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios-dev"],"jetpack_featured_media_url":"https:\/\/www.ecoop.net\/memo\/wp-content\/uploads\/2014\/11\/gori0I9A3217_TP_V.jpg","_links":{"self":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1155","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/comments?post=1155"}],"version-history":[{"count":1,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1155\/revisions"}],"predecessor-version":[{"id":1156,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/posts\/1155\/revisions\/1156"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media\/1256"}],"wp:attachment":[{"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/media?parent=1155"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/categories?post=1155"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ecoop.net\/memo\/wp-json\/wp\/v2\/tags?post=1155"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}