ios - Swift println 不打印数组值

标签 ios xcode swift

我是全新的 Swift 学习者,我想知道我在这里做错了什么?我喜欢玩代码来获得理解。

var shoppingList = ["pound of catfish", "bottle of fresh water", "bag of tulips", "can of blue paint"]

println("Susie checks her Shopping List to find that a \(shoppingList[2]) is her third item.")

我想弄清楚为什么输出没有说“Susie 检查她的购物 list ,发现一袋郁金香是她的第三件商品。”与目前所说的相反:与上面完全相同,“Susie 检查她的购物 list ,发现 (shoppingList[2]) 是她的第三项。”

我知道这是一个非常基本的概念,但我想确保我 100% 理解所有内容。

谢谢!

最佳答案

这里的问题是您只是输出字符串“(shoppingList[2])”。

要用您想要的值替换它,您必须首先使用 \ 对字符串进行转义。

var shoppingList = ["pound of catfish", "bottle of fresh water", "bag of tulips", "can of blue paint"]

"Susie checks her Shopping List to find that a \(shoppingList[2]) is her third item."

这称为字符串插值,您可以找到更多信息 here .

关于ios - Swift println 不打印数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24501977/

相关文章:

arrays - 获取枚举数组的基数组

ios - 有条件的 MFMessageComposeViewController 中的 MessageComposeResult 与 swift

ios - Swift 我需要 layoutifneeded() 吗

ios - “folly/Portability.h”文件未找到 React 库

iOS - 我可以将 Google Ads 或 Apple iAds 放置在 App Store 之外的应用上吗?

objective-c - 从 NSDictionary 中获取特定数据

iphone - 与每个细胞独特合作的一种观点

android - 在 .net 中实现从移动应用程序到服务器的同步

ios - 使用 MPMoviePlayerController 播放视频时如何静音/取消静音?

c# - 如何使用 Xamarin Forms Shell 在 iOS 中的 Tabbar 行和图标之间添加空格?