将数组嵌套到NSDictionary对象(Objective-C) [英] Nesting arrays into NSDictionary object (Objective-C)
问题描述
我想使用NSDictionary定义任务,我想保存在plist文件中(到目前为止,我还没有运行Core Data),但是遇到了两个问题:
I would like to define tasks using NSDictionary, which I'd like to save in a plist file (I didn't have much luck with Core Data so far), but got stuck at two points:
当使用 initWithObjectsAndKeys:
我可以使用NSDate的 numberWithInt更改数据类型为数字或布尔值:
和 numberWithBool:
方法。我似乎找不到方法来改变类型到日期虽然。我在文档中找不到类似的东西。
-- When using initWithObjectsAndKeys:
I can change the data type to number or boolean, using NSDate's numberWithInt:
and numberWithBool:
methods, respectively. I can't seem to find the method to change the type to date though. I couldn't find anything like that in the documentation.
- 我碰到的第二个问题是嵌套数组。我如何将它们添加到字典?
-- The second problem I ran into was with the nested arrays. How can I add them to the dictionary?
我已将图片上传到这里我想要实现的。提前感谢!
I have uploaded a picture to here of what I am trying to achieve. Thank you in advance!
推荐答案
您的意思是 NSNumber
code> + numberWithInt:和 + numberWithBool:
方法,而不是 NSDate
?它是定义这些方法的NSNumber。
Do you mean NSNumber
's +numberWithInt:
and +numberWithBool:
methods, not NSDate
? It's NSNumber that defines those methods.
要将数字转换为日期,它实际上取决于数字是多少。如果是UNIX时间戳,则 [NSDate dateWithTimeIntervalSince1970:theTimestampInSeconds]
。
To convert a number to a date, it really depends on what the number is. If it's a UNIX timestamp, then [NSDate dateWithTimeIntervalSince1970:theTimestampInSeconds]
.
至于添加 NSArray
对象到字典:
[yourDictionary setObject:yourArray forKey:@"SomeKey"];
如果您需要更多帮助,您需要发布一些代码,因为您的问题不是很清楚。
You'll have to post some code if you need more help as your question isn't very clear.
这篇关于将数组嵌套到NSDictionary对象(Objective-C)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!