将Swift Dictionary转换为String [英] Convert Swift Dictionary to String

查看:368
本文介绍了将Swift Dictionary转换为String的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了测试和调试,我试图将Dictionary的内容放到String中。但不知道它会实现什么。可能吗?如果是,如何。

For testing and debugging I am trying to put the content of Dictionary to a String. But have no clue hows it going to achieve. Is it possible? If yes, how.

从Web服务获取字典,因此我不知道它具有的键值。我想在app中使用数据。

Dictionary is fetched from web service so I have no idea the key values it have. I want to use the data in app.

在Objective C中,%@足以在NSString中存储任何内容。

In Objective C %@ was enough to store anything in NSString.

推荐答案

只需使用 CustomStringConvertible 描述属性为

注意:在Swift之前3(或可能在之前), CustomStringConvertible 被称为可打印

Note: Prior to Swift 3 (or perhaps before), CustomStringConvertible was known as Printable.

这篇关于将Swift Dictionary转换为String的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆