﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-Kuai. Man. Zhi. Jian-随笔分类-MAC &amp; iPhone</title><link>http://www.cnitblog.com/rolandash/category/8624.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 29 Sep 2011 15:04:22 GMT</lastBuildDate><pubDate>Thu, 29 Sep 2011 15:04:22 GMT</pubDate><ttl>60</ttl><item><title>MAC 开发笔记 － Objective-C 语法</title><link>http://www.cnitblog.com/rolandash/archive/2010/03/21/64765.html</link><dc:creator>陆宁</dc:creator><author>陆宁</author><pubDate>Sun, 21 Mar 2010 10:07:00 GMT</pubDate><guid>http://www.cnitblog.com/rolandash/archive/2010/03/21/64765.html</guid><wfw:comment>http://www.cnitblog.com/rolandash/comments/64765.html</wfw:comment><comments>http://www.cnitblog.com/rolandash/archive/2010/03/21/64765.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/rolandash/comments/commentRss/64765.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/rolandash/services/trackbacks/64765.html</trackback:ping><description><![CDATA[
MAC平台上一个重要的开发语言是Objective C。Objective C看起来和C有那么一点关系——没错，它是基于C的面向对象的扩展，但是它又不是C++。严格地说，Objective C更象是在C的基础上，Smalltalk的另外一个实现。<br><br>Selector是Objective C语法上的一个特色。没有接触过Smalltalk等纯对象语言的朋友可能对Selector的概念感到难以理解，不过如果了解了Selector本身的用途，那么对这个新的概念就不难理解了。<br><br>Smalltalk这样比较纯粹的对象语言看重程序应用的灵活性。在基本C/C++的框架内，使得代码在编译前都必须明确所有方法调用和函数调用的类型。一旦编译完成，在代码运行时，想要改变函数调用的类型或方法调用的形式是不可能的。而在Smalltalk的理想世界中，一个纯粹是由对象组成的世界，一切在运行时应该都是可以根据环境的变化而改变的，包括对对象方法的调用的形式和类型。然而灵活的代价是牺牲效率，在计算机处理能力底下的时期，C/C++的效率统治了一切。不过当计算机处理能力获得的成本越来越低时，人们对灵活性的要求也就日益突出了。<br><br>Selector就是为了灵活性而存在的语法特性之一。它的目的概括说起来有两个：第一，可以在运行时，动态地改变被调用的对象（类），第二，可以在运行时，动态地改变调用的方法。<br><br>以上这段话其实是不准确的。因为对象方法调用是C++中的概念，Objective C中的没有调用的概念，而是对象之间&#8220;消息&#8221;的传递（messaging）。<br><br>要适应Objective C的开发，对C++ 程序员来说需要一个思路转换的过程。Java开发人员可能感觉会稍好点，不过对于动态类型部分也需要继续学习。不过Objective C 还有一个好处是，它的编译器最终还是兼容C++语法的，如果你实在适应不了，那么你也可以尝试在Objective C代码里混入C++的代码。不过这样的代码维护起来可就没那么简单了。<br><br><br><img src ="http://www.cnitblog.com/rolandash/aggbug/64765.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/rolandash/" target="_blank">陆宁</a> 2010-03-21 18:07 <a href="http://www.cnitblog.com/rolandash/archive/2010/03/21/64765.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>