[翻译]*iPhone OS for Cocoa Developers

经和洽
2023-12-01

[翻译]*iPhone OS for Cocoa Developers


(给Cocoa开发人员的iPhone OS信息)

    If you are an existing Cocoa developer, many of the frameworksavailablein iPhone OS should seem familiar to you. The basictechnology stack iniPhone OS is identical in many respects to the onefound in Mac OS X.Despite the similarities, however, the frameworks iniPhone OS are notexactly the same as their Mac OS X counterparts. Thisarticle describesthe key differences you may encounter as you pursuedevelopment of youriPhone application and how you can adapt your codeto handle thosedifferences.

( 如果你是一名Cocoa的开发人员,那么iPhone OS系统中有许多框架你应该很熟悉。iPhone有许多基础架构你都可以在Mac OSX中找到。无论有多么的相似,iPhone OS并不完全和Mac OSX一模一样。这篇文章列出了一些关键的不同,当你在开发你的iPhone应用程序的时候你就能改变你的代码以适应这个新的开发平台。)

Changes to Foundation Framework

(Foundation 框架的改变)

    The Foundation frameworkcontains most of the classes experienced Cocoadevelopers would expect,including value objects, strings, collections,thread management, andmany others. However, a handful of classes arenot included in theversion of the Foundation framework that ships withiPhone OS.



(   Foundation框架包含了许多Cocoa 程序员熟悉的值对象,字符串,集合,线程管理,还有其他的一些东西。事实上,只有少量的一些Foundation框架的类没有被包含在iPhone OS中。)


    Table 1lists some of the major areasof functionality that are not included inthe version of Foundationframework found in iPhone OS. The table alsolists the reasons why therelated classes are not available andalternative technologies for youto use instead. For a list of thespecific classes that are availablein Mac OS X but not in iPhone OS,see the class hierarchy diagramlocated in "The Foundation Framework" in Foundation Framework Reference.


(表 1 列出了iPoneOS平台下的Foundation框架不包括的函数。这个表同时也列出了为什么没有包括的原因和你可以选择替换的技术。表中的函数都是适用于MacOS平台的但是不适用于iPhone OS,你可以在"Foundation框架参考"中的“Foundation框架”中查看到他们的类层次。)


Table 1  Differences in Foundation technologies


(表 1 Foundation框架中的不同点)


Technology
技术

Notes
内容

                    Metadata and predicate management
Spotlight metadata and search predicates are not supported in iPhone OS because Spotlight itself is not supported.
                    

元数据和短语管理
  元数据和短语搜索并不能在iPhone上运行,因为系统不支持怎么做。
  

Distributed objects and port name server management
The Distributed Objects technology is not available, but you can still use the NSPortfamilyof classes to interact with ports and sockets. You can also usethe CoreFoundation and CFNetwork frameworks to handle your networkingneeds.
                    

分布式对象和端口命名服务管理
分布式对象技术不支持,但是你任然可以使用NSPort类来管理端口和sockets。你也可以使用Core Foundation和CFNetwork框架来操作你的网络需求。


Bonjour management
The NSNetService and NSNetServiceBrowser classes are not available, but their Core Foundation equivalents are. The CFNetServices opaque type lets you perform Bonjour networking and is part of the CFNetwork framework.
                    

问候管理
NSNetServic和NSNetServiceBrowse类都不可用,但是他们Core Foundation保留了。CFNetServices类让你可以执行问消息,她是CFNetwork的一部分。   



Cocoa bindings
Cocoabindingsare not supported in iPhone OS. Instead, iPhone OS uses aslightlymodified version of the target-action model that addsflexibility in howyou handle actions in your code. For moreinformation about thetarget-action model in iPhone OS, see UIControl Class Reference.
                    Cocoa绑定


iPhone OS不支持Cocoa绑定。取而代之的是,iPhone操作系统使用经过轻微修改过的基于目标行为的模型,他可以让你弹性的在你的代码中控制命令。想要了解更多iPhone OS中的目标命令模型,请参考UIControl类参考。


Objective-C garbage collection
Garbagecollectionis not supported in iPhone OS. Instead, you must use thememory-managedmodel, whereby you retain objects to claim ownership andrelease objectswhen you no longer need them.
                    

Objective-C的垃圾回收
iPhone操作系统不支持垃圾回收。取而代之的是你必须使用内存管理模型,当你你要的时候保持对象,不需要的时候释放掉他们。


AppleScript support
AppleScript is not supported in iPhone OS.
                    
AppleScrit支持
iPhone操作系统不支持AppleScript。

Undo management
The NSUndoManager class is not available, and there is no automatic support for undoing operations in iPhone OS.
                    

撤销管理
NSUndoManage类不可用,在iPhone OS中不支持自动撤销的方法。

XML Parsing
The NSXMLParser class is available in iPhone OS. You can use it to parse XML and extract information from an existing source of XML. However, NSXMLDocument and its associated classes (used to create, modify, and repeatedly query tree-based XML documents) are not available.


XML解析
iPhone操作系统不支持NSXMLParse类。事实上NSXMLDocumen也不支持(用来创建,修改和基于XML的文挡)  





  For complete class and method information for the Foundation framework in iPhone OS, see Foundation Framework Reference.



(查看iPhone OS中的所有的类和方法,请查看Foundation 架构参考。)


UIKit Versus AppKit

(UIKit和AppKit的对比)

   Experienced Cocoa developers will noticesimilarities between the AppKitframework in Mac OS X and the UIKitframework in iPhone OS. The UIKitframework was written with theconventions and features of the AppKitframework in mind; however,UIKit was designed and built for a verydifferent platform with verydifferent needs. Changing the names ofsymbols in a Cocoa applicationto match similar symbol names in UIKitwould not yield an applicationcapable of running in iPhone OS.Structural and behavioral differencesbetween the two frameworks requireyou to rework (or even rewrite) anyAppKit code you might want to moveto iPhone OS.


( 一个有经验的Cocoa开发人员一定会注意到Mac OS的AppKit和iPhoneOS的UIKit之间的区别。在大体上UIKit框架参考了AppKit框架来设计和构想的。事实上,UIKit是为了满足一个很特别的平台的特许需求而生的。如果只是改变Cocoa应用程序中的符号的名称来适应UIKit的话那这个程序还是不能在iPhone上运行。结构和行为上的不同使你不得不重写你的给予AppKit的代码。)


  Still, if you compare the two frameworks side-by-side, you would see the differences listed in Table 2.



(如果你认真的比较这两个框架的不同点,你将会看到他们的区别,列在图表2中。)


Table 2  Differences in application technologies


(表 2 应用程序中的不同)


Difference
不同

Discussion
讨论

                    The use of accessor methods versus properties
Oneofthe biggest differences is the extensive use of propertiesthroughoutthe UIKit class declarations. Properties were introduced toMac OS X inversion 10.5 and thus came along after the creation of manyclasses inthe AppKit framework. Rather than simply mimic the samegetter andsetter methods in AppKit, UIKit employs properties as a wayto simplifythe class interfaces. For information about properties, seeProperties in The Objective-C 2.0 Programming Language.



                    存储器方法对比属性
一个最大的不同是贯穿在UIKit类中的属性申明。属性是Mac OS X10.5的AppKit框架中引入的。不像AppKit中使用getter和setter那样,UIKit使用属性这个简单的方法来作为类接口。想要了解更多有关“属性”的信息,可以看“Objective-C 2.0开发语言”。


View classes
AniPhoneapplication has a more focused set of custom views andcontrolsavailable for you to use. Many of the views and controls foundinAppKit would simply not work well on iPhone OS-baseddevices.Organizational controls such as boxes, browsers, tab views, andsplitviews are either not needed or have more appropriate alternatives.Forexample, instead of providing an NSBrowser class,iPhoneuses an entirely different paradigm (navigation controllers) tomanagethe display of hierarchical information. For a description of theviewsand controls available in iPhone OS along with information on howtouse them, see iPhone Human Interface Guidelines.


                    视图类
一个iPhone的应用程序有的时候更需要自定义视图和控制。许多在AppKit下工作的视图和控制不能很好的在iPhone操作系统下工作。组织控件比如盒子,浏览器,标签栏视图,和分割视图他们在iPhone中不需要或者只保留了1,2个。举个例子,NSBrowse的代替类,iPhone使用完全不同的控件(导航控制器)去管理和显示分层的信息。有关iPhone中可用的视图和控制器请参考iPhone人机界面指南



Event handling
Theevent-handlingmodel in iPhone OS is significantly different than theone found in MacOS X. Instead of mouse and keyboard events, the iPhoneOS delivers oneor more touch events through a new set of handlermethods. The way youinterpret and track these events is also differentand is described morefully in "Event Handling" in iPhone OS Programming Guide.


                    事件控制
和Mac OS X相比iPhone OS的事件控制完全不一样。取代了鼠标和键盘的事件,iPhone使用的是一个或多个触摸事件控制方法。想要更好的了解如何跟踪这些事件请参考iPone开发指南中的事件控制。


Target-action model
Thetarget-actionmodel in iPhone OS supports three variants for actionmethod definitions(as opposed to one in AppKit), and each method canbe associated with adifferent type of action related to the control.In addition, controlscan have more than one target assigned to thesame action, resulting inthe delivery of multiple messages with eachaction. For more informationabout the target-action model in iPhoneOS, see UIControl Class Reference.



                    目标指令模型
在 iPhoneOS中的命令对象模型,支持命令方法定义三个参数(与他形成对比的是AppKit只能有一个),每一个方法可以you不同的命令去相关和控制。另外控制器可以分配一个多个对象给相同的命令,可以为每一个命令显示多消息的返回。想要了解更多关于iPhone命令对象的模型,请参考 UIControl类参考


Drawing and printing support
Thedrawingcapabilities of UIKit are scaled to support the rendering needsof theUIKit classes. This support includes image loading and display,stringdisplay, color management, font management, and a handful offunctionsfor rendering rectangles and getting the graphics context.UIKit doesnot include a general purpose set of drawing classes becauseseveralother alternatives (namely Quartz and OpenGL ES) are alreadypresent iniPhone OS. Printing is not supported because there is nodirect supportfor connecting printers or other print-related hardwareto an iPhoneOS-based device. Automatic color matching is also notprovided. Forinformation about drawing in iPhone OS, see ?Coordinate Systems? later in this article and "Graphics and Drawing" in iPhone OS Programming Guide.
                    

绘图和打印支持
UIKit 中的绘图功能很好的支持了UIKit类中的要求。这些支持包含图形加载和显示,字符串显示,颜色管理,字体管理,和一些函数用来绘制矩形和他里面的内容。 UIKit不包括通常的一些绘图函数,因为在iPhone中已经包括了2个绘图框架(Quartz和OpenGLES)。在iPhone操作系统平台上打印不被支持因为他没有直接的支持链接到打印机或者和打印相关的设备上。自动颜色匹配也没有支持。想要了解更多有关iPhone的绘图可以看本文后面的坐标系统和在iPhone开发指南中的图形和绘画。


Text support
Thetextsupport in iPhone OS is geared towards composing email and notes.TheUIKit classes let applications display and edit simple stringsandsomewhat more complex HTML content. The more advanced text layoutandglyph generation features that you would find in an advancedwordprocessor are not included in iPhone OS because they are lessrelevantfor the mobile environment.
                    

文本支持
在iPhone中email和记事本需要文本的支持。UIKit类让应用程序显示编辑简单的字符串和一些复杂的HTML内容。一些高级的文本输出的方法或者类似文本编辑器一样的功能不会包括在iphone中因为他们和移动平台关系不大。


Document support
IniPhoneOS, applications typically have only one window and do not useseparatedocument objects or document windows. Therefore, any filesopened by theapplication are managed by the application directly andused to updatethe content of its window.
                    

文档支持
在iPhone中,应用程序只有一个窗口并且不使用分离的文档对象或者文档窗口。因此任何文档的打开都是由应用程序直接打开显示在窗口上的


Controls and cells
Controlsin UIKit do not use cells. Cells are used in Mac OS X as a lightweightalternative to views. Because views in UIKit are themselves verylightweight objects, cells are not needed. Despite the namingconventions, the cells designed for use with the UITableView class are actually based on the UIView class.
                    
控制和单元
在UIKit中的控制器并没有使用单元。单元只是Mac OS X中的一个轻量的框架。因为UIKit本身就是一个轻量的框架了,所以不需要单元了。忽略命名规则,单元中的UITableView类也是基于UIView类的。


Table views
The UITableView class in iPhone OS can be thought of as a cross between the NSTableView and NSOutlineViewclassesin the AppKit framework. It uses features from both of those AppKitclasses to create a more appropriate tool for displaying data on asmaller screen. The UITableView class displays a singlecolumn at a time and allows you to group related rows together intosections. It also is a means for displaying and editing hierarchicallists of information. For more information about the UITableView class, see UITableView Class Reference. 


表格视图
在AppKit框架中的UITableVie类可以看成是贯通NSTableVie和NSOutlineViewclasses类的桥梁。她使用了AppKit中的一些特性创建了一些合适的方法来在小的视图中显示数据。UITableVie类显示了一个带有滚动条的分组显示数据的区域。这意味着她是用来处理分层型的数据列表的。先要了解更多UITableVie类的信息,参考UITableVie类参考。    




                    Menus
Menusare another user interface paradigm that is not supported in iPhoneOS.Nearly all applications written for iPhone OS have a much smallercommand set than a comparable Mac OS X application, and so menus aregenerally unnecessary. For those few commands that are needed, atoolbar or set of buttons is usually more appropriate. For data-basedmenus, a picker or navigation controller interface is often moreappropriate.


菜单
在iPhone OS中是不支持菜单的。因为iPhone的应用程序通常比Mac OS小的多,所以菜单并不太重要。对着这样的小程序来说,一个工具栏或者一个导航界面就足够了。对于给予数据的菜单,一个提示框或导航控制器通常来够用了。


Core Animation layers
IniPhone OS, every drawing surface is backed by a Core Animation layerandimplicit animation support is provided for many view-relatedproperties.Because of the built-in animation support, you usually donot need touse Core Animation layers explicitly in your code. Mostanimations canbe performed simply by changing the desired property ofthe affectedview. The only time you might need to use layers directlyis when youneed precise control over the layer tree or when you needfeatures notexposed at the view level. For information about how CoreAnimationlayers are integrated into the drawing model of iPhone OS,see iPhone Application Programming Guide. 


核心动画层
在 iPhone中,每一个绘图面都是基于核心动画层的并且其中的动画支持许多基于视图的属性。因为基于内部的动画至此后,你通常不需要去直接使用核心动画层,大多数动画你可以通过改变视图中的一些你想要的属性进行。只有你真正需要控制一些更深层次的细节而视图层没有提供这些特性的时候你需要使用动画层。更多有关核心动画层的内容你可以参考iphone OS中的绘图模块,见iPhone程序开发指南


Changes to Other Frameworks

(来自其他框架的改变)

Table 3-3 lists the key differences in other frameworks found in iPhone OS.

(表格3列出了iPhone操作系统中和其他框架中的一些关键的不同点)

AddressBook.framework
Thisframework contains the interfaces for accessing user contacts. IniPhoneOS, the interfaces of this framework are written in C insteadofObjective-C. For more information, see Address Book Framework Reference.

通信录框架
这个框架是用来访问用户的一些信息的,在iPhone操作系统中,这个框架的接口是基于C的而不是基于Objective-C的,更多有关的信息,请看通信录架构参考。

AudioToolbox.framework
AudioUnit.framework
CoreAudio.framework
TheiPhone OS versions of these frameworks provide support primarilyforrecording, playing, and mixing of single and multichannel audiocontent.More advanced audio processing features and custom audio unitplug-insare not supported. One addition for iPhone OS, however, is theabilityto trigger the vibrate option for iPhone devices. Forinformation on howto use the audio support, see Audio and Video TechnologiesiPhone Application Programming Guide in



音频工具框架
音频单元框架
核心音频框架
在 iPhoneOS版本中的这些框架是用来为录音,播放,混音做支持的。更多一些高级的音频的应用和自定义音频插件不被支持。在iPhone中还有一个特别的应用,为震动设备提供支持。需要了解更多信息,有关如果使用音频,你可以参考"应用程序开发指南"中的"iPhone中的音频和视频技术"。


CFNetwork.framework
Thisframework contains the Core Foundation Network interfaces. IniPhone OS,the CFNetwork framework is a top-level framework and not asubframework.Most of the actual interfaces remain unchanged, however.For moreinformation, see CFNetwork Framework Reference.



CFNetwork框架
这个框架包含了 Core Foundation Network接口。在iPhone中,CFNetwork框架是一个顶层框架,没有子结构。大多数的接口被毫无更改的保留了。需要更多信息,请参考CFNetwork框架参考。


CoreGraphics.framework
Thisframework contains the Quartz interfaces. In iPhone OS, theCoreGraphics framework is a top-level framework and not a subframework.Youcan use Quartz to create paths, gradients, shadings, patterns,colors,images, and bitmaps in exactly the same way you do in Mac OS X.Thereare a few Quartz features that are not present in iPhone OS,however,including PostScript support, image sources and destinations,QuartzDisplay Services support, and Quartz Event Services support. Formoreinformation, see Core Graphics Framework Reference.


CoreGraphics框架
这个框架包含了Quartz接口。在iPhone操作系统中,核心图形框架是顶层框架没有子结构。你可以使用和 MacOS中一样的Quartz去创建线性,倾斜,渐变,阴影,纯色,图片或者位图等。在iPhone操作系统中这里有一些Quartz的特性没有被支持,事实上,包含PostScript,源图片和指定,Quartz显示服务支持,和Quartz事件服务支持。需要了解更多信息,可以查看“核心图片框架参考”。




OpenGLES.framework
Theversion of OpenGL that comes with iPhone OS is OpenGL ES version1.1,which is a version of OpenGL designed specifically for embeddedsystems.If you are an existing OpenGL developer, the OpenGL ESinterface shouldbe familiar to you. However, the OpenGL ES interfacestill differs inseveral significant ways. First, it is a much morecompact interface,supporting only those features that can be performedefficiently usingthe available graphics hardware. Second, many of theextensions youmight normally use in desktop OpenGL might not beavailable to you inOpenGL ES. Despite these differences, you shouldstill be able toperform most of the same operations you would normallyon the desktop.If you are migrating existing OpenGL code, however, youmay have torewrite some parts of your code to use different renderingtechniques iniPhone OS. For information about the OpenGL ES support iniPhone OS, seeiPhone Application Programming Guide.



OpenGLES框架
在 iPhone中的OpenGL版本是OpenGL ES 1.1他是专门为嵌入式系统而制作的。如果你是一个OpenGL的开发人员,那么OpenGLES对你来说会很熟悉。事实上,OpenGLES的接口仍然有一些自己的定义。首先,这是一个很精简的接口用来支持那些有效的使用硬件显示图形的方法。第二许多桌面上的OpenGL的一些拓展方法也许你不能在 OpenGLES中使用。虽然有这些不同,但是大多数的操作和你在桌面版本的操作是一样的。如果你想把你的OpenGL的代码迁移到iPhone中你需要对其中的一些部分进行修改。了解更多有关OpenGL ES的信息,你可以参考iPhone 应用程序开发指南。



QuartzCore.framework
Thisframework contains the Core Animation interfaces. Most of theCoreAnimation interfaces are the same for both iPhone OS and Mac OSX.However, in iPhone OS, the classes for managing layout constraintsandsupport for using Core Image filters are not available. Inaddition,the interfaces for Core Image and Core Video (which are alsopart ofthe Mac OS X version of the framework) are not available. Formoreinformation, see Quartz Core Framework Reference.


QuartzCore框架
这个框架包含了一些核心动画的接口。iPhone上的大多数核心动画的接口和Mac OSX很相近。事实上,在iPhone中,管理内容输出支持使用核心图片滤镜的类没有被支持。另外,核心图片和核心视频接口(他们是MacOS中的以部分)没有被支持。需要了解更多的信息请参考"Quartz 核心框架参考"。



Security.framework
Thisframework contains the security interfaces. In iPhone OS, thisframeworkfocuses on securing your application data by providingsupport forencryption and decryption, pseudo-random number generation,and theKeychain. The framework does not contain authentication orauthorizationinterfaces and has no support for displaying the contentsofcertificates. In addition, the Keychain interfaces are asimplifiedversion of the ones used in Mac OS X. For information aboutthesecurity support, see iPhone Application Programming Guide.



安全框架
这个框架包含了一些安全的接口。在iPhone OS中,这个框架关心你应用程序中的数据被破解和反破解,产生仿冒的随机码,和Keychain。这个框架不包含授权和认证的接口不支持显示证书的内容。另外Keychain的接口只是在Mac OS X中使用。更多有关安全的信息请看iPhone应用程序开发指南。



SystemConfiguration.framework
Thisframework contains networking-related interfaces. In iPhone OS,thisframework contains only the reachability interfaces. You usetheseinterfaces to determine how a device is connected to the network,suchas whether it’s connected using EDGE, GPRS, or Wi-Fi.


SystemConfiguration框架
这个框架包含了和网络有关系的接口。在iPhone OS中这个框架包含了只有它可用的接口。你可以使用这些接口来决定设备是如何链接到网络的,比如它是使用EDGE,GPRS还是Wi-Fi。

 类似资料: