我一直在玩 Swift,刚刚遇到了一个问题。
我有以下词典:
var locations:Dictionary<String,CLLocationCoordinate2D> = ["current":CLLocationCoordinate2D(latitude: lat, longitude: lng) ];
println("current locaition is \(locations["current"])")
但编译器抱怨周围的双引号current
它代表我字典中的一个键。
我尝试用它来逃避它\
但这不是正确的方式。
感谢任何帮助。
Xcode 7.1+
从 Xcode 7.1 beta 2 开始,我们现在可以在字符串文字中使用引号。从发行说明来看:
插入到字符串中的表达式现在可以包含字符串文字。例如,“My name is (attributes["name"]!)”现在是一个有效的表达式。 (14050788)
Xcode
我认为你不能那样做。
来自docs https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/Swift_Programming_Language/StringsAndCharacters.html#//apple_ref/doc/uid/TP40014097-CH7-XID_368
在内插字符串的括号内编写的表达式不能包含未转义的双引号 (") 或反斜杠 (\),也不能包含回车符或换行符。
你必须使用
let someVar = dict["key"]
println("Some words \(someVar)")
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)