forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSObject.swift
171 lines (128 loc) · 4.62 KB
/
NSObject.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
import CoreFoundation
public protocol NSObjectProtocol {
func isEqual(object: AnyObject?) -> Bool
var hash: Int { get }
func `self`() -> Self
func isProxy() -> Bool
var description: String { get }
var debugDescription: String { get }
}
extension NSObjectProtocol {
public var debugDescription: String {
return description
}
}
public struct NSZone : NilLiteralConvertible {
public init() {
}
public init(nilLiteral: ()) {
}
}
public protocol NSCopying {
func copyWithZone(zone: NSZone) -> AnyObject
}
extension NSCopying {
public func copy() -> AnyObject {
return copyWithZone(nil)
}
}
public protocol NSMutableCopying {
func mutableCopyWithZone(zone: NSZone) -> AnyObject
}
extension NSMutableCopying {
public func mutableCopy() -> AnyObject {
return mutableCopyWithZone(nil)
}
}
public class NSObject : NSObjectProtocol, Equatable, Hashable {
// Important: add no ivars here. It will subvert the careful layout of subclasses that bridge into CF.
public init() {
}
public func copy() -> AnyObject {
if let copyable = self as? NSCopying {
return copyable.copyWithZone(nil)
}
return self
}
public func mutableCopy() -> AnyObject {
if let copyable = self as? NSMutableCopying {
return copyable.mutableCopyWithZone(nil)
}
return self
}
public func isEqual(object: AnyObject?) -> Bool {
return object === self
}
public var hash: Int {
return ObjectIdentifier(self).hashValue
}
public func `self`() -> Self {
return self
}
public func isProxy() -> Bool {
return false
}
public var description: String {
return "<\(self.dynamicType): \(unsafeAddressOf(self))>"
}
public var debugDescription: String {
return description
}
public var _cfTypeID: CFTypeID {
return 0
}
// TODO move these back into extensions once extension methods can be overriden
public var classForCoder: AnyClass {
return self.dynamicType
}
public func replacementObjectForCoder(aCoder: NSCoder) -> AnyObject? {
return self
}
// TODO: Could perhaps be an extension of NSCoding instead. The reason it is an extension of NSObject is the lack of default implementations on protocols in Objective-C.
public var classForKeyedArchiver: AnyClass? {
return self.classForCoder
}
// Implemented by classes to substitute a new class for instances during
// encoding. The object will be encoded as if it were a member of the
// returned class. The results of this method are overridden by the archiver
// class and instance name<->class encoding tables. If nil is returned,
// then the null object is encoded. This method returns the result of
// [self classForArchiver] by default, NOT -classForCoder as might be
// expected. This is a concession to source compatibility.
public func replacementObjectForKeyedArchiver(archiver: NSKeyedArchiver) -> AnyObject? {
return self.replacementObjectForCoder(archiver)
}
// Implemented by classes to substitute new instances for the receiving
// instance during encoding. The returned object will be encoded instead
// of the receiver (if different). This method is called only if no
// replacement mapping for the object has been set up in the archiver yet
// (for example, due to a previous call of replacementObjectForKeyedArchiver:
// to that object). This method returns the result of
// [self replacementObjectForArchiver:nil] by default, NOT
// -replacementObjectForCoder: as might be expected. This is a concession
// to source compatibility.
public class func classFallbacksForKeyedArchiver() -> [String] {
return []
}
public class func classForKeyedUnarchiver() -> AnyClass {
return self
}
public var hashValue: Int {
return hash
}
}
public func ==(lhs: NSObject, rhs: NSObject) -> Bool {
return lhs.isEqual(rhs)
}
extension NSObject : CustomDebugStringConvertible {
}
extension NSObject : CustomStringConvertible {
}