我正在做一个项目,我希望能够处理一些模板类型的消息。该模板将包含如下内容:
"{{user1}} has just created an account"
然后我有一个数据映射,它会为您提供数据所在的 NSMutableDictionary 中的一个位置:
"activity.message.status"
然后我希望能够通过拆分该字符串来查询 NSMutableDictionary,以便它变成类似这样的内容:
[[[myDictionary objectForKey:@"activity"] objectForKey:@"message"] objectForKey:@"status"]
我可以制作一些东西,只要它始终只有 3 根弦,但有些可能或多或少。
如有任何帮助,我们将不胜感激。
最佳答案
这实际上比将字符串拆分为键要容易得多。 Apples Key-Value-Coding 正是你想要的。
[myDictionary valueForKeyPath:@"activity.message.status"];
A key path is a string of dot separated keys that is used to specify a sequence of object properties to traverse. The property of the first key in the sequence is relative to the receiver, and each subsequent key is evaluated relative to the value of the previous property.
For example, the key path address.street would get the value of the address property from the receiving object, and then determine the street property relative to the address object.
关于iphone - 创建具有多个值的动态 NSMutableDictionary 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10962717/