NSDictionary 带有键 =>字符串和值 => c-样式数组
我需要一个 NSDictionary,它具有字符串形式的键 (@"key1", @"key2"
) 和 C 风格二维数组形式的值 (valueArray1, valueArray2
) 其中 valueArray1
定义为:
int valueArray1[8][3] = { {25,10,65},{50,30,75},{60,45,80},{75,60,10},
{10,70,80},{90,30,80},{20,15,90},{20,20,15} };
valueArray2 也是如此。
我的目标是给定一个 NSString 我需要获取相应的二维数组。 我想使用 NSArray 而不是 c 风格的数组会起作用,但是我无法像上面那样初始化数组(我有很多这样的数组)。但是,如果这是可行的,请告诉我如何做。
目前,以下内容给出警告“从不兼容的指针类型传递'dictionaryWithObjectsAndKeys:'的参数1”: <代码>
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:valueArray1,@"key1",
valueArray2,@"key2",nil];
I need an NSDictionary which has key in the form of string (@"key1", @"key2"
) and value in the form of a C-style two-dimensional array (valueArray1,valueArray2
) where valueArray1
is defined as :
int valueArray1[8][3] = { {25,10,65},{50,30,75},{60,45,80},{75,60,10}, {10,70,80},{90,30,80},{20,15,90},{20,20,15} };
And same for valueArray2.
My aim is given an NSString i need to fetch the corresponding two-dimensional array.
I guess using an NSArray, instead of c-style array, will work but then i cannot initialize the arrays as done above (i have many such arrays). If, however, that is doable please let me know how.
Currently the following is giving a warning "Passing argument 1 of 'dictionaryWithObjectsAndKeys:' from incompatible pointer type" :
NSDictionary *myDict = [NSDictionary dictionaryWithObjectsAndKeys:valueArray1,@"key1", valueArray2,@"key2",nil];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
valueArray2 也是一个
int[][3]
吗?如果是这样,您可以将数组转换为 ObjC 值。要检索内容,您需要使用
如果只有 2 个键,则使用类似的函数会更有效
Is valueArray2 also an
int[][3]
? If so, you could useto convert the array into an ObjC value. To retrieve the content, you need to use
If there's just 2 keys, it is more efficient to use a function like
不是直接添加数组作为 NSDictionary 中的值,而是创建一个自定义类,在其中创建 NSArray 的变量...并将此类对象设置为值,就像
MyClassObj1 和 MyClassObj2 是 MyClass 的成员一样
Rather than Adding Array Directly as a value in NSDictionary make a custom class in which create variable of NSArray ... and set this class object as value like
where MyClassObj1 and MyClassObj2 are member of MyClass