相关疑难解决方法(0)

NSDictionary`描述`格式化问题 - 将结构视为char数据

我有一个自定义类(在概念上类似于NSArray,希望格式化外观),它有一个description格式化程序.

当单独打印格式化程序的输出(NSLog)时,它看起来很好,但当它作为NSDictionary description的元素包含时,NSDictionary格式化程序似乎决定它是一个字符串,而不是结构定义,用引号括起来,转义字符串中的所有控制字符.

当然,对于标准的NSArray,它不会这样做,所以我想知道它是如何决定以一种方式对待另一种方式来处理字符串的.

例如,而不是具有如下输出:

theChildren = (
                  {
                      "@meta.type" = "ns3:location";
                      "childNumber" = 0;
                      ...
Run Code Online (Sandbox Code Playgroud)

看起来像:

theChildren = "( \n\t\t {\n\t  \"@meta.type\" = \"ns3:location\";\n\t   \"childNumber\" = 0;
...
Run Code Online (Sandbox Code Playgroud)

任何人都可以提出改变这种行为的方法吗?

FWIW,我NSDictionary description在NSMutableString中累积描述字符串(主要包含来自调用的结果的数据),然后NSString stringFromString在退出处执行(虽然我不知道这会做什么).

添加

我想我找到了NSDictionary写入中的答案(尚未检查):

讨论

返回的NSString对象包含每个字典条目的字符串表示形式.descriptionWithLocale:indent:获取给定键或值的字符串表示形式,如下所示:

If the object is an NSString object, it is used as is.

If the object responds to descriptionWithLocale:indent:, that
Run Code Online (Sandbox Code Playgroud)

调用方法以获取对象的字符串表示形式.

If the object responds to descriptionWithLocale:, that method is
Run Code Online (Sandbox Code Playgroud)

调用以获取对象的字符串表示形式.

If none of the above conditions …
Run Code Online (Sandbox Code Playgroud)

iphone formatting objective-c ios

8
推荐指数
2
解决办法
3024
查看次数

标签 统计

formatting ×1

ios ×1

iphone ×1

objective-c ×1