OC development-xcode新しいプロジェクト(22)

概要

  • OCプロジェクトがコマンドラインを使用してプロジェクトを作成およびコンパイル、リンク、実行する前
  • この記事では、IDEツールxcodeを使用してプロジェクトを作成し、新しいクラスファイルを作成してプロジェクトを実行する方法を紹介します

プロジェクトを作成する2つのxcode

  • Xcode-> File-> New-> Projectの順にクリックして、プロジェクト作成ウィンドウを開きます。

  • プロジェクト作成ウィンドウで、[macOS]タブを選択しますCommand Line Tool

  • プロジェクトの作成時に、オプションの対応するコンテンツを選択または入力します

    Product Name:项目名字
    Organization Name(可无)
    Organization Identifier:组织标识(一般填入公司的网址)
    Bundle Identifier:无需填写,根据Organization Identifier和Product Name,自动生成
    Languge:有C,C++,Object-C和switch语言(本文选择Object-C)
    

  • 次に、ファイルの保存場所を選択します

  • 左上隅の▶️実行プロジェクトをクリックして、プロジェクト出力表示します

3つの新しいファイル

  • Xcode-> File-> New-> Fileの順にクリックして、新しいファイルのダイアログボックスを開きます。

  • (新しいファイル)ダイアログボックスで、macOSタブを選択しますCocoa Class

  • 新しいクラスを作成するときは、クラス名を入力して次のステップに進みます

  • ファイルが作成されると、プロジェクトの下にさらにファイルがあります(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
    

4つの主な関数呼び出し

#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;
}
362の元の記事を公開 118の賞賛 530,000ビュー

おすすめ

転載: blog.csdn.net/Calvin_zhou/article/details/105321979