0

私はnsmutabeldictionaryこのようなものを持っています

   {
        alert = "test from dot net";
        badge = 1;
        sound = default;
    }

と同じように値10のキー「ID」が必要です

     {
        alert = "test from dot net";
        badge = 1;
        sound = default;
        ID  = 10;
    }

助けてください

4

3 に答える 3

1

あなたのコメントから:

'NSUnknownKeyException'、理由: '[<__NSDictionaryI 0x1ede8740> setValue:forUndefinedKey:]:

実際に不変の辞書を持っているかのように見えます (接尾辞 I に注意してください)。

あなたのコードは次のようになると思います:

//Even though you are assigning to a mutable object
//The method may not return an mutable dictionary
NSMutableDictionary *d = [someObject getDictionary]; 

代わりに次を使用する必要があります。

NSMutableDictionary *d = [NSMutableDictionary dictionaryWithDictionary:[someObject getDictionary]];

次に、快適に使用できます。

[d setObject:@10 forKey:@"ID"];
于 2013-06-06T13:18:48.047 に答える
0

新しいキーを持つ新しいオブジェクトをディクショナリに追加するには、SetObject:forKey メソッドを使用できます。

于 2013-06-06T13:14:04.573 に答える