我是全新的 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/