天天看點

[翻譯]*iPhone OS for Cocoa Developers[翻譯]*iPhone OS for Cocoa Developers

[翻譯]*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。

繼續閱讀