<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>结网 &#187; 教学</title>
	<atom:link href="http://blog.liuhongwei.cn/tag/%e6%95%99%e5%ad%a6/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.liuhongwei.cn</link>
	<description>Agile, Startup, 产品管理, Google开发, iPhone开发</description>
	<lastBuildDate>Fri, 30 Jul 2010 10:31:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>In-App Purchase 培训</title>
		<link>http://blog.liuhongwei.cn/iphone/in-app-purchase/</link>
		<comments>http://blog.liuhongwei.cn/iphone/in-app-purchase/#comments</comments>
		<pubDate>Thu, 12 Nov 2009 13:40:49 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=138</guid>
		<description><![CDATA[Consumable苹果新加坡的标志居然是红苹果 http://twitpic.com/p7v5b
苹果允许在免费应用中提供购买（In-App Purchase）之后，销售模式有了全新的改变，用户们终于可以先试后买了。以后那些几个漂亮图+烂内容，用户卖完大呼上当的程序恐怕越来越没有市场了。
正好apple组织了一个In-App Purchase的培训，来瞧瞧，顺便跟开发者们交流一下。迟到了几分钟，百人小会议厅已经坐满了，茶歇的时候才发现，居然有一半洋人，很多人一身休闲打扮，穿着短裤，踏着拖鞋就来了。培训先介绍In-App Purchase，然后演示了一个具体的例子。只有一个感觉，非常的复杂。
In-App Purchase的3种类型

Consumable：一次性购买，最简单的类型，不用保存历史记录。
Nonconsumable：每个产品，用户只买一次，此后就可以在自己的所有设备上看到该产品。
Subscriptions：订阅模式允许多次购买末一个产品，但是购买后，用户可以在自己的所有设备上看到该产品。

一个典型的In-App Purchase需要4大部分的协作：your Server，App，App Store，iTune。
Your Server主要是保存交易代号，传递购买的内容；当然如果购买的内容比较简单，Server也是可以省略的。
App中内置需要购买的产品

用自己的服务器来提供需要购买的产品

后面还有一些话题，获取产品信息，在程序中添加购买的过程，向App Store验证交易收据，在iTune Connect中的配置，使用测试帐号来测试程序的购买过程等等，都很实用。
]]></description>
			<content:encoded><![CDATA[<p>Consumable苹果新加坡的标志居然是红苹果 <a href="http://twitpic.com/p7v5b">http://twitpic.com/p7v5b</a></p>
<p>苹果允许在免费应用中提供购买（<a href="http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/StoreKitGuide/Introduction/Introduction.html">In-App Purchase</a>）之后，销售模式有了全新的改变，用户们终于可以先试后买了。以后那些几个漂亮图+烂内容，用户卖完大呼上当的程序恐怕越来越没有市场了。</p>
<p>正好apple组织了一个In-App Purchase的培训，来瞧瞧，顺便跟开发者们交流一下。迟到了几分钟，百人小会议厅已经坐满了，茶歇的时候才发现，居然有一半洋人，很多人一身休闲打扮，穿着短裤，踏着拖鞋就来了。培训先介绍In-App Purchase，然后演示了一个具体的例子。只有一个感觉，非常的复杂。</p>
<p>In-App Purchase的3种类型</p>
<ul>
<li>Consumable：一次性购买，最简单的类型，不用保存历史记录。</li>
<li>Nonconsumable：每个产品，用户只买一次，此后就可以在自己的所有设备上看到该产品。</li>
<li>Subscriptions：订阅模式允许多次购买末一个产品，但是购买后，用户可以在自己的所有设备上看到该产品。</li>
</ul>
<p>一个典型的In-App Purchase需要4大部分的协作：your Server，App，App Store，iTune。</p>
<p>Your Server主要是保存交易代号，传递购买的内容；当然如果购买的内容比较简单，Server也是可以省略的。</p>
<p>App中内置需要购买的产品</p>
<p><img class="alignnone size-full wp-image-139" title="built_in_store_diagram" src="http://blog.liuhongwei.cn/wp-content/uploads/2009/11/built_in_store_diagram.jpg" alt="built_in_store_diagram" width="373" height="496" /></p>
<p>用自己的服务器来提供需要购买的产品</p>
<p><img class="alignnone size-full wp-image-140" title="store_transactions_with_server" src="http://blog.liuhongwei.cn/wp-content/uploads/2009/11/store_transactions_with_server.jpg" alt="store_transactions_with_server" width="564" height="757" /></p>
<p>后面还有一些话题，获取产品信息，在程序中添加购买的过程，向App Store验证交易收据，在iTune Connect中的配置，使用测试帐号来测试程序的购买过程等等，都很实用。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/iphone/in-app-purchase/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Google Insights揭示web2.0应用趋势</title>
		<link>http://blog.liuhongwei.cn/marketing/google-insights-web2-0/</link>
		<comments>http://blog.liuhongwei.cn/marketing/google-insights-web2-0/#comments</comments>
		<pubDate>Fri, 18 Sep 2009 15:31:55 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[市场与销售]]></category>
		<category><![CDATA[工具]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[unveil]]></category>
		<category><![CDATA[推荐]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=121</guid>
		<description><![CDATA[Google Insights是Google推出的一项服务，比Google Trends更进一步，可以显示和比较一段时间内，在各个地区，不同的关键字的热度和趋势。对于研究和分析市场趋势，有很强的指导意义。
Google Insights最多可以比较5个关键字，可以把比较的结果存放在iGoogle中，和嵌入网页。
作为示例，输入了现在比较热门的一些web2.0应用：youtube，facebook，twitter，myspace，yahoo。从比较的结果可以看出

myspace确实在走下坡路
youtube势头很猛，Google这16亿没有白花
FaceBook的上升势头，斜率最高，特别是到了2009年，迅速超越所有其他应用，难怪当年Google为其股价150亿
twitter到了2009年，确实火爆起来了，不过微型博客毕竟还是微型的，没法跟其他应用比
Yahoo虽说危机重重，不过还在稳步增长，最近Yahoo又推出了meme等一系列应用，更是让人看到了希望，web2.0时代，后来者往往才是创造奇迹的赢家。


]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft size-full wp-image-122" title="google_insight_web2.0" src="http://blog.liuhongwei.cn/wp-content/uploads/2009/09/google_insight_web2.0.png" alt="google_insight_web2.0" width="323" height="278" /><a href="http://www.google.com/insights/search/">Google Insights</a>是Google推出的一项服务，比Google Trends更进一步，可以显示和比较一段时间内，在各个地区，不同的关键字的热度和趋势。对于研究和分析市场趋势，有很强的指导意义。</p>
<p>Google Insights最多可以比较5个关键字，可以把比较的结果存放在iGoogle中，和嵌入网页。</p>
<p>作为示例，输入了现在比较热门的一些web2.0应用：youtube，facebook，twitter，myspace，yahoo。从比较的结果可以看出</p>
<ul>
<li>myspace确实在走下坡路</li>
<li>youtube势头很猛，Google这16亿没有白花</li>
<li>FaceBook的上升势头，斜率最高，特别是到了2009年，迅速超越所有其他应用，难怪当年Google为其股价150亿</li>
<li><a href="http://twitter.com/harryempire">twitter</a>到了2009年，确实火爆起来了，不过微型博客毕竟还是微型的，没法跟其他应用比</li>
<li>Yahoo虽说危机重重，不过还在稳步增长，最近Yahoo又推出了<a href="http://meme.yahoo.com/">meme</a>等一系列应用，更是让人看到了希望，web2.0时代，后来者往往才是创造奇迹的赢家。</li>
</ul>
<p><script src="http://www.gmodules.com/ig/ifr?url=http%3A%2F%2Fwww.google.com%2Fig%2Fmodules%2Fgoogle_insightsforsearch_interestovertime_searchterms.xml&amp;up__property=empty&amp;up__search_terms=facebook%7Cyoutube%7Ctwitter%7Cmyspace%7Cyahoo&amp;up__location=US&amp;up__category=0&amp;up__time_range=empty&amp;up__compare_to_category=false&amp;synd=ig&amp;w=320&amp;h=350&amp;lang=en-US&amp;title=Google+Insights+for+Search&amp;border=%23ffffff%7C3px%2C1px+solid+%23999999&amp;output=js" type="text/javascript"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/marketing/google-insights-web2-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>正式进军iPhone开发，现场直播，Day 1</title>
		<link>http://blog.liuhongwei.cn/iphone/first-iphone-dev/</link>
		<comments>http://blog.liuhongwei.cn/iphone/first-iphone-dev/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 13:43:59 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[脑图]]></category>
		<category><![CDATA[live]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=105</guid>
		<description><![CDATA[从几个月前开始学Objective C开始，断断续续也写了几个iPhone小程序了。一直想写一个复杂点的游戏，无奈，时间都花在了向往已久的巴厘岛和普吉岛。计划一次次的流产，再不发布，就成纸上谈兵了。这个周末，决定利用3天时间写出一个先，不需要太复杂，毕竟复杂度和赚钱是两回事，找一个简单点的题材开刀，先睹为快。
用在线脑图利器MindMeister写了个开发计划

截止到现在，一切按照计划，正在攻克技术问题中。
]]></description>
			<content:encoded><![CDATA[<p>从几个月前开始学<a href="http://blog.liuhongwei.cn/tag/objective-c/">Objective C</a>开始，断断续续也写了几个<a href="http://blog.liuhongwei.cn/category/iphone/">iPhone</a>小程序了。一直想写一个复杂点的游戏，无奈，时间都花在了向往已久的<a href="http://blog.sina.com.cn/s/articlelist_1400116791_3_1.html">巴厘岛</a>和<a href="http://blog.sina.com.cn/s/articlelist_1400116791_4_1.html">普吉岛</a>。计划一次次的流产，再不发布，就成纸上谈兵了。这个周末，决定利用3天时间写出一个先，不需要太复杂，毕竟复杂度和赚钱是两回事，找一个简单点的题材开刀，先睹为快。</p>
<p>用<a style="color: #2970a6; text-decoration: none; padding: 0px; margin: 0px;" title="在线脑图制作利器：MindMeister" href="http://blog.liuhongwei.cn/web2/gtd-mindmeister/">在线脑图利器MindMeister</a>写了个开发计划</p>
<p><img class="alignnone size-full wp-image-107" title="first iphone app plan" src="http://blog.liuhongwei.cn/wp-content/uploads/2009/08/first-iphone-dev.gif" alt="first iphone app plan" width="696" height="460" /></p>
<p>截止到现在，一切按照计划，正在攻克技术问题中。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/iphone/first-iphone-dev/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Agile项目半年记，Agile脑图</title>
		<link>http://blog.liuhongwei.cn/agile/agile-mindmap/</link>
		<comments>http://blog.liuhongwei.cn/agile/agile-mindmap/#comments</comments>
		<pubDate>Sat, 25 Jul 2009 03:40:58 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[Agile开发]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=86</guid>
		<description><![CDATA[做这个Agile项目也有半年了，经历了1次release，几次iteration，完成的大小不一的story也有30多个了，还有deadline临近时的繁忙。7年前在书上读过的那些关于Agile和XP的概念和名词，一直没太多机会完整地实践，现在却是天天在用。近来闲暇，正好用在线工具MindMeister，结合工作笔记和培训资料，画了一个Agile脑图，汇总一下这半年的收获。
Agile作为一个知识体系，内容很复杂，脑图有点大，时间有限，暂时没有设置太多关联，只是简单按照层级列了一下，以后慢慢补上。这也是正是脑图的一个优势，当事情层级比较多、关系比较复杂的时候，使用脑图比较容易理清脉络。
]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.liuhongwei.cn/wp-content/uploads/2009/07/agile-mindmap.gif"><img class="alignleft size-medium wp-image-87" title="agile mindmap" src="http://blog.liuhongwei.cn/wp-content/uploads/2009/07/agile-mindmap-231x300.gif" alt="agile mindmap" width="231" height="300" /></a>做这个Agile项目也有半年了，经历了1次release，几次iteration，完成的大小不一的story也有30多个了，还有deadline临近时的繁忙。7年前在书上读过的那些关于Agile和XP的概念和名词，一直没太多机会完整地实践，现在却是天天在用。近来闲暇，正好用在线工具<a href="http://blog.liuhongwei.cn/web2/gtd-mindmeister/">MindMeister</a>，结合工作笔记和培训资料，画了一个Agile脑图，汇总一下这半年的收获。</p>
<p>Agile作为一个知识体系，内容很复杂，脑图有点大，时间有限，暂时没有设置太多关联，只是简单按照层级列了一下，以后慢慢补上。这也是正是脑图的一个优势，当事情层级比较多、关系比较复杂的时候，使用脑图比较容易理清脉络。</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/agile/agile-mindmap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>zt Objective C 入门诗，iPhone程序结构</title>
		<link>http://blog.liuhongwei.cn/iphone/objective-c-poetry-iphone-structure/</link>
		<comments>http://blog.liuhongwei.cn/iphone/objective-c-poetry-iphone-structure/#comments</comments>
		<pubDate>Sun, 28 Jun 2009 00:21:35 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=68</guid>
		<description><![CDATA[Objective C 快速入门诗
C没有类
这让人很疲惫
对象的说法很时髦
不就是继承封装组合人人会
右走是C++，这个大众都熟悉它
左走就是objective-c，躲在僻静僻静的麦金塔
本是同根生的C
如何高举面向对象的大旗
求同存异标新立异且听一一细分清

对象的C
是不同的C
类的处理与众不同重点要区分

不重复是我的口头禅
任何时候我只说一次告诉你我的地盘
    [@begincommand] &#124; @end就是我的指示
        @interface classname  声明类
        @implementation classname  实现类
        @protocol interfacename  声明接口
就是这么简单，你的一定要明白

我先声明对成员变量和方法的关系有远近
    成员变量大大括在我的怀
        关系远近 public [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Objective C 快速入门诗</strong></p>
<pre style="line-height: 22px; padding: 0px; margin: 0px;">C没有类
这让人很疲惫
对象的说法很时髦
不就是继承封装组合人人会
右走是C++，这个大众都熟悉它
左走就是objective-c，躲在僻静僻静的麦金塔
本是同根生的C
如何高举面向对象的大旗
求同存异标新立异且听一一细分清

对象的C
是不同的C
类的处理与众不同重点要区分

不重复是我的口头禅
任何时候我只说一次告诉你我的地盘
    [@begincommand] | @end就是我的指示
        @interface classname  声明类
        @implementation classname  实现类
        @protocol interfacename  声明接口
就是这么简单，你的一定要明白

我先声明对成员变量和方法的关系有远近
<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><span style="line-height: 22px; color: #000000; padding: 0px; margin: 0px;">    </span><strong>成员变量大大括在我的怀</strong></span>
        关系远近 public / protected / private 来区分
        若不声明全默默受着保护
        静态成员变量请不要放在此
    成员方法我不太爱
        前面拴着绳子置于类的变量列表外
<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><span style="line-height: 22px; color: #000000; padding: 0px; margin: 0px;">            </span><strong>减号就是普通函数</strong></span>
<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><span style="line-height: 22px; color: #000000; padding: 0px; margin: 0px;">            </span><strong>加号就是静态函数</strong></span>莫怪
        函数的声明有点怪
            我要一眼叫出名，包括函数名和参数名
            其余的<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><strong>类型括起来</strong></span>，我有空再来慢慢看
            函数名和参数名之间用：分隔开
        多个参数的函数那就是更怪
            逗号其实不是我的爱
            后续的每个参数分隔用空白
            每个参数形式如 <span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><strong>标签：(参数类型)参数名</strong></span>
            其实只要把函数名看作是第一个参数标签
            你就能领悟其中的奥妙并在调用时喜爱
        成员方法太多我才懒得区分亲疏远近
            它们一律都是公之于众要好好的干活
            谁若不服胆敢出头犯上
            就踢出头文件打入冷宫永世不能露面试试看
<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><span style="line-height: 22px; color: #000000; padding: 0px; margin: 0px;">        </span><strong>所有的成员方法都是虚函数</strong></span>
            改则重载，不改就继承
            不用任何标记请放心大胆随便使用

对象的类，在继承层次上考虑才显得重要
    所有的类最终都继承于NSObject
        因为它给你创建自己生命的方法

    不继承于NSObject的只能是接口protocol
        它没有成员变量只有方法
        它只有声明不用实现
        这点和java很相似

当然类还有一些绝活可以让你开开眼
    可以动态的扩充一个类 而不总是用继承
        @interface CClassA(Category)|@end
        @implementation CClassA (Category)|@end
        源代码外包含该 类的头文件
        就可以使用该Category中的方法

也可以动态的替换一个类
    但是只限于用继承类来替换基类功能
        [CInheritClass poseAsClass: [CBaseClass class]];
    声明之后用基类创建的对象实际上行为都是继承类

所以一个类的完整声明如下：
<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><span style="line-height: 22px; color: #000000; padding: 0px; margin: 0px;">    </span><strong>@interface CClassA(Category): CBaseClass&lt;IA,IB...&gt;</strong></span>
    类别，基类，接口一一具全
    加上静态 虚函数
    所有特性和C++均可对应
    再加上所独有的特性
    这一特性编译类语言很少有
    设计得当完全可以实现动态调用dll切换功能

类的定义和使用，也有点怪
    想想看一个对象的生命周期，该是如何办
        创建很是别扭
            这样就定义了一个类对象，
            CClassName* pA = [[CClassName alloc] init];
            能且只能返回对象指针
    释放分为两种
        自动释放声明后 [pA autorelease]; 以后可以不管
        否则就必须配对 [pA release];
    注意类的构造函数init可以捕获
    但是<span style="line-height: 22px; color: #0000ff; padding: 0px; margin: 0px;"><strong>析构函数却没有</strong></span>这点很让人意外

    使用类也有多种情况
        调用成员方法用中括号     int nRtn = [pA method:param1];
        而静态成员方法不需要对象 int nRtn = [CClassName method];
        调用成员变量还是C格式    pA-&gt;m_nCount = 1;

    所有的类，都可以对应一个id类型
        用来引用一个对象               id     cur = sq;
        或者用来引用一个对象指定的接口 id&lt;IA&gt; cur = sq;
        然后就可以调用该对象的方法和指定接口方法</pre>
<p><strong>Iphone APP程序结构</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/iphone/objective-c-poetry-iphone-structure/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>从 C 到 Objective C 入门2</title>
		<link>http://blog.liuhongwei.cn/iphone/objective-c-2/</link>
		<comments>http://blog.liuhongwei.cn/iphone/objective-c-2/#comments</comments>
		<pubDate>Sun, 14 Jun 2009 07:39:22 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=54</guid>
		<description><![CDATA[在Objective C入门中我们了解了如何定义类，类的实现，以及调用类函数的方式。现在再来看一看关于类的高级概念。
id，动态绑定

#import &#60;stdio.h&#62;
#import &#34;Bank.h&#34;
&#160;
int main&#40; int argc, const char *argv&#91;&#93; &#41; &#123;
    Bank *bank1= &#91;&#91;Bank alloc&#93; init&#93;;
    Bank *bank2= &#91;&#91;Bank alloc&#93; init&#93;;
    id b; //可以把任何对象赋值给b
&#160;
    &#91;bank1 addAmount: 1&#93;;
    b = bank1;
    &#91;b print&#93;; //调用bank1的print函数
    [...]]]></description>
			<content:encoded><![CDATA[<p>在<a href="http://blog.liuhongwei.cn/iphone/objective-c/">Objective C入门</a>中我们了解了如何定义类，类的实现，以及调用类函数的方式。现在再来看一看关于类的高级概念。</p>
<h2>id，动态绑定</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;stdio.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Bank.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span> <span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    Bank <span style="color: #002200;">*</span>bank1<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    Bank <span style="color: #002200;">*</span>bank2<span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
    <span style="color: #a61390;">id</span> b; <span style="color: #11740a; font-style: italic;">//可以把任何对象赋值给b</span>
&nbsp;
    <span style="color: #002200;">&#91;</span>bank1 addAmount<span style="color: #002200;">:</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
    b <span style="color: #002200;">=</span> bank1;
    <span style="color: #002200;">&#91;</span>b print<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//调用bank1的print函数</span>
    b <span style="color: #002200;">=</span> bank2;
    <span style="color: #002200;">&#91;</span>b print<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//调用bank2的print函数</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// true</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>bank1 isMemberOfClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>Bank class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #a61390;">YES</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;bank1是Bank类的一个对象<span style="color: #2400d9;">\n</span>&quot;</span> <span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// true</span>
    <span style="color: #a61390;">if</span> <span style="color: #002200;">&#40;</span> <span style="color: #002200;">&#91;</span>bank1 respondsToSelector<span style="color: #002200;">:</span> <span style="color: #a61390;">@selector</span><span style="color: #002200;">&#40;</span> addAmount<span style="color: #002200;">:</span> <span style="color: #002200;">&#41;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">==</span> <span style="color: #a61390;">YES</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
        <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;bank1响应addAmount:函数<span style="color: #2400d9;">\n</span>&quot;</span> <span style="color: #002200;">&#41;</span>;
    <span style="color: #002200;">&#125;</span>
&nbsp;
    <span style="color: #11740a; font-style: italic;">// free memory</span>
    <span style="color: #002200;">&#91;</span>bank1 <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>;
    <span style="color: #002200;">&#91;</span>b <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<p>id类型可以接受各种类型的对象，然后调用对应的函数。调用函数时，Objective C在编译的时候并不会检查该对象是否有该函数，需要开发人员自己确保调用的有效。另外Objective C也提供功能，在运行时检查某对象是否具有某函数。</p>
<h2>类的高级使用：继承、类别、扮演、协议</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #11740a; font-style: italic;">////////////// BankMath.h</span>
<span style="color: #6e371a;">#import &quot;Bank.h&quot;</span>
<span style="color: #a61390;">@interface</span> Bank<span style="color: #002200;">&#40;</span>Math<span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//为类Bank定义一个类别Math</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> add<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> b; <span style="color: #11740a; font-style: italic;">//Math中的函数add</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> sub<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> b; <span style="color: #11740a; font-style: italic;">//Math中的函数sub</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@protocol</span> Auditable <span style="color: #11740a; font-style: italic;">//定义一个协议</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> audit; <span style="color: #11740a; font-style: italic;">//其中包括一个函数audit的定义</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@interface</span> ExBank<span style="color: #002200;">:</span> Bank&lt;Auditable&gt; <span style="color: #11740a; font-style: italic;">//ExBank类继承Bank，同时实现Auditable协议</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print; <span style="color: #11740a; font-style: italic;">//定义一个新的函数print，覆盖父类Bank中的print函数</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">////////////// 实现部分 BankMath.m</span>
<span style="color: #6e371a;">#import &quot;BankMath.h&quot;</span>
<span style="color: #a61390;">@implementation</span> Bank <span style="color: #002200;">&#40;</span>Math<span style="color: #002200;">&#41;</span> <span style="color: #11740a; font-style: italic;">//Bank的类别Math的实现部分</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> add<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> f <span style="color: #002200;">&#123;</span>
    amount <span style="color: #002200;">++</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> sub<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> f <span style="color: #002200;">&#123;</span>
    amount <span style="color: #002200;">--</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> ExBank
<span style="color: #11740a; font-style: italic;">// 实现新定义的函数print</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;ExBank amount=%i&quot;</span>, amount<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #11740a; font-style: italic;">// 实现协议中包含的函数audit</span>
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> audit <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;audit: amount=%i&quot;</span>, amount<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
<span style="color: #a61390;">@end</span>
&nbsp;
<span style="color: #11740a; font-style: italic;">////////////// main.m</span>
<span style="color: #6e371a;">#import  &lt;stdio.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Bank.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span> <span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    Bank <span style="color: #002200;">*</span>bank <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
     <span style="color: #002200;">&#91;</span>bank add<span style="color: #002200;">:</span> <span style="color: #2400d9;">10</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//直接使用Bank对象类别Math中的函数</span>
     <span style="color: #002200;">&#91;</span>bank sub<span style="color: #002200;">:</span> <span style="color: #2400d9;">5</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//直接使用Bank对象类别Math中的函数</span>
     <span style="color: #002200;">&#91;</span>bank print<span style="color: #002200;">&#93;</span>;
&nbsp;
     <span style="color: #002200;">&#91;</span>ExBank poseAsClass<span style="color: #002200;">:</span> <span style="color: #002200;">&#91;</span>Bank class<span style="color: #002200;">&#93;</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//使用ExBank来扮演Bank</span>
     Bank <span style="color: #002200;">*</span>bank2 <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//对Bank的调用，就是对ExBank的调用</span>
     <span style="color: #002200;">&#91;</span>bank2 print<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//调用ExBank的print函数</span>
    <span style="color: #002200;">&#91;</span>bank2 audit<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//调用ExBank的audit函数</span>
&nbsp;
    <span style="color: #a61390;">id</span> auditable <span style="color: #002200;">=</span> bank2; <span style="color: #11740a; font-style: italic;">//为auditable赋值bank2</span>
    <span style="color: #002200;">&#91;</span>auditable audit<span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">//调用bank2的函数audit</span>
    <span style="color: #11740a; font-style: italic;">//[auditable print]; //不行，因为Auditable类型中没有该函数</span>
&nbsp;
     <span style="color: #002200;">&#91;</span>bank <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// 释放对象</span>
    <span style="color: #002200;">&#91;</span>bank2 <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// 释放对象</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li>
<div lang="objc">类定义@interface，相当于Java和C++中的class</div>
</li>
<li>
<div lang="objc">继承，与Java继承类似，没有C++中继承的那么多繁琐的访问范围差别</div>
</li>
<li>
<div lang="objc">类别（categories），是用来扩展类的好办法，比继承更方便，因为你不需要有源代码就可以扩充某个类。</div>
</li>
<li>
<div lang="objc">扮演（Posting），可以在运行时指定用某个类A来替代另一个类B，这样此后所有对B的调用都是对A的调用。</div>
</li>
<li>
<div lang="objc">协议（@protocol），相当于Java的接口，或C++的abstract class。定义在其中的函数只有定义而不需要实现。使用协议的时候，一个类可以实现多个协议，多个协议之间用逗号分隔列出。</div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/iphone/objective-c-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>从 C 到 Objective C 入门1</title>
		<link>http://blog.liuhongwei.cn/iphone/objective-c/</link>
		<comments>http://blog.liuhongwei.cn/iphone/objective-c/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 00:35:30 +0000</pubDate>
		<dc:creator>Harry</dc:creator>
				<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[教学]]></category>

		<guid isPermaLink="false">http://blog.liuhongwei.cn/?p=34</guid>
		<description><![CDATA[进军iPhone开发，最大的难点之一就是怪异的Objective C语法了。不过，了解之后才发现，原来仅仅是形式上与C++、Java有差异，属于换汤不换药。如果有C语言基础，又用过C++、Java，2天之内掌握Objective C，没有问题，至少看例子程序会感觉顺眼很多。
Objective C脱胎于C语言，苹果版的开发编译环境就是大名鼎鼎的Xcode，其中的Cocoa就是Objective C库函数。
与C语言一致的部分

int main&#40; int argc, const char *argv&#91;&#93; &#41; &#123;
    printf&#40; &#34;hello worldn&#34; &#41;;
    return 0;
&#125;


数据类型，表达式，各种运算符
循环：for, while, do while, break, continue
分支：if, else, switch

类定义@interface

#import &#60;Foundation/NSObject.h&#62;
&#160;
@interface Bank: NSObject &#123;
    NSString *name;
    int amount;
&#125;
&#160;
-&#40;void&#41; print;
-&#40;void&#41; addAmount: &#40;int&#41; a;
-&#40;int&#41; amount;
-&#40;Bank *&#41; initWithName: &#40;NSString *&#41; [...]]]></description>
			<content:encoded><![CDATA[<p>进军iPhone开发，最大的难点之一就是怪异的Objective C语法了。不过，了解之后才发现，原来仅仅是形式上与C++、Java有差异，属于换汤不换药。如果有C语言基础，又用过C++、Java，2天之内掌握Objective C，没有问题，至少看例子程序会感觉顺眼很多。</p>
<p>Objective C脱胎于C语言，苹果版的开发编译环境就是大名鼎鼎的Xcode，其中的Cocoa就是Objective C库函数。</p>
<h2>与C语言一致的部分</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span> <span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span> <span style="color: #bf1d1a;">&quot;hello worldn&quot;</span> <span style="color: #002200;">&#41;</span>;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li>数据类型，表达式，各种运算符</li>
<li>循环：for, while, do while, break, continue</li>
<li>分支：if, else, switch</li>
</ul>
<h2>类定义@interface</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/NSObject.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@interface</span> Bank<span style="color: #002200;">:</span> <span style="color: #400080;">NSObject</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span>name;
    <span style="color: #a61390;">int</span> amount;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> addAmount<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> a;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> amount;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>Bank <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> initWithName<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> n andAmount<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> a;
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>写在Bank.h中</li>
<li>#import是引入库函数</li>
<li>@interface是表明定义了一个类，冒号后面是父类类型</li>
<li>两个大括号之间的部分就是类的成员变量，只有类函数能够直接访问</li>
<li>- 表明要定义一个类对象级别的函数；如果是+，表明要定义类级别的函数</li>
<li>返回值与参数的类型放在()内</li>
<li>函数定义中的: 表明后面会跟一个参数</li>
<li>如果函数有多个参数，要写多个xxx:</li>
<li>类的函数定义结束后，使用@end关闭</li>
</ul>
<h2>类实现@implementation</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &quot;Bank.h&quot;</span>
<span style="color: #6e371a;">#import &lt;Foundation/NSObject.h&gt;</span>
<span style="color: #6e371a;">#import &lt;Foundation/NSString.h&gt;</span>
&nbsp;
<span style="color: #a61390;">@implementation</span> Bank
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> print <span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">printf</span><span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">&quot;Total amount is %i&quot;</span>, amount<span style="color: #002200;">&#41;</span>;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">void</span><span style="color: #002200;">&#41;</span> addAmount<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> a <span style="color: #002200;">&#123;</span>
    amount <span style="color: #002200;">+=</span> a;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> amount<span style="color: #002200;">&#123;</span>
    <span style="color: #a61390;">return</span> amount;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #002200;">-</span><span style="color: #002200;">&#40;</span>Bank <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> initWithName<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #400080;">NSString</span> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span> n andAmount<span style="color: #002200;">:</span> <span style="color: #002200;">&#40;</span><span style="color: #a61390;">int</span><span style="color: #002200;">&#41;</span> a<span style="color: #002200;">&#123;</span>
    self <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span>super init<span style="color: #002200;">&#93;</span>;
    name <span style="color: #002200;">=</span> n;
    amount <span style="color: #002200;">=</span> a;
    <span style="color: #a61390;">return</span> self;
<span style="color: #002200;">&#125;</span>
&nbsp;
<span style="color: #a61390;">@end</span></pre></div></div>

<ul>
<li>写在Bank.m</li>
<li>@implementation定义函数的具体内容，后面接着类名</li>
<li>函数头按照定义来写</li>
<li>最后用@end来结束所有函数体</li>
</ul>
<h2>调用写好的类和类函数</h2>

<div class="wp_syntax"><div class="code"><pre class="objc" style="font-family:monospace;"><span style="color: #6e371a;">#import &lt;Foundation/NSObject.h&gt;</span>
<span style="color: #6e371a;">#import &lt;Foundation/NSString.h&gt;</span>
<span style="color: #6e371a;">#import &quot;Bank.h&quot;</span>
&nbsp;
<span style="color: #a61390;">int</span> main<span style="color: #002200;">&#40;</span> <span style="color: #a61390;">int</span> argc, <span style="color: #a61390;">const</span> <span style="color: #a61390;">char</span> <span style="color: #002200;">*</span>argv<span style="color: #002200;">&#91;</span><span style="color: #002200;">&#93;</span> <span style="color: #002200;">&#41;</span> <span style="color: #002200;">&#123;</span>
    <span style="color: #11740a; font-style: italic;">//创建新对象，使用缺省初始化函数</span>
    Bank <span style="color: #002200;">*</span>bankDefault <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> init<span style="color: #002200;">&#93;</span>;
&nbsp;
   <span style="color: #11740a; font-style: italic;">//创建新对象，使用自定义初始化函数</span>
   Bank <span style="color: #002200;">*</span>bank <span style="color: #002200;">=</span> <span style="color: #002200;">&#91;</span><span style="color: #002200;">&#91;</span>Bank alloc<span style="color: #002200;">&#93;</span> initWithName<span style="color: #002200;">:</span> <span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;Harry&quot;</span> andAmount<span style="color: #002200;">:</span> <span style="color: #2400d9;">28</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>bank addAmount<span style="color: #002200;">:</span> <span style="color: #2400d9;">1</span><span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>bank print<span style="color: #002200;">&#93;</span>;
&nbsp;
    <span style="color: #002200;">&#91;</span>bank <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// 释放对象</span>
   <span style="color: #002200;">&#91;</span>bankDefault <span style="color: #a61390;">free</span><span style="color: #002200;">&#93;</span>; <span style="color: #11740a; font-style: italic;">// 释放对象</span>
&nbsp;
    <span style="color: #a61390;">return</span> <span style="color: #2400d9;">0</span>;
<span style="color: #002200;">&#125;</span></pre></div></div>

<ul>
<li>调用类函数的时候，首先创建并初始化对象。这里我们使用缺省的init和我们自定义的initWithName来分别初始化一个对象；</li>
<li>使用[]来调用函数，按照次序分别是：对象名，函数名，: 参数值（如果有），函数名第二部分（如果有），:第二参数值（如果有）；</li>
</ul>
<h2>参考：</h2>
<ul>
<li>Objective C编程，书的精简版：<a href="http://www.otierney.net/objective-c.html.zh-tw.big5">http://www.otierney.net/objective-c.html.zh-tw.big5</a></li>
<li>Objective-C语法快速入门：<a href="http://www.cocoachina.com/index.php/archives/cocoachina_122.html">http://www.cocoachina.com/index.php/archives/cocoachina_122.html</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.liuhongwei.cn/iphone/objective-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
