forked from swiftlang/swift-corelibs-foundation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNSObject.swift
140 lines (104 loc) · 2.8 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
// 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 {
get {
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 {
// 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 {
get {
return ObjectIdentifier(self).hashValue
}
}
public func `self`() -> Self {
return self
}
public func isProxy() -> Bool {
return false
}
public var description: String {
get {
return "<\(self.dynamicType): \(unsafeAddressOf(self))>"
}
}
public var debugDescription: String {
get {
return description
}
}
internal var _cfTypeID: CFTypeID {
return 0
}
}
extension NSObject : Equatable, Hashable {
public var hashValue: Int {
get {
return hash
}
}
}
public func ==(lhs: NSObject, rhs: NSObject) -> Bool {
return lhs.isEqual(rhs)
}
extension NSObject : CustomDebugStringConvertible {
}
extension NSObject : CustomStringConvertible {
}