SlideShare une entreprise Scribd logo
1  sur  7
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 觀看執行結果

Contenu connexe

En vedette

Webinar slides: ClusterControl New Features Webinar
Webinar slides: ClusterControl New Features Webinar Webinar slides: ClusterControl New Features Webinar
Webinar slides: ClusterControl New Features Webinar Severalnines
 
Webinar slides: Managing MySQL Replication for High Availability
Webinar slides: Managing MySQL Replication for High AvailabilityWebinar slides: Managing MySQL Replication for High Availability
Webinar slides: Managing MySQL Replication for High AvailabilitySeveralnines
 
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNs
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNsTemporal Action Localization in Untrimmed Videos via Multi Stage CNNs
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNsUniversitat Politècnica de Catalunya
 
Marcapasos: Aspectos Prácticos
Marcapasos: Aspectos PrácticosMarcapasos: Aspectos Prácticos
Marcapasos: Aspectos PrácticosCardioTeca
 
Scaling Analytics with Apache Spark
Scaling Analytics with Apache SparkScaling Analytics with Apache Spark
Scaling Analytics with Apache SparkQuantUniversity
 
MNIST for ML beginners
MNIST for ML beginnersMNIST for ML beginners
MNIST for ML beginners홍배 김
 
Creative AI & multimodality: looking ahead
Creative AI & multimodality: looking aheadCreative AI & multimodality: looking ahead
Creative AI & multimodality: looking aheadRoelof Pieters
 

En vedette (8)

Webinar slides: ClusterControl New Features Webinar
Webinar slides: ClusterControl New Features Webinar Webinar slides: ClusterControl New Features Webinar
Webinar slides: ClusterControl New Features Webinar
 
Webinar slides: Managing MySQL Replication for High Availability
Webinar slides: Managing MySQL Replication for High AvailabilityWebinar slides: Managing MySQL Replication for High Availability
Webinar slides: Managing MySQL Replication for High Availability
 
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNs
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNsTemporal Action Localization in Untrimmed Videos via Multi Stage CNNs
Temporal Action Localization in Untrimmed Videos via Multi Stage CNNs
 
Marcapasos: Aspectos Prácticos
Marcapasos: Aspectos PrácticosMarcapasos: Aspectos Prácticos
Marcapasos: Aspectos Prácticos
 
Scaling Analytics with Apache Spark
Scaling Analytics with Apache SparkScaling Analytics with Apache Spark
Scaling Analytics with Apache Spark
 
MNIST for ML beginners
MNIST for ML beginnersMNIST for ML beginners
MNIST for ML beginners
 
Creative AI & multimodality: looking ahead
Creative AI & multimodality: looking aheadCreative AI & multimodality: looking ahead
Creative AI & multimodality: looking ahead
 
svaneke
svanekesvaneke
svaneke
 

Plus de Ryan Chung

Voice-First Games for Alexa
Voice-First Games for AlexaVoice-First Games for Alexa
Voice-First Games for AlexaRyan Chung
 
AI Service Integration - Education
AI Service Integration - EducationAI Service Integration - Education
AI Service Integration - EducationRyan Chung
 
AI Service Integration
AI Service IntegrationAI Service Integration
AI Service IntegrationRyan Chung
 
AI Adoption in the Enterprise
AI Adoption in the EnterpriseAI Adoption in the Enterprise
AI Adoption in the EnterpriseRyan Chung
 
Intro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot DevelopmentIntro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot DevelopmentRyan Chung
 
AI in Classroom
AI in ClassroomAI in Classroom
AI in ClassroomRyan Chung
 
AWS re:Invent 2018 Recap
AWS re:Invent 2018 RecapAWS re:Invent 2018 Recap
AWS re:Invent 2018 RecapRyan Chung
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration WorkshopRyan Chung
 
Smart Home Intro Lab
Smart Home Intro LabSmart Home Intro Lab
Smart Home Intro LabRyan Chung
 
Introduction to DialogFlow
Introduction to DialogFlow Introduction to DialogFlow
Introduction to DialogFlow Ryan Chung
 
Conversational AI Orientation
Conversational AI OrientationConversational AI Orientation
Conversational AI OrientationRyan Chung
 
Udacity Meet Up - 0413
Udacity Meet Up - 0413Udacity Meet Up - 0413
Udacity Meet Up - 0413Ryan Chung
 
Amazon Alexa Development Part II
Amazon Alexa Development Part IIAmazon Alexa Development Part II
Amazon Alexa Development Part IIRyan Chung
 
Amazon Alexa Development
Amazon Alexa DevelopmentAmazon Alexa Development
Amazon Alexa DevelopmentRyan Chung
 
Microsoft Professional Program - AI
Microsoft Professional Program - AIMicrosoft Professional Program - AI
Microsoft Professional Program - AIRyan Chung
 
AI Service Integration
AI Service IntegrationAI Service Integration
AI Service IntegrationRyan Chung
 
Hour of Code - Amazon Alexa
Hour of Code - Amazon AlexaHour of Code - Amazon Alexa
Hour of Code - Amazon AlexaRyan Chung
 

Plus de Ryan Chung (20)

Voice-First Games for Alexa
Voice-First Games for AlexaVoice-First Games for Alexa
Voice-First Games for Alexa
 
AI Service Integration - Education
AI Service Integration - EducationAI Service Integration - Education
AI Service Integration - Education
 
AI Service Integration
AI Service IntegrationAI Service Integration
AI Service Integration
 
AI Adoption in the Enterprise
AI Adoption in the EnterpriseAI Adoption in the Enterprise
AI Adoption in the Enterprise
 
Intro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot DevelopmentIntro to Dialogflow Chatbot Development
Intro to Dialogflow Chatbot Development
 
AI in Classroom
AI in ClassroomAI in Classroom
AI in Classroom
 
AWS re:Invent 2018 Recap
AWS re:Invent 2018 RecapAWS re:Invent 2018 Recap
AWS re:Invent 2018 Recap
 
MovieBot
MovieBotMovieBot
MovieBot
 
Service Integration Workshop
Service Integration WorkshopService Integration Workshop
Service Integration Workshop
 
MPP AI
MPP AIMPP AI
MPP AI
 
Smart Home Intro Lab
Smart Home Intro LabSmart Home Intro Lab
Smart Home Intro Lab
 
Introduction to DialogFlow
Introduction to DialogFlow Introduction to DialogFlow
Introduction to DialogFlow
 
Conversational AI Orientation
Conversational AI OrientationConversational AI Orientation
Conversational AI Orientation
 
Udacity Meet Up - 0413
Udacity Meet Up - 0413Udacity Meet Up - 0413
Udacity Meet Up - 0413
 
Amazon Alexa Development Part II
Amazon Alexa Development Part IIAmazon Alexa Development Part II
Amazon Alexa Development Part II
 
Amazon Alexa Development
Amazon Alexa DevelopmentAmazon Alexa Development
Amazon Alexa Development
 
Microsoft Professional Program - AI
Microsoft Professional Program - AIMicrosoft Professional Program - AI
Microsoft Professional Program - AI
 
AI Service Integration
AI Service IntegrationAI Service Integration
AI Service Integration
 
Intro to AI
Intro to AIIntro to AI
Intro to AI
 
Hour of Code - Amazon Alexa
Hour of Code - Amazon AlexaHour of Code - Amazon Alexa
Hour of Code - Amazon Alexa
 

Lesson 2 Basicstructure

  • 1. iPhone Development How-To Lesson2. 第一個結構化程式 Step1.Create a new Xcode project Step2.Mac OS X ->Application -> Command Line Tool -> Foundation
  • 3. Step4.在 Source 資料夾上按右鍵,Add -> New File… Step5.Cocoa Touch Class -> Objective-C class -> NSObject,Next
  • 5. 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 方法的內容
  • 6. 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; }
  • 7. 10.Build -> Build & Debug,然後點選 Run -> Console 觀看執行結果