Help us understand the problem. What is going on with this article?

【Xcode】第二引数以降はラベルをつける【Objective-C】

More than 3 years have passed since last update.

Objective-Cを触り始めて一ヶ月が経ちました。先日言われて初めて気づいたのですが、Objective-Cでは第二引数以降はラベルをつけるのが一般的だそうです。

// 引数が3つの場合
- (戻り値の型)メソッド名:(引数の型)引数1 ラベル:(引数の型)引数2 ラベル:(引数の型)引数3

//@IT Objective-Cのクラスやプロパティ、特徴的なメソッドの使い方 (3/3) 
//http://www.atmarkit.co.jp/ait/articles/1404/09/news029_3.html より引用

実はこの引数のラベル、省略することができるので全く気づかなかったという…

実装

ViewController.m
#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    NSString *stringArgument1 = @"aiueo";
    NSString *stringArgument2 = @"kakikukeko";
    int intArgument = 5;

    [self setMyArgument:stringArgument1 myArgument2:stringArgument2 myArgument3:intArgument];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void) setMyArgument:(NSString *)argument1 myArgument2:(NSString *)argument2 myArgument3:(int)argument3;{
     NSLog(@"myArgument1:%@ myArgment2:%@ myArgment3:%d", argument1, argument2, argument3);
}

@end

実行結果

myArgument1:aiueo myArgment2:kakikukeko myArgment3:5

第一引数はメソッド名(ラベル名?)で関連付けができているので新たに明記しないとのこと

参考

Objective-Cの勉強(2);メソッドの宣言
引数が複数あるメソッドの記述方法

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした