• Save
Lesson 2 Basicstructure
Upcoming SlideShare
Loading in...5
×
 

Lesson 2 Basicstructure

on

  • 929 views

 

Statistics

Views

Total Views
929
Views on SlideShare
888
Embed Views
41

Actions

Likes
1
Downloads
0
Comments
0

1 Embed 41

http://mobiledev.tw 41

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

CC Attribution-NonCommercial LicenseCC Attribution-NonCommercial License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Lesson 2 Basicstructure Lesson 2 Basicstructure Document Transcript

  • iPhone Development How-To Lesson2. 第一個結構化程式 Step1.Create a new Xcode project Step2.Mac OS X ->Application -> Command Line Tool -> Foundation
  • Step3.輸入專案名稱,Save
  • Step4.在 Source 資料夾上按右鍵,Add -> New File… Step5.Cocoa Touch Class -> Objective-C class -> NSObject,Next
  • Step6.命名
  • Step7.在 fraction.h 中進行修改, .h 檔負責存放@interface 區段: 1. 宣告一個新的類別,並指出此類別的父類別是誰 2. 描述此類別有哪些資料成員 3. 定義方法(method) 備註: A. Fraction 繼承自 NSObject 類別 B. Fraction 有兩個整數變數:numerator, denominator C. –(void) setNumerator:( int)n; 減號代表實體方法,加號代表類別方法 void 代表該方法沒有傳回值 setNumerator 接收一個整數參數,參數名稱為 n Step8.修改 Fraction.m 撰寫 print, setNumerator, setDenominator 方法的內容
  • 9.撰寫主程式 function0615.m #import <Foundation/Foundation.h> #import "Fraction.h" int main (int argc, const char * argv[]) { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; Fraction *myFraction;//宣告一個Fraction物件 myFraction=[[Fraction alloc]init];//分配記憶體與初始化 [myFraction setNumerator:1]; //執行setNumerator方法,並傳入1 [myFraction setDenominator:3];//執行setDenominator方法,並傳入3 NSLog(@"The value of myFraction is:");//於Console視窗顯示字串 [myFraction print];//執行print方法,會顯示出結果 [myFraction release];//釋放記憶體 [pool drain]; return 0; }
  • 10.Build -> Build & Debug,然後點選 Run -> Console 觀看執行結果