3

私の質問は、ログの最後の 4 行を出力する理由です (以下を参照)。ここで基本的なものが欠けています... thx

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
    [NSURL URLWithString: @"www.stanford.edu"], 
    @"Stanford University", 
    [NSURL URLWithString: @"www.apple.com"], 
    @"Apple shop", 
    [NSURL URLWithString: @"cs193p.stanford.edu"], 
    @"CS193P course", 
    [NSURL URLWithString: @"itunes.stanford.edu"], 
    @"Stanford on iTunes U", 
    [NSURL URLWithString: @"stanfordshop.com"], 
    @"Stanford Mall", 
    nil];

NSMutableArray *myArray = [NSMutableArray arrayWithObjects:
    [NSString init],
    [NSURL URLWithString: @"www.stanford.edu"],
    [NSProcessInfo processInfo],
    dictionary,
    [@"Mutable string example" mutableCopy],
    [@"another mutable string" mutableCopy]];

NSEnumerator *enumerator = [myArray objectEnumerator];
id object;

while ((object = [enumerator nextObject])) {
    NSLog([object description]);
}

2009-07-02 09:35:12.756 WhatATool[6407:10b] NSString
2009-07-02 09:35:12.756 WhatATool[6407:10b] www.stanford.edu
2009-07-02 09:35:12.757 WhatATool[ 6407:10b] <NSProcessInfo: 0x107e20>
2009-07-02 09:35:12.758 WhatATool[6407:10b] {
「アップル ショップ」= www.apple.com;
「CS193P コース」 = cs193p.stanford.edu;
"スタンフォード モール" = stanfordshop.com;
「スタンフォード大学」= www.stanford.edu;
「iTunes U のスタンフォード」 = itunes.stanford.edu;
}
2009-07-02 09:35:12.758 WhatATool[6407:10b] 可変文字列の例
2009-07-02 09:35:12.759 WhatATool[6407:10b] 別の可変文字列
2009-07-02 09:35:12.760 WhatATool [6407:10b] itunes.stanford.edu
2009-07-02 09:35: 12.760 WhatATool[6407:10b] iTunes U の
スタンフォード
[6407:10b] スタンフォード モール

4

2 に答える 2

24

便利なメソッドを使用して NSMutableArray を作成するときに、最後の引数として必要な nil が欠落していると思います。する

NSMutableArray *myArray = [NSMutableArray arrayWithObjects:
    [NSString init],
    [NSURL URLWithString: @"www.stanford.edu"],
    [NSProcessInfo processInfo],
    dictionary,
    [@"Mutable string example" mutableCopy],
    [@"another mutable string" mutableCopy],
    nil];

仕事?

于 2009-07-02T00:35:02.743 に答える
4

警告をオンにすると (他の警告フラグ "-Wall")、次のようになります。

警告: 関数呼び出しにセンチネルがありません

NSMutableArray arrayWithObjects メソッドの最後に、欠落している nil について通知します。

于 2009-07-02T02:47:06.860 に答える