iphone - 创建具有多个值的动态 NSMutableDictionary 查询

标签 iphone ios templates dynamic nsmutabledictionary

我正在做一个项目,我希望能够处理一些模板类型的消息。该模板将包含如下内容:

"{{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.

Key-Value Coding Programming Guide

关于iphone - 创建具有多个值的动态 NSMutableDictionary 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10962717/

相关文章:

ios - 将数据从 tableview 传回 viewcontroller textfield Objective - C

iphone - 如何在 Safari 中打开 UIWebview 中的链接

ios - AVPlayerViewController UITapGestureRecognizer 在 ios 11 中不起作用

具有纯虚函数的模板类的 C++ 语法?

c++ - 使用模板 C++ 的链表实现中未解析的外部符号

iphone - 动态改变UITextView高度而不是滚动

iphone - 向 iphone 应用程序添加可达性会导致链接错误

ios - UINavigationController 后退按钮标题不一致?

c++ - 如何在编译时打印常量值?

ios - iOS7 中的滑动手势控制问题