我在Swift教学书中看到了这两个陈述。
let padding = String(count: spaces, repeatedValue: Character(" "))
println(String(format:"%@%@", "Year", "Test"))
我的问题是:
String(count:repeatedValue:)
和String(format:)
的初始值设定项
字符串?String(format:)
的在线文档
你能建议任何链接吗?init()
和Apple文档中的init(count:repeatedValue)
非常感谢。
答案 0 :(得分:0)
字符串是Swift中的结构。您可以在Xcode中获取文档。
以下是详细信息。
/// Objective-C Bridge /// ================== /// ///
String
是 桥接到Objective-C为NSString
,以及String
/// 起源于Objective-C可以将其字符存储在///NSString
。由于任何NSSString
的任意子类都可以/// 成为String
,无法保证表示或/// 在这种情况下的效率。由于NSString
是不可变的,因此它是/// 就好像存储是由某些副本共享的:///中的第一个 任何变异操作序列都会导致复制元素/// 进入独特的,连续的存储,可能花费O(N)
时间和/// 空格,其中N
是字符串表示的长度(或/// 更多,如果基础NSString
具有异常性能/// 特性)。
struct String {
init()
}
这是String的扩展名。
extension String {
/// Construct an instance that is the concatenation of `sz` copies
/// of `repeatedValue`
init(count sz: Int, repeatedValue c: Character)
/// Construct an instance that is the concatenation of `sz` copies
/// of `Character(repeatedValue)`
init(count: Int, repeatedValue c: UnicodeScalar)
/// `true` iff `self` contains no characters.
var isEmpty: Bool { get }
}