August 2008 Archives

Cocoa GUI 圖形用戶界面

| No Comments | No TrackBacks
Cocoa GUI基於以下四個概念:
  • 窗口(Windows)
  • Nib文件
  • 插座變量(Outlets)
  • 動作(Actions)
下面簡要介紹下後三種:
Nib文件
nib文件是對象實例的存檔, 它由Interface Builder生成. 和其他界面生成系同的是, nib文件不是生成的一段代碼. 它是一組真實的對象, 經過特殊編碼保存在磁盤中. nib文件中的對象由
Interface Builder中的圖形工具創建和操作.

nib文件通常將一組相關的界面對象及其資源一起打包, 也伴隨著對象之間如何關聯, 對象與您應用程序的其他對象如何關聯的信息. nib文件以特殊的存檔方式, 或者叫freeze-drying(速凍干燥)方式來描述它保存的所有對象, 以便應用程序在運行時能再生成並使用他們.

每個圖形界面的應用程序至少有一個nib文件, 它在應用程序啟動時被自動加載. 主nib文件通常包含了應用程序菜單, 而輔助的nib文件包含應用程序窗口及其關聯的界面對象. For example: Photoshop可能有一些輔助nib文件, 用來描述各種調板和控件以便您處理圖像.

插座變量 Outlets
插座變量是類的頭文件中以IBOutlet關鍵字標記的特殊實例變量, 它包含了對另一個對象的引用. 對象經由插座變量向應用程序的其它對象發送消息來與之通信.

插座變量能引用程序中的任何對象: 界面對象, 自定義類的實例, 甚至是應用程序對象自己. 插座實例變量於眾不同的是, Interface Builder只能識別IBOutlet關鍵字, 使您能操作插座變量定義的連接. 一旦定義了連接, 對象就在程序運行時就被聯系起來. 使用Interface Builder定制對象之間的連接把您從手工編寫初始化代碼中解脫出來. 除了插座變量之外, 還有許多方法能在應用程序中引用對象, 但插座變量與Interface Builder極大的便利了引用的初始化工作.

動作 Actions
動作是類定義中以IBAction關鍵字標記的特殊方法, 它由界面對象觸發.跟插座變量類似, Interface Builder也能識別頭文件中的動作聲明. 類似地,
Interface Builder允許您將用戶界面產生的一個動作(比如一個按鈕)與對象的方法相連接

話外:
用MVC模式設計應用程序
Cocoa應用程序中利用了一個經久不衰的面向對象范例 -----
模型 -- 視圖 -- 控制器 (Model - View - Controller, MVC)模式.
模型
持有數據並定義數據的邏輯操作
視圖
為用戶可視化的呈現對象, 如窗口和按鈕
控制器
在模式和視圖之間起到中間人角色的對象
MVC范例適用於很多應用程序, 因為控制器在中間的協調角色使模型對象無需知道界面的狀態和事件. 視圖對象同樣也不必知道模型對象的編程接口. 這樣將問題分割開來, 有助於在應用程序中封裝各種對象. 這也有助於代碼復用, 因為模型可用在其它地方, 甚至是另一平台.
 

內存管理在程序設計中是一個重要話題. 初學者遇到的多數問題都是由糟糕的內存管理導致的. 當一個對象在不同的應用程序中創建並傳遞給不通的"消費者"對象時, 該由哪個"消費者"來負責它的善後處理, 何時進行? 當一個對象不再使用卻沒被回收時, 就會造成內存洩漏. 當對象回收的太早, 別的對象若仍然假設它還存在時就會出現問題, 應用程序也可能崩潰.

Foundation框架定義了一套機制和策略, 以保證對象只在不需要的時候才被回收. 策略很簡單: 您有責任處理自己所擁有對象的善後工作. 您擁有由您創建的對象, 無論是通過內存分配還是拷貝得來的; 您還擁有(或共同擁有)您所保持(retain)的對象. 這個策略反過來說就是: 決不要釋放不歸您所有或保持的對象. 這樣做將過早地釋放內存, 導致很難追蹤得到的漏洞, 即便是那些很容易修補的漏洞

對象的初始化和回收
對象通常用alloc方法創建, 用init方法(或init方法變種)初始化. 當調用任何數組的init方法時, 該方法就會初始化數組的實例變量為默認值, 並完成一些其他的初始化工作. For example:
NSArray  *array = [[NSArray alloc]  init];
當用完創建的對象時, 您給對象發一條release(釋放)消息. 如果沒有其它對象使用或關注這個對象, 它就會被回收並移除內存.
回收對象調用dealloc方法, 讓該對象有機會釋放它所創建的對象, 解放被它分配的內存等.

引用計數 Reference Count
為了讓多個對象都可以注冊表示關注某個對象, 並在該對象不再被任何對象關注的時候從內存清除, Cocoa中的每個對象都有與之關聯的引用計數(Reference Count). 當您分配或復制對象時, 引用計數自動設為1. 這表示對象在一個地方使用. 當您這個對象傳遞給其它對象, 卻還想確保它能被自己使用時, 可以使用retain方法來將引用計數加1.
learnobjectivec-referencecounting.png(以上圖片來自http://cocoadevcentral.com/)

自動釋放池 Autorelease Pools
根據對象善後處理的上述策略, 如果對象的擁有者必須在它的程序范圍內釋放對象, 那麼怎麼將對象傳遞給其他對象? 或者說, 您怎麼能釋放一個將要返回給方法調用者的對象? 因為一旦從方法返回, 就再沒辦法釋放對象了.
答案是NSObject類內置的autorelease方法, 它與NSAutoreleasePool類共同配合. autorelease方法用NSAutoreleasePool來標記其接收者要稍後釋放. 這使對象的生命范圍超出了其擁有者對象的范圍, 以便其它對象使用. 這種機制解釋了您能看到很多實例中包含這樣的代碼:
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
// ... code ...
[pool drain];

每個應用程序都至少有一個(用於應用程序中每個控件線程的)自動釋放池(autoreleasepool), 也可以有多個. 通過發送autorelease消息可將對象放入池中. 在應用程序的事件循環中, 當代碼執行完畢並將控制權交還給應用程序對象時, 應用程序對象會發送一個release消息給自動釋放池, 而自動釋放池再給它包含的每個對象發release消息. 任何引用計數為0的對象就會自動的自我回收.
當對象只在創建它的方法范圍內使用時, 可以發送release消息立刻回收它. 否則就發送autorelease消息給所有創建了又移交走的對象, 以便選擇是否保持它.
除非您出於某種原因先保持了由其他對象傳來的對象, 否則不要釋放它. 這樣做會導致對象的引用計數過早地達到0, 後果可想而知: 內存洩漏!
您可以假設接收的對象在接收的方法以及處理它的事件循環(event loop)中都保持有效. 如果希望它留作實例變量, 就應該給它發retain消息, 然後在使用完自動釋放它.

在訪問方法中保持對象
內存管理中需要了解的一個重要地方在您類似的訪問方法中.乍一看似乎很明顯您需要釋放舊的對象引用而保持新的. 然而, 由於代碼很可能以參數形式多次調用同一個對象的訪問方法設置屬性, 所以對象引用的釋放和保持順序就變得非常重要.
一條規則是: 您當在釋放舊對象前保持新對象. 這確保了每件事如預期所料, 哪怕新舊對象相同. 如果您顛倒步驟, 如果新舊對象相同, 則有可能對象在保持前就從內存中被永久的移除了.
下面代碼體現了先保持, 再釋放的原則:
- (void) setProperty: (id)newProperty {
[newProperty retain];
[property release];
property = newProperty;
}
還有其它的方法也能保證訪問方法設置屬性時的關聯性, 他們中的多數在特定環境下是有效和適當的. 無論如何, 上述方法是我們能給出保證永遠有效的最簡單常用的模式

經驗之談
Cocoa中要記住的幾件內存管理相關的重要事情歸納為下面幾條:
  1. 通過分配或復制創建的對象保持計數為1
  2. 假設任何別的方法獲取的對象保持計數為1. 而且在自動釋放池中. 要想在當前執行范圍外使用該對象, 就必須保持它
  3. 向集合添加對象時它就被保持, 從集合移走對象時就被釋放. 釋放集合對象(如NSArray)會釋放該集合當中所有的對象
  4. 確保有多少個alloc, copy, mutableCopy或retain消息就有多少release或autorelease消息發送給該對象. 換句話說, 確保您代碼的平衡
  5. 在訪問方法設置屬性時先保持, 再釋放
  6. 在程序中用@"..."結構創建的NSString對象是有效常量. 向它們發送retain或者release消息沒有用
  7. 使用便利構造方法創建的對象(如NSString的stringWithFormat)可以被認為會自動釋放
  8. 在使用你自己的參數實例時, 需要實現-dealloc方法來釋放
未盡事宜, 有待補充...

gdb調試器命令及秘籍

| No Comments | No TrackBacks
調試器能做很多事情, 這裡有一些常用的調試器命令:

call [exp]
調用給定的對象功能, 如:
(gdb) call (void) [array removeObject: @"just a test"]

print [exp]
輸出給定表達式的原始值, 如:
(gdb) print (int) [artist length]

print-object [exp]
輸出表達式返回的對象的值, 該命令可以用po簡化,如
(gdb) print-object [artist description]
         等價於:
(gdb) po artist

set [variable] = [exp]
將表達式的值賦給變量, 如:
(gdb) set artist = @"new artist"

whatis [variable]
輸出變量的類型, 如:
(gdb) whatis artist

help
輸出調試器的命令列表, 演示:
(gdb) help
List of classes of commands:

aliases -- Aliases of other commands
breakpoints -- Making program stop at certain points
data -- Examining data
files -- Specifying and examining files
internals -- Maintenance commands
obscure -- Obscure features
running -- Running the program
stack -- Examining the stack
status -- Status inquiries
support -- Support facilities
tracepoints -- Tracing of program execution without stopping the program
user-defined -- User-defined commands

Type "help" followed by a class name for a list of commands in that class.
Type "help" followed by command name for full documentation.
Command name abbreviations are allowed if unambiguous.
其他工具
以下是除過Xcode和Interface Builder之外的, 具有GUI的開發工具, 除非特別說明, 它們均安裝在/Developer/Application/Utilities文件夾內.

Instruments

自Xcode3.0開始提供的非常獨特的調試工具. 它的界面有點像蘋果的音樂制作軟件GarageBand一樣的風格和時間線.Instruments讓您的性能調試工作從未變得如此直觀.

Dashcode
用來制作任何屬於您自己的Dashboard widget, 簡單而且有用. 您可以只用幾分鍾就做出widget並使用它, 甚至都不懂如何寫代碼.

FileMerge
可視化的比較兩個文件或目錄的內容. 您可以用FileMerge來判定同一源碼文件的不同版本或不同工程目錄之間的區別, 也用它來合並修改.

IconCompose
從源素材開始創建Mac OS X 圖標

IORegistryExplose
分層次顯示系統I/O注冊列表

MallocDebug
用於測量應用程序的動態內存使用情況, 找出內存洩露, 分析應用程序分配的內存, 測量自給定時間起分配的內存, 該工具在Performance Tools文件夾下

PackageManager
創建Mac OS X安裝包

Pixie
放大光標下的屏幕區域, 可以讓您精確的看到組成任何屏幕對象的像素. 放大倍率可在正常顯示的1~12倍之間調整. 該工具在Graphics Tools文件夾下

Property List Editor
打開, 顯示, 修改屬性列表(.plist)文件的內容

Quartz Debug
顯示系統管理的所有窗口的列表. 這個工具允許您打開Quartz調試模式, 在該模式下, 窗口服務器在更新屏幕區域時會在其上閃爍黃色. 該工具在Performance Tools文件夾下

Thread Viewer
允許您瀏覽應用程序高級別的線程行為. 該工具在Performance Tools文件夾下

命令行工具
還有一些命令行工具作為工具包的一部分被安裝, 它們負責編譯, 調試, 分析性能等工作. 其中許多工具是標准Unix應用程序的一部分. 可在/usr/bin文件夾下找到一下工具:

cc, gcc
GNU C編譯器(gcc), 用於編譯C, Objective-C, C++和Objective-C++的源代碼文件

gdb
一個源代碼級的C語言符號調試器, 已被擴展支持Objective-C, C++和Objective-C++

as
匯編; 將匯編代碼翻譯為目標代碼

defaults
讀寫, 搜索, 刪除用戶默認設置. 默認系統記錄了應用程序不運行時仍需保留的用戶偏好設置

nibtool
讀取Interface Builder的nib文件的內容. nibtool輸入類, 對象層次, 對象, 連接和可被本地化的字符串

libtool
由指定的對象二進制文件創建靜態或動態庫

otool
顯示對象文件或庫的指定內容

nm
顯示指定對象文件的全部或部分符號表

xcodebuild
通過命令行構建Xcode工程

strip
用於移除或修改附在匯編和連接生成結果上的符號表

cvs
CVS允許多人團隊在一個公用代碼的基礎上協同工作

sample
搜集進程的運行行為並生成報告顯示應用程序運行過程中執行了什麼函數

leaks
檢查進程中由malloc分配卻未被應用程序引用的緩沖區

Cocoa 二三事

| No Comments | No TrackBacks
Cocoa定義
Cocoa是一個先進的面向對象框架,主要用於構建運行在蘋果Mac OS X上的應用程序. 它把共享對象庫, 運行環境系統及開發環境完整地整合在了一起. Cocoa提供的基礎體系滿足大部分圖形界面應用程序的典型需要, 並將應用程序於操作系統內部的工作相互隔離.
可以把Cocoa理解為一個對象層, 它充當程序於操作系統之間的媒介於協調人的角色. 這些對象覆蓋了從基本類型的簡單封裝, 如字符串和數組, 到復雜的功能, 如分布式計算和高級影像處理. 它們被設計於一個復雜而精巧的體系之上, 以簡化編程工作, 輕松創建圖形界面的應用程序.
基於Cocoa的應用程序並不僅限於使用Cocoa框架中的特性. 它們也能使用Mac OS X中其它框架的全部功能, 例如Quartz, QuickTime, OpenGL, ColorSync等等. 由於Mac OS X是建立在一個給予BSD的堅固系統Darwin之上, Cocoa應用程序可以使用Unix系統的所有核心功能, 並按程序需要使用底層的文件系統, 網絡服務和設備.

Cocoa 歷史
Cocoa其實已存在很長時間, 幾乎於Macintosh一樣久遠. 它很大程度上基於OpenStep, 於1987年與雅典的NeXT cube電腦一起以NeXTSTEP的名字公布於世. 當時的NeXTSTEP的目標正如只有Steve Jobs才敢宣稱的"創造下一個瘋狂而偉大的事務". 它的發展經歷很多版本, 被眾多公司采納作為開發和部署環境, 並被廣泛報道, 十分火熱. 它基於領先當時世界上任何產品多年的設計, 成為一種強悍的技術延續至今.
NeXTSTEP建立由加州大學伯克利分校(UC Berkeley)開發的BSD Unix和卡內基梅隴大學(Carnegie-Mellon University)開發的Mach微內核基礎之上. 它利用了Apple公司開發的Display PostScript技術(允許使用PostScript頁面描述語言相同的代碼)來實現在屏幕上顯示文檔和輸出打印文檔. NeXTSTEP包含一組被成為框架(Framework)的庫, 還有一些工具, 使開發人員能夠利用Objective-C語言構建應用程序.
1993年,
NeXT公司退出硬件領域而專注於軟件業務. NeXTSTEP被移植到X86體系上並發布. 同時還移植到了SPARC, Alpha和PA-RISC等體系架構之上. 後來, 這些框架為了運行在如Windows和Solaris等其他操作系統上而進行了修改. 這些修改後的框架就是眾所周知的OpenStep.
到了1996年, 蘋果公司正在開發下一代操作系統, 代號Colpand, 用來接替非常成功的Mac OS 7, 但開發進展並不順利. 工程師們四處碰壁, 最終他們決定從外界尋找方案來搭建新操作系統的底層基礎. 盡管領先的競爭者是BeOS, 但出乎意料的是蘋果選擇了NeXT系統, 宣稱其在軟件開發和用與企業及互聯網市場的應用環境中有特殊的優勢. 作為合並的一部分, 蘋果著手開發Rhapsody(狂想曲), 它是
NeXTSTEP於經典Mac OS系統的融合. 經過五年多的發展, Rhapsody最終以Mac OS X 10.0發布. OpenStep隨著發展演變成了Cocoa.
Mac OS X保持了相當完整的Unix系統, Mac OS X的Unix一面只是對用戶隱藏起來, 除非用戶真想使用它. 然而它強大的能力卻能為程序員所用. 你不僅能利用它的能力, 實際上你還可以深入它的內部, 了解它是如何工作的. Mac OS X的底層代碼可在http://www.opensource.apple.com/darwinsource/找到

Cocoa框架
Cocoa由兩個面向對象的框架組成:Foundation(請勿與Core Foundation框架混淆)和Application Kit. 他們在系統中的位置如下:
                   Cocoa AppKit
                             |
               Cocoa Foundation
                             |
                Core Foundation
                             |
                        Kernel
Cocoa Foundation  框架中的類提供的對象和函數, 構成了Cocoa的基礎或者說是基石, 而這些函數和對象並不影響界面. 構建在Foundation框架上的AppKit框架, 提供了用戶在界面上可以看到的對象和行為, 如窗口和按鈕; 這些類同時也處理鼠標和鍵盤事件. 可以這樣認為它們的區別: Cocoa Foundation框架提供了應用程序表層之下的操作功能, 而AppKit框架的類提供了用戶可見的關於界面的功能.
網站:
蘋果開發人員聯盟(Apple Developer Connection)
蘋果定期的通過蘋果開發人員聯盟(ADC)網站來發布新文檔, 更新現有文檔. 與此同時, 成為ADC會員(online會員是免費的)讓您能訪問到最新的開發工具:

http://developer.apple.com.cn/

O'Reilly的Mac DevCenter
歸屬於O'Reilly & Associates, Inc., O'Reilly Network是Mac DevCenter的家.它是一個為Mac OS X開發人員匯集新聞, 常見問題, 原創文檔和其他技術信息的地方:

http://www.macdevcenter.com/

Cocoa Dev Central
這個網站頻繁地為Cocoa初學者更新小提示, 小技巧和開發指導. 它還有很多和其他Cocoa網站的鏈接:

http://www.cocoadevcentral.com/

CocoaDev Wiki
這個用戶可以自己參與編寫的網站供Mac OS X開發人員社區使用. 如果您從來沒用過Wiki, 這種風格的網站能讓任何瀏覽網站的人都能為之增添新信息

http://www.cocoadev.com/

MacTech雜志
MacTech網站也包含了很多可以下載的資源以及網頁版的MacTech在線雜志, 它每月都有來自雜志的專題提供在線的技術和資源. 這些資源包括網頁的鏈接, 共享軟件, 新聞組, 郵件列表, 和面向Mac程序員的頻道

http://www.mactech.com/

郵件列表
Apple的cocoa-dev郵件列表
由蘋果主持的專注在Cocoa開發問題的郵件列表.
http://lists.apple.com/mailman/listinfo/cocoa-dev

Apple的xcode-users郵件列表
由蘋果主持的關於Xcode問題的郵件列表.
http://lists.apple.com/mailman/listinfo/xcode-users

The OmniGroup的MacOSX-dev郵件列表
由一家黃金級Cocoa開發工作室建立的供開發人員互相幫助的郵件列表.
http://www.omnigroup.com/mailman/listinfo/macosx-dev

Cocoa詞匯表

| No Comments | No TrackBacks
A
abstract
抽象

accessor method
訪問方法

aggregation
聚合

alias
替身

API
應用程序編程接口

ADC
Apple Developer Connection
蘋果開發人員聯盟

Aqua
Aqua is the graphical user interface and primary visual theme of Apple Inc.'s Mac OS Xoperating system

Architecture
架構, 體系結構

archive
n. 存檔; v. 歸檔

array
(軟件的)數組; (硬件的)陣列

association
關聯

autorelease pool
自動釋放池

B
boot/bootable
引導/可引導的

Boot Manager
引導管理器

box
方框

breakpoint
斷點

browser
瀏覽器

buffer
緩沖, 緩沖區

build
v. 構建(工程), 聯編(代碼)

Build and Debug
構建並調試

Build and Go
構建並執行

bundle
文件包

bus master
總線主控程序

C
cache
快存, 緩存

call
調用 (函數, 方法, 接口)

callback
回調

Carbonized
Carbon化

category
分類

cell
控制單元

checkbox
選框, 復選框

click
點擊

clipboard
剪貼板

Cocoalized
Cocoa化

coding
編碼, 編寫代碼

cohesion
內聚

color space
色彩空間, 色域

color well
選色框

combo box
組合框

command gate
命令門

compile / compiler
編譯 / 編譯器

compiler directive
編譯指令

component
組件

composition
合成

concatenate
(字符串的)連接

configure / configuration
配置, 設置

console
控制台

contextual menu
右鍵菜單

control
控件

copy
n. 副本, v. 拷貝

core program framework
核心程序框架

coupling
耦合

credit
功勞簿, 開發團隊

cursor
光標, 鼠標指針

custom view
自定義視圖

cycle
生命周期, 周期

D
Darwin
Darwin is an open source UNIX computer operating system released by Apple Inc. in 2000. It is composed of code developed by Apple, code derived from NEXTSTEP, and code derived from FreeBSD and other free software projects.


deallocation
回收

delegate / delegation
委托 / 委托機制

design-time
設計環境

designated initializer
指定初始化方法

designator
命名

Developer Document
開發文檔

disable
禁用

disc
光盤, 移動硬盤

disk
磁盤

Dock
n. Dock欄; v. 放入Dock

drawer
抽屜(窗口)

duplicate
復制

E
eject
彈出

emulate / emulator
仿真 / 仿真器

enable
啟用

encapsulation
封裝

enumerate
枚舉

event cycle
事件周期

event loop
事件循環

export / exportor
導出 / 導出器

F
field
(界面中的)域

file wrapper
文件包裝

File's Owner
文件擁有者

first responder
第一響應對象

folder
文件夾

forced
強制(的)

fork
分支

form
表單

formatter
格式器

foundation
基礎

framework
框架

G

generalization
泛化

graphic
圖形

GUI
圖形用戶界面

guideline
准則, 向導線

H
hierarchy
層次

hook
掛接

I
identifier
標識符

image well
圖相框

inheritance
繼承

initial first responder
初始響應對象

initializer
初始化方法

inline
內聯

inspector
查看器

instance
(類的)實例

interrupt handler
中斷處理程序

introspection
內省

K
kernel environment
內核環境

kernel extension
內核擴展

Key Equiv.
等效按鍵

key window
鍵窗口

key-value pair
鍵值對

L
language-aware keyword highlight
語法點亮

library


license
授權

link / linker
連接 / 連接器

load
v. 加載(到內存), 裝載(組件), 讀取(文件);
n. 負荷, 負載

log
日志

low level
底層, 底層的

M

Mac / Macintosh
Macintosh, commonly nicknamed Mac, is a brand name which covers several lines of personal computers designed, developed, and marketed by Apple Inc. The Macintosh 128K was released on January 24, 1984; it was the first commercially successful personal computer to feature a mouse and a graphical user interface (GUI) rather than a command line interface.

mailing list
郵件列表

map
v. 映像

margin
頁邊距

matrix
矩陣

memory cursor
內存光標

memory descriptor
內存描述符

memory protection
內存保護

menu bar
菜單欄

message
消息

mirror
鏡像

mode
模式

modifier key
修飾鍵

mount
掛載

mutable / immutable
可變的 / 不可變的

mutex
互斥體

N
namespace
名字空間

native
原生的

notification
通告

nub
結點

O
oserver
監聽者

offscreen
下屏

onsereen
上屏

OS
Operating System
操作系統

outlet
插座變量

outline view
大綱視圖

overload
(類的)重載, (物品, 電)超載

override
(類的)覆蓋

P
palette
(控件, 組件)選盤

panel
面板

parse
語法分析, 解析

pasteboard
剪貼板

plug-in
插件

polymorphism
多態

preference
偏好設置

preinstall
預裝

preload
預載

procedure
過程

programming interface
編程接口

progress indicator
進度指示器

property list
屬性列表

R
redo
重做

release
釋放(對象, 內存); 發布(版本, 軟件)

Release Note
發布說明

reload
重新加載

responder
響應對象

retain
保持

retain count
保持計數

reusable
可復用的

revert
復原

root


routine
例程

runtime
運行環境


S

schema
(操作)策略, (數據庫)結構

screen
屏幕

scrolling list
滾動列表

selector
選標

serialize / serializer
序列化 / 序列化器

sheet
卷簾窗口

shortcut
快捷鍵

simulate / simulator
模擬 / 模擬器

slider
劃動條

socket
套接字

specification
規范, 規格說明

stack
堆棧

stepper
步進器

stubbed method
存根方法

subclass
子類

subview
子視圖

symbolic link
符號鏈接

synchronous / asynchronous
同步的 / 異步的

T
tab
(窗口中分頁的)頁簽

target / action
目標 / 動作模式

text field
文本框

text label
文本標簽

timestamp
時間戳

titlebar
標題欄

token
令牌, 格式符

tracking rectangle
跟蹤矩形

triangle / disclosure triangle
(三角形)展開符號

U
underlying
下層, 下層的

undo
還原

Unique Application Identifiers
唯一應用程序標識

Universal Access
萬能輔助

Universal Binary
通用二進制

unload
卸載

unmount
卸下

V
viewer
觀察器

volume
卷, 卷宗

W
widget
窗口部件

wired memory
聯系內存

work loop
工作環

WYSIWYG
what you see is what you get
所見即所得

How to Learn

| No Comments | No TrackBacks
All sorts of people come to my class: the bright and the not so bright, the motivated and the lazy, the experienced and the novice. Inevitably, the people who get the most from the class share one characteristic: They remain focused on the topic at hand.

The first trick to maintaining focus is to get enough sleep. I suggest ten hours of sleep each night while you are studying new ideas. Before dismissing this idea, try it. You will wake up refreshed and ready to learn. Caffeine is not a substitute for sleep.

The second trick is to stop thinking about yourself. While learning something new, many students will think, "Damn, this is hard for me. I wonder if I am stupid." Because stupidity is such an unthinkably terrible thing in our culture, the students will then spend hours constructing arguments that explain why they are intelligent yet are having difficulties. The moment you start down this path, you have lost your focus.
Foundation: Every object-oriented programming language needs the standard value, collection, and utility classes. Strings, dates, lists, threads, and timers are in the Foundation framework.

AppKit: All things related to the user interface are in the AppKit framework. Windows, buttons, text fields, events, and drawing classes are in the AppKit. You will also see this framework called the ApplicationKit.

Core Data: Core Data makes it easy to save your objects to a file and then reload them into memory. We say that Core Data is a persistence framework.

原文地址http://blog.csdn.net/chinajash/archive/2006/12/19/1448953.aspx

首先,需要在Windows里面将文件夹共享出来,linux下面可以用Samba配置共享,在Mac机里面按照如下步骤即可访问windows和linux的共享文件夹

1. 打开Finder,  在菜单栏里面, 点击Go->Connect to Server...

2. 在Server Address:下, 输入smb://<user>@<IP>, 点击Connect按钮

3. 选择要访问的共享文件夹, 假设是software文件夹, 点击OK按钮

4. 输入<user>对应的密码, 点击OK按钮

5. 在Mac的桌面上会生产一个software的文件夹, 即是windows或linux共享出来的文件夹software

"以追求心靈方式開發產品"------ 蘋果創始人史蒂夫●乔布斯
8月21日, 蘋果創始人史蒂夫●乔布斯表示, 對於年輕一代計算機工程師而言, 他們在電腦硬件, 軟件開發過程中, 應追求自己靈魂中想要實現的東西, 而不能把眼光只盯在如何賺錢上面. 他說: "如果你們能做到這一點, 將得到巨大的回報, 雖然回報是無形的, 但它卻能給我們帶來心靈上的巨大安慰"

iPhone SDK Release Notes for iPhone OS 2.0

Known Issues

Xcode/Developer Tools

  • You may only use .png files for application icons for the device.

  • You may receive iTunes error messages when installing an IPSW onto the phone via Xcode. (✔)

  • The iPhone SDK is designed for Intel-based Macs and is not supported on PPC-based Macs.(✔)

  • Xcode and the iPhone SDK only work in 32-bit mode; 64-bit mode is not supported.

  • When running and debugging on a device, be sure to turn off Passcode lock.

  • Using the Xcode menu Run > Start with Performance Tool > <instrument> does not work even though it is enabled. The application is not uploaded to the device. When the application is already present, Instruments targets the local machine and "Target failed to start" appears in the tracks.

  • Trying to debug two applications at the same time on the same device fails with a broken pipe error in the debugger console.

  • Instruments will act unpredictably with multiple devices attached

iPhone Simulator

  • iPhone Simulator does not support network home directories.

  • The version of Foundation in the simulator platform includes functionality not included in iPhone OS. To ensure functionality is not used that is not present on iPhone, check the documentation for availability information.

UIImage

  • You have to specify the image extension to -imageNamed: to get results.

UIKit

  • Applications using UINavigationController cannot be launched in landscape mode.

UILabel

  • Including the degree character in a format string disables text updates to a UILabel object.

  • UILabel ignores its contentMode property.

UIScrollView

  • After zooming, content inset is ignored and content is left in the wrong position.

UIStringDrawing

  • UILineBreakModeTruncateHead and UILineBreakModeMiddleTruncation do not work properly for multiline text.

UITableView

  • UITableView ignores separatorStyle and separatorColor.

  • The list of styles available for UITableView specifies "Indexed" and "Grouped" as the two available options; however, the headers and documentation refer to "Indexed" as "Plain".

  • UITextView objects embedded inside a UITableViewCell never receive touches.

  • It is very, very expensive to customize row heights (via tableView:heightForRowAtIndexPath:).

  • Unable to resize table wider than the screen.

UITextField

  • UITextField cannot be made to resign first responder once offscreen.

UITextView

  • UITextView's loupe ignores the underlying view's background color.

  • Setting UITextView.editable to YES should not automatically show the keyboard.

UIToolbarController

  • -[UIToolbarController setSelectionIndex] doesn't work for members of the viewControllers array that are offscreen.

UITouch

  • UITouch is not adjusted when a layer has a transform applied to it.

  • UITouch does not properly handle multiple taps from multiple fingers.

  • An application will not receive UITouchPhaseBegan if a swipe begins on or above the status bar.

UIView

  • Many UIKit controls cannot be resized properly if initialized with a CGRectZero frame.

  • animationDidEnd fires too soon and can cause animations to stutter if you do too much work in the callback.

  • If a view subclass implements -drawRect: then the background color for that view subclass cannot be animated.

UIViewController

  • UINavigationController won't resize content view automatically if barStyle is changed to/from UIBarStyleBlackTranslucent.

  • If a view is detached from a given UIViewController as a top-level nib object, but connected as an outlet, the view's origin is incorrectly moved upwards by approximately 24 pixels.

  • UIViewController does not support fading to a different view when rotated to landscape.

UIWebView

  • UIViewController does not auto-rotate when added to a window that is rotated already.

  • Links don't highlight when WebKit is single threaded.

Media

  • MPVolumeView cannot be created using Interface Builder. To use an MPVolumeView, create it programmatically as you would a normalUIView and call sizeToFit, as follows:



    CGRect frame = CGRectMake(originX, originY, width, 0);


    MPVolumeView *volumeView = [[[MPVolumeView alloc]



    initWithFrame:frame] autorelease];

    [volumeView sizeTo


    [myView addSubview:volumeView];]]




where is my passion??

| No Comments | No TrackBacks
Mac and iPhone development, I am going as far, and as long as I can!
I promise to myself!
想賺錢的都在拼命, 不想賺錢都在瞎折騰!
Hard work for money, hard trick for satisfying the feeling???
閣下屬於哪一種??
which kind you are belonging to?
I can't understand why her smiling so shining?
View imageiphone_gril02.jpegiphone_gril01.jpeg

AP

| No Comments | No TrackBacks
Today, I buy a AP on 360buy.com, the type is TP-Link WR541G+(54M), very useful~
 Now my Mac mini is update soft by the AP, its wireless,
and can be used under  IEEE 802.11g、IEEE 802.11b、IEEE 802.3 IEEE 802.3u
.
support CSMA/CA、CSMA/CD、TCP/IP、PPPoE、DHCP、ICMP、NAT protocol
one 10/100M(WAN) interface,
and four 10/100M(LAN) interface.
and so on~~

Flex 3

| No Comments | No TrackBacks
Today I received a book from ADOBE SYSTEMS, INC.
USA to CHINA, only 3 days, I got it~
and the book is free for me:
 <<Getting Started with Flex3>>, an Adobe developer library pocket guide~
I'll appreciate it!

Stay hungry. Stay foolish.

| No Comments | No TrackBacks
好学若饥, 谦卑若愚( Stay hungry. Stay foolish.)
简单既是美(Simple is beautiful.)

I don't know why I have affection on pure C.
At the beginning of studying the C programming language, I have an idea that: Where there is a C can be Object Oriented, the 'C'  would be  splendid!
Today, when I get acquaintance with Mac OS X, I know there is a language called Objective-C, that's what I dreamd of, so I catch it, totally as a interest.
From now on, my life become simple and clean, I am being an apple developer!
Thx to all!

Effective Objective-C

| No Comments | No TrackBacks

This article is from here~

Effective Objective-C



JavaBook
There is a really great book more than worth reading by Joshua Bloch called Effective Java, Programming Language Guide (Pearson Education Inc, Addison-Wesley) which states in 57 items rules to good Java programming.
Rumors say that the inventors of Java where inspired by some ideas of early Objective-C and therefore as an ObjC programmer you will recognize some idioms and kind of feel home in the Java world.

Actually when I read the book I found that many rules more or less apply to Objective-C as well. In this article I'd like to comment on Joshua's items in regard to Objective-C - if they can be applied and how. You will need a copy of Joshua's book as I don't delve into details here.

Item 1: Static factory methods for creation of objects: Generally this is very good idea. Objective-C does not allow method overloading (think of it as pure C) and hence you would need differently named init-methods anyway so that would not be the reason why you should use class methods as a factory.
The advantage of class factory methods is that they need not create new objects if objects are allowed to be used more than once. You will find an example in
[NSImage imageNamed: @"SomeName"]
Plus class factory methods might give back specialized subclasses. Even though the mechanism differs a little bit in Objective-C go to Apple and read about Class Clusters.

Item 2: Closely related to item 1: Singletons. Take a look at Apple's implementation.

Item 3: If you really want that no object can be created of your class you have to overwrite NSObjects allocWithZone/init and return nil. The concept of a private constructor cannot be realized in Objective-C so the best you can do is to overwrite all allocWithZone returning nil.

Item 4: Prevent object duplicates: Using NSConstantStrings like @"Hello" makes that string constant. You can even enhance its use by declaring it static in the definition file of your class. Now your class can reuse the same string over and over again.
This does not have to be restricted to Strings. You can use any object you like as a static (class) variable. Bloch uses a Date. If you like to do the same declare:
@implementation MyClass
  static NSCalendarDate * const BOOM_START = nil;
+(void) initialize {
  if( self == [MyClass class]) {
    BOOM_START = [[NSCalendarDate alloc] initWithYear:...];
  }
}
@end

+(void) initialize replaces Java's static { } - block.

If for some reason you need a constant String that has to visible outside of your class declare it extern:
deklaration file (.h)
extern NSString * const MY_CONSTANT;
defininition file (.m)
NSString * const MY_CONSTANT = @"Constant Name";

Item 5: Right now Objective-C uses a well defined memory management with retain-counting. In the near future with the release of Mac OS X 10.5 a Garbage Collector for Objective-C will be introduced. It is very likely that item 5 can be applied there.

Item 6: Finalizer. In Objective-C this can be compared to
-(void) dealloc { }
which is called when an object's retain-count is zero. Joshuas idea to have a separate finalizing method which is called explicitly can be taken into account but depends on your design. Generally Objective-C will call dealloc when the retain-count is zero but with autorelease pools it can take a while. If you are sure that no other object is interested in your helper object that you want to terminate calling the finalizing method is a good thing.
But beware of singletons which are shared and not deallocated at runtime. If you use a singleton for database access (connect/disconnect etc) for example when you app quits or crashes disconnect has to be called. That's no problem - just a matter of clear design.
A word of caution on autorelease pools. There are times when an object has to be autoreleased like when it is a return object that was created especially for the caller (read: no ivar). That is part of memory management. But it is not a good idea to use autoreleased objects within a method. For example you have to create objects within a for-loop. Each object will perform a certain task and is not needed later. You cannot reuse that object (for whatever reason). Then alloc/init it, make it perform its task and release it at once. If you put it in the autorelease pool it will stay there at least until the runloop finished one turn. If you create large amounts of objects this means that memory usage explodes and will be released later than necessary.
On the other hand this should be a rare case. Usually you would either reuse your worker object or it is created and put into a collection which means it isn't deallocated. Still then use release after you put into the collection so the autorelease pool won't have to do your work.

Item 7: Equals in Java is exactly the same as isEqual in Objective-C so all the contract rules Bloch describes apply just the same. The same goes for

Item 8: hashCode which simply translates to hash in Objective-C. Both are methodes that are declared as a protocol (in Java: interface) to NSObject so every object understands isEqual and hash but the default implementation of NSObject will not necessarily meet your needs.

Item 9: This is easy as well: Java's toString is reflected in NSObject's description, thus returning a meaningful NSString.

Item 10: clone: The interface Cloneable has the same intention as the protocol NSCopyingcopyWithZone:. Read carefully what Bloch has to say on this matter as this is true in Objective-C as well and can lead to really hard to find bugs.

Item 11: comparable. This is a bit tricky as NSObject itself doesn't feature a compare-mtehod. NSString and NSNumber sure do (compare:) both returning a NSComparisonResult but this is not defined in a protocol/interface. On the other-hand there is an informal protocol in Foundation called NSComparisonMethods which are designed for scripting (NSSpecifierTest).
So probably the best you can do is add compare: to your own classes (if needed) to keep in accordance with the framework.
To sort members of a collection (array in my example) you can provide a selector like the compare:-method (with the same return type of NSComparisonResult and the same signature). As there is no concept like generics in Obj-C you are responsible that each member understands that selector otherwise doesNotRecognizeSelector: is called and you app will misbehave.
Instead of a comparison object - the Java and C++ ("predicate") approach - you can also provide a function pointer to a comparison function with the signature of int (*)(id, id, void *) - which is rather a C-approach. See the documentation for NSArray and the like.

Item 12: Restrict access to members. One of the hardest short-comings of Obj-C is access restriction. You can only set the scope of instance variables with the compiler directives @private, @protected and @public. Methods are always public and always will be due to the dynamism of the runtime. The compiler doesn't have a chance to predict if a certain method exists at runtime (Categories can expand any object's methods) and even doesn't know what classes will be there and which one will be loaded during runtime. And there is nothing like private inheritance.
As I said, all methods are public. You can hide them though by declaring them in the definition file as a Category and thus they are not visible in the class's interface (for the programmer). But they still can be called (and dumped). So yes, you can severely mess with the runtime.
But the least you can do - and should! - is to declare all fields (instance variables) of a class at least @protected and strive to get to the level of @private where appropriate and provide public accessors for them (adhere to Key-Value-Coding here). This is good OOP and you should follow that road. Never let another class access your instance variables directly (even though there are still means to achieve that even though you declared them private - but that is a hack).
Bloch mentions the attribute final. As Obj-C is based on C you can use const to the nearly same effect.

Item 13: Unchangeability. Everything Bloch has to say on that subject you can translate exactly like this to Obj-C classes. Still you will never gain such a high level of security as he does with Java. If you read up to here you can see why. But nonetheless try to adhere to good programming practice.

Item 14: Favor composition over inheritance. Let me just add one thing: Exclamation-mark!

Item 15: Bloch demands to either develop a class for inheritance or make it completely impossible to inherit from that class. Read what he has to say because it is important but you will have to realize that in Obj-C there is nothing like a final class. So you can inherit from every class you want. Add this to the list of weaknesses of Obj-C.

Item 16: Use interfaces (protocols) instead of abstract classes. If you are coming from C++ take this to heart, if you are an old school Obj-C programmer you might have done that all along. Abstract classes have their pros and you should know when to use them but their are not everyday remedy to all problems ;-)

Item 17: Similar to item 16, but seldom found in the frameworks themselfs (AppKit and Foundation): Also use protocols as a type in the parameters of a method. This gives you more flexibility.

Item 18: Obj-C does not have inner classes so this item can not be translated.

The following Chapter 5 deals with substitues for pure C-constructs. All of them will work in Obj-C, of course, but nonetheless Bloch will show you a few advantages the way he implements those substitutes. Item 19, substitute structs with classes, does make sense, and item 20, unions, just don't use them anymore. Item 21, enums are still a relatively common thing and I keep using them as long as they are not saved to disk. Remember that their values (and hence meaning) can change in the next version so if you have to save any enum value take at least a NSConstantString instead. Still his idea of an enum class is interesting, but obsolete with Java 5. Item 22: function pointers can be evil, so try to follow his rules.

Item 23: Check the validity of parameters - just the same in Obj-C. Don't forget to explicitly state in the documentation if and under what conditions this method might throw an exception.

Item 24: The creation of defensive copies is a good idea. Actually the AppKit itself has a pitfall here: If you want to know what the user has entered in a TextField you can ask the current FieldEditor (and sometimes have to if you don't want to end editing). The FieldEditor is an instance of NSText and usually a window has only one of it that is shared among the TextFields - which is a clever approach. But if you want to get the content of what is edited you use
- (NSString *)string
and get back a pointer to an NSString which is a pointer to an internal String that changes when the text gets changed. You have to make a copy yourself if you are interested in maintaining the content, otherwise it is lost.

Item 25 Design method signature carefully should be true for all programming languages ;-)

Item 26: Method overloading is not supported in Obj-C. This is a relict of C. But you can certainly have different constructors - just name them differently. You usually use the pair alloc/init... so you are free to name them accordingly to what they expect - to give you an example here are just some init-methods from NSString:
- (id)initWithString:(NSString *)aString
- (id)initWithUTF8String:(const char *)bytes
- (id)initWithContentsOfURL:(NSURL *)url encoding:(NSStringEncoding)enc error:(NSError **)error
- (id)initWithCharacters:(const unichar *)characters length:(unsigned)length
- (id)initWithBytes:(const void *)bytes length:(unsigned)length encoding:(NSStringEncoding)encoding

Just to give you an idea....

Item 27: This can not be stressed enough! It is good programming practice to return an empty collection instead of nil/null. Like Bloch states: It makes sense. You will see this used throughout the Cocoa framework.

Item 28: Dito. Instead of JavaDoc you can use AppleDoc which is integrated with XCode, meaning macro scripts exists. You might also want to take a look at doxygen. You can copy and change Apple's scripts easily to produce doxygen-tags instead of AppleDoc-tags.

Item 29: Scope of local variables. Since gcc 3.0 (some time ago) you can now declare variables anywhere in your method and hence follow Bloch's advice.

Item 30: Know your framework. Again, this can't be stressed enough: Don't reprogram what others already did and tested for you in many extreme situations by millions of users. Cocoa is part of a RDE and you can gain a lot of time with it - but you have to know what the framework can do for you. The time spent to learn the framework is time saved well later on. A little bit off topic but it should be mentioned here: Don't program what you can download.

Item 31: Float and double an inaccurate. Period. We all learned that and we all should act accordingly. In Obj-C to store big numbers you can use NSDecimalNumber.

Item 32: Dito. You should not use Strings where not appropriate.

Item 33: String concatenation is slow. Every-time you use NSString's
- (NSString *)stringByAppendingString:(NSString *)aString
a new instance of NSString is created. This is slow. Like Bloch writes, use NSMutableString

Item 34: Reference objects by their interface. To use an interface as a type can easily be done in Obj-C, too. So this item also gets a dito. You can write:
NSObject *object;
The only drawback in Obj-C is that collections don't share a common interface even though they have many methods in common.

Item 35: Use Interfaces instead of Reflection. Obj-C is highly dynamic and a concept like reflection is kind of build in. You can load classes at runtime, make classes pose as others and the poor compiler didn't have a chance to know about this mess. This can be erroneous so you have to be careful. Nonetheless skip item 35 in Bloch's book.

Item 36: Native methods. Based on C and thanks to the Obj-C++ compiler you can use both pure C functions and C++ classes mixed (to some great extend) in Obj-C. So there is nothing like Java's native methods with the overhead of switching in the JVM. You can freely use C functions and like always you are responsible for the results.

Item 37: Optimization: Read this item twice - it is important to remember this; always.

Item 38: Keep to the naming conventions. Take a look at Apple's.

...to be continued soon...
with one method: - the counterpart to StringBuffer - instead.

About this Archive

This page is an archive of entries from August 2008 listed from newest to oldest.

September 2008 is the next archive.

Find recent content on the main index or look in the archives to find all content.