I. Overview
- Before the OC project used the command line to create and compile, link, run the project
- This article introduces the use of IDE tool xcode to create projects, create new class files and run projects
Two xcode to create a project
-
Click in turn: Xcode ——> File ——> New ——> Project to open the project creation window
-
In the project creation window, select the macOS tab
Command Line Tool
-
Select or fill in the corresponding content on the options when the project is created
Product Name:项目名字 Organization Name(可无) Organization Identifier:组织标识(一般填入公司的网址) Bundle Identifier:无需填写,根据Organization Identifier和Product Name,自动生成 Languge:有C,C++,Object-C和switch语言(本文选择Object-C)
-
Next, choose the file storage location
-
Click the
▶️
run project in the upper left corner to view the project output
Three new files
-
Click in turn: Xcode ——> File ——> New ——> File to open the file new dialog box
-
In the New File dialog box, select the macOS tab
Cocoa Class
-
When creating a new class, fill in the class name and go to the next step
-
After the file is created, there are more files under the project (Person.h, Person.m)
//文件声明 Person.h #import <Foundation/Foundation.h> NS_ASSUME_NONNULL_BEGIN @interface Person : NSObject @end NS_ASSUME_NONNULL_END //文件实现 Person.m #import "Person.h" @implementation Person @end
Four main function calls
#import <Foundation/Foundation.h>
#include "Person.h"
int main(int argc, const char * argv[]) {
@autoreleasepool {
// insert code here...
//NSLog(@"Hello, World!");
Person *person=[Person new];
[person setAge:10];
NSLog(@"年龄是%d",[person age]);
}
return 0;
}