Mais conteúdo relacionado Semelhante a NS Prefix 外伝 … Copy-On-Write #関モバ (16) Mais de Tomohiro Kumagai (20) NS Prefix 外伝 … Copy-On-Write #関モバ25. public struct Data
: ReferenceConvertible, _MutablePairBoxing {
// NSData とのブリッジ
public typealias ReferenceType = NSData
// 参照をラップ (Boxing) する
internal var _wrapped : _SwiftNSData
26. internal final class _SwiftNSData {
// NSData と NSMutableData とを管理するラッパー
var __wrapped : _MutableUnmanagedWrapper<
NSData, NSMutableData>
29. public mutating func append(_ other: Data) {
// この関数で mutableCopy の必要性を判断・実施
_applyUnmanagedMutation { $0.append(other) }
}
30. public init(capacity: Int) {
if let d = NSMutableData(capacity: capacity) {
_wrapped = _SwiftNSData(mutableObject: d)
} else {
fatalError("Unable to allocate data
of the requested capacity")
}
}
32. public static func _forceBridgeFromObjectiveC(
_ input: NSData, result: inout Data?) {
result = Data(referencing: input)
}
public init(referencing reference: NSData) {
_wrapped = _SwiftNSData(immutableObject:
reference.copy() as AnyObject)
}
38. public struct Date
: ReferenceConvertible {
// NSDate とのブリッジ
public typealias ReferenceType = NSDate
// データを TimeInterval (Double) で直接保持
fileprivate var _time : TimeInterval