差不多該學學 Objective-C 了,手邊也有 iphone 及相關的環境可開發,剩下只有懶散的心情要整頓。至於什麼是 Objective-C ,可以先看看維基百科的介紹,我覺得還滿詳盡的,甚至英文版還有介紹從 C/C++ 跨到 Objective-C 的範例程式,真的就乾心哩,看程式比看英文快上十倍啊。
跟 iphone 開發相關的網頁介紹:
- Introduction to The Objective-C Programming Language
- Objective-C Runtime Programming Guide
- Objective-C Runtime Reference
其他相關的教學
接著,就只剩環境架設的部分,
在 Ubuntu 9.10 最簡化版:
- 安裝相關套件- # sudo apt-get install gnustep-devel
- The following extra packages will be installed:
 gnustep-back-common gnustep-back0.16 gnustep-back0.16-art gnustep-base-doc gnustep-core-devel gnustep-core-doc gnustep-gpbs gnustep-gui-common
 gnustep-gui-doc gnustep-gui-runtime gnustep-make-doc gorm.app libaspell-dev libaudiofile-dev libgif-dev libgnustep-gui-dev libgnustep-gui0.16
 libjpeg62-dev libpng12-dev librenaissance0 librenaissance0-dev libtiff4-dev libtiffxx0c2 projectcenter.app projectmanager.app zlib1g-dev
 
- 安裝完就能用 gcc 進行編譯囉- # gcc -lgnustep-base -lpthread -lobjc -lm -I/usr/local/include/GNUstep -I/usr/include/GNUstep source.m -o source_run
 
- 參考資料- [ubuntu] how do I compile objective C on ubuntu - Ubuntu Forums
- 文章建議安裝: build-essential s, gobjc, gnustep-common, gnustep-devel, and libgnustep-base-dev.
 
使用 Makefile 的教學:
- 建立 GNUmakefile- GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles/
 include $(GNUSTEP_MAKEFILES)/common.make
 TOOL_NAME = LogTest
 LogTest_OBJC_FILES = source.m
 include $(GNUSTEP_MAKEFILES)/tool.make
- 最上頭那段是我自己加的,網路上大部分的文件都是使用 shell 來設置環境變數- C shell- # source <GNUstep root>/System/Library/Makefiles/GNUstep.csh
 
- Bourne shell- # . <GNUstep root>/System/Library/Makefiles/GNUstep.sh
 
 
- C shell
 
- GNUSTEP_MAKEFILES = /usr/share/GNUstep/Makefiles/
- 建立 source.m- #include <stdio.h>
 /*
 * The next #include line is generally present in all Objective-C
 * source files that use GNUstep. The Foundation.h header file
 * includes all the other standard header files you need.
 */
 #include <Foundation/Foundation.h>
 /*
 * Declare the Test class that implements the class method (classStringValue).
 */
 @interface Test
 + (const char *) classStringValue;
 @end
 /*
 * Define the Test class and the class method (classStringValue).
 */
 @implementation Test
 + (const char *) classStringValue;
 {
 return "This is the string value of the Test class";
 }
 @end
 /*
 * The main() function: pass a message to the Test class
 * and print the returned string.
 */
 int main(void)
 {
 printf("%s\n", [Test classStringValue]);
 return 0;
 }
 
- #include <stdio.h>
- 編譯與測試- # mkdir test ; cd test ;
- # vim GNUmakefile (內容如上)
- # vim source.m (內容如上)
- # make ;
- # ./obj/LogTest - 輸出結果:This is the string value of the Test class
 
 
- 參考資料- Objective-C GNUstep Base Programming Manual: Introduction - 1.5 Building Your First Objective-C Program
- Ubuntu 下 Objective-C 开发环境
- Learn Objective-C on Ubuntu
 
 
謝謝你的教學,在這篇文章以及蔡明志翻譯的新書下
回覆刪除在下也開始"玩" Objective-C 了
不過很快的就發現gunstep 編譯的限制
目前我發現的差異有
不支援 @property, @synthesize 這些設定屬性方式
也似乎不支援 物件.屬性 = XX,非得要用 [物件 屬性] = XX 才行
不知道你有沒有遇到類似的問題,挺煩人的
版主回覆:(04/13/2010 12:01:12 AM)
哦哦,後來工作上公司有配 Mac Mini 了 XD 從此我就都用 Mac 跟 Xcode 來開發了 orz
暫時沒有其他經驗可以分享
不過 @property, @synthesize 只是自動幫你把一些冗長重複性的 func 幫你寫好而已,因此,你只要手動去把他們打出來,或許就可以使用"物件.屬性" 的存取方式囉!你可以再留意看看。此部份算是我猜想而已 XD,但感覺像 C++ 可以自行去定義 operator(運算子) 的感覺,如物件相加、相乘等等。