{"id":862,"date":"2013-08-21T06:33:07","date_gmt":"2013-08-21T06:33:07","guid":{"rendered":"http:\/\/tw.newtonstudio.com\/?p=862"},"modified":"2013-08-21T07:17:23","modified_gmt":"2013-08-21T07:17:23","slug":"objective-c-%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98","status":"publish","type":"post","link":"https:\/\/tw.newtonstudio.com\/?p=862","title":{"rendered":"Objective C \u5b78\u7fd2\u7b46\u8a18 (part 1): \u57fa\u790e"},"content":{"rendered":"<h4>\u57fa\u790e<\/h4>\n<ol>\n<li>Objective C\u5176\u5be6\u662fC\u7684superset\uff0c\u6240\u6709\u4e4b\u524d\u5b78\u904e\u7684\uff23\u8a9e\u8a00\u8a9e\u6cd5\u5728Objective C\u88e1\u9762\u90fd\u53ef\u4ee5\u4f7f\u7528\uff0c\u800cObjective C\u70baC\u589e\u52a0\u4e86\u4e00\u4e9b\u529f\u80fd\u3002<\/li>\n<li>\u5b78\u7fd2Objective C\u6709\u500b\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff0c\u5b83\u4e0d\u50cf.NET\u8207JAVA\u90a3\u6a23\u6703\u6709\u7cfb\u7d71\u4f5cGarbage Collection\uff0c\u4e00\u5207\u8a18\u61b6\u9ad4\u7ba1\u7406\u90fd\u8981\u81ea\u5df1\u4f86\u3002<\/li>\n<li>\u5efa\u8b70\u5728\u5efa\u7acbObjective C\u5c08\u6848\u7684\u6642\u5019\u4e0d\u8981\u4f7f\u7528Automatic Reference Counting\uff0c\u56e0\u70ba\u4ed6\u4e26\u4e0d\u662f\u50cfGarbage Collection\u90a3\u9ebc\u7684\u81ea\u52d5\u5316\uff0c\u7d14\u7cb9\u53ea\u662f\u5728\u7de8\u8b6f\u7684\u6642\u5019\u5e6b\u4f60\u52a0\u4e00\u4e9b\u8ddf\u8a18\u61b6\u9ad4\u76f8\u95dc\u7684statement\u800c\u5df2\uff0c\u8655\u7406\u4e0d\u597d\u53ef\u80fd\u9084\u6703\u9020\u6210memory\u7684\u554f\u984c\u3002<\/li>\n<li>\u70ba\u751a\u9ebcObjective C\u7684NSString,NSOject\u9019\u4e9b\u7269\u4ef6\u524d\u9762\u90fd\u6709&#8221;NS&#8221;? \u5176\u5be6NS\u7684\u662f&#8221;NeXtStep&#8221; \u7684\u7e2e\u5beb, \u7531\u9019\u5bb6\u516c\u53f8\u6240\u958b\u767c\u7684\u7a0b\u5f0f\u8a9e\u8a00\u3002<\/li>\n<li>Nil \u8207 Null\u7684\u5dee\u5225\uff1fNil\u662f\u4e00\u500b\u7269\u4ef6\uff0c\u4ed6\u53ef\u4ee5\u88ab\u64cd\u4f5c[nil message],\u4f46NULL\u5c31\u662f\u4e00\u500b\u7a7a\u7269\u4ef6\uff0c\u64cd\u4f5c\u7a7a\u7684\u7269\u4ef6\u7a0b\u5f0f\u6703\u6b7b\u6389\uff0c\u4f46nil\u4e0d\u6703\u3002<\/li>\n<li>include\u7684\u90e8\u5206 &lt; &#8230; &gt; \u8207 &#8220;&#8221;&#8230;&#8221;&#8221; \u7684\u5dee\u5225? \u524d\u8005\u662f\u7cfb\u7d71\u63d0\u4f9b\u7684.h\u6a94\uff0c\u5f8c\u8005\u662f\u4f7f\u7528\u81ea\u5df1\u5efa\u7acb\u7684\u3002<\/li>\n<li>NSLog \u8207 printf \u7684\u5dee\u5225? NSLog \u662f\u771f\u7684\u6703\u5beb\u9032\u7a0b\u5f0f\u65e5\u8a8c\u6a94\uff0c\u6240\u4ee5\u5982\u679c\u53ea\u662f\u5e73\u5e38\u7a0b\u5f0fdebug\u5176\u5be6\u53ef\u4ee5\u7528printf (\u5982\u679c\u4e0d\u662f\u5bebiOS\u7684\u8a71)<\/li>\n<li>NSString \u7684\u8868\u793a\u65b9\u6cd5 @&#8221;&#8230;&#8221; \u8207 C\u7684char array \u7528\u6cd5\u5b8c\u5168\u4e0d\u540c, \u4e0d\u80fd\u7576\u6210\u540c\u4e00\u7a2e\u6771\u897f\u3002<\/li>\n<li>\u8b8a\u6578\u7684\u547d\u540d\u8981\u6709\u610f\u7fa9\uff0c\u539f\u5247\u4e0a\u5982\u679c\u7a0b\u5f0f\u78bc\u5beb\u5f97\u5920\u597d\uff0c\u5b83\u672c\u8eab\u5c31\u662f\u4e00\u500b\u8a3b\u89e3\u3002<\/li>\n<\/ol>\n<h4>\u4f7f\u7528\u65b9\u6cd5 Method<\/h4>\n<ol>\n<li>[myObject someMethod:argument];<\/li>\n<li>\u5b83\u4e0d\u50cfJAVA\u662f\u7528 &#8220;.&#8221; (\u5982 myObject.someMethod), &#8220;.&#8221; \u5728Objective C\u6709\u5225\u7684\u610f\u7fa9\u5b58\u5728\uff0c\u7a0d\u5f8c\u6703\u89e3\u91cb\u3002<\/li>\n<li>Method\u7684\u53c3\u6578\u5beb\u6cd5\u76f8\u7576\u7279\u5225\uff0c\u5b83\u7684\u539f\u610f\u662f\u5e0c\u671b\u6574\u500bMethod\u5ff5\u8d77\u4f86\u5c31\u50cf\u4e00\u500b\u53e5\u5b50\u4e00\u6a23\uff0c\u53c3\u6578\u4e4b\u9593\u7528\u7a7a\u683c\u9593\u9694\uff0c\u683c\u5f0f\u5982\u4e0b\uff1a<br \/>\n-(void)setBrand:(NSString *)brandname isA:(NSString *)type whichcost:(int) price;<\/li>\n<\/ol>\n<h4>Header File<\/h4>\n<div>\n<ol>\n<li>\u7528\u4f86\u5ba3\u544a\u9019\u500b\u7269\u4ef6\/\u5354\u5b9a\u6709\u54ea\u4e9b\u6210\u54e1(\u5982attribute\u8207method)\uff0c\u8a18\u5f97\u5728Objective C\u4e2d\u4e0d\u80fd\u5236\u5b9a\u521d\u503c\uff08\u6163\u6027\u4e0a\u6703\u5728init\u88e1\u9762\u4f5c\u521d\u503c\u7684\u6307\u5b9a\uff09<\/li>\n<li>\u683c\u5f0f\u5982\u4e0b\uff1a(import\u5f8c\u9762\u4e0d\u9700\u8981\u5206\u865f), attribute\u90fd\u662f\u5305\u5728{ }\u4e4b\u9593\uff0cmethod\u5beb\u5728{}\u4e4b\u5f8c\uff0c&#8221;-&#8221; \u4ee3\u8868\u7684\u662f\u5be6\u9ad4\u65b9\u6cd5\u3002&#8221;+&#8221;\u4ee3\u8868\u7684\u662f\u975c\u614b\u65b9\u6cd5<\/li>\n<\/ol>\n<blockquote>\n<div>#import &lt;Foundation\/Foundation.h&gt;<\/div>\n<div>@interface A : NSObject {<\/div>\n<div>NSString *brand;<\/div>\n<div>CGFloat size;<\/div>\n<div>BOOL power;<\/div>\n<div>NSDate *creationDate;<\/div>\n<div>}<\/div>\n<div>-(void)ma;<\/div>\n<div>@end<\/div>\n<\/blockquote>\n<div>\u88dc\u5145: \u4e00\u822c\u4e0a\u6211\u5011\u7684\u8a8d\u77e5\u662fvoid\u662f\u4e00\u7a2e\u4e0d\u6703\u56de\u50b3\u6771\u897f\u7684\u65b9\u6cd5\uff0c\u4f46\u4e8b\u5be6\u4e0a(void)\u672c\u8eab\u5c31\u662f\u4e00\u500b\u578b\u614b\uff0c\u56de\u50b3\u7684\u4e5f\u662fvoid\u3002<\/div>\n<\/div>\n<h4>\u5efa\u7acb\u5be6\u9ad4\u7269\u4ef6\u7684\u65b9\u5f0f<\/h4>\n<div>\n<ol>\n<li>\u5118\u91cf\u4e0d\u8981\u7528 new, \u7528 alloc, \u56e0\u70ba new \u5176\u5be6\u5305\u542b\u4e86\u5169\u500b\u52d5\u4f5c: alloc \u52a0 init, \u4e26\u4e0d\u662f\u6240\u6709\u7684\u7269\u4ef6\u90fd\u6703\u4ee5init\u958b\u59cb, \u53ef\u80fd\u6703initWithXXX, \u6240\u4ee5\u8207\u5176\u9019\u6a23\u4e0d\u5982\u5c31\u81ea\u5df1alloc\u4e4b\u5f8c\u518d\u6311init\u7684\u65b9\u6cd5\uff0c\u6211\u5011\u5e38\u770b\u5230\u7684\u5beb\u6cd5\u5c31\u6703\u9019\u6a23\uff1a<\/li>\n<\/ol>\n<blockquote>\n<div>A *a = [[A alloc] init];<\/div>\n<div>[a release]; \/\/\u7269\u4ef6\u90fd\u8981\u8a18\u5f97release, \u4ed6\u5011\u6703\u6210\u5c0d\u51fa\u73fe<\/div>\n<\/blockquote>\n<div><a title=\"Part 2\" href=\"http:\/\/tw.newtonstudio.com\/?p=868\">\u7e7c\u7e8cPart 2<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>\u57fa\u790e Objective C\u5176\u5be6\u662fC\u7684superset\uff0c\u6240\u6709\u4e4b\u524d\u5b78\u904e\u7684\uff23\u8a9e\u8a00\u8a9e\u6cd5\u5728Objective C\u88e1\u9762\u90fd [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[198],"tags":[],"class_list":["post-862","post","type-post","status-publish","format-standard","hentry","category-objectivec"],"_links":{"self":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/862","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=862"}],"version-history":[{"count":7,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/862\/revisions"}],"predecessor-version":[{"id":874,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=\/wp\/v2\/posts\/862\/revisions\/874"}],"wp:attachment":[{"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=862"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=862"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tw.newtonstudio.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=862"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}