-
Notifications
You must be signed in to change notification settings - Fork 9
/
_TestObject.swift
70 lines (57 loc) · 1.21 KB
/
_TestObject.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
//
// _TestObject.swift
// SwizzleTests
//
// Created by Yasuhiro Inami on 2014/09/14.
// Copyright (c) 2014年 Yasuhiro Inami. All rights reserved.
//
import Foundation
extension NSObject
{
@objc func hello() -> String
{
return "NSObject-hello"
}
@objc func bye() -> String
{
return "NSObject-bye"
}
@objc class func hello() -> String
{
return "NSObject+hello"
}
@objc class func bye() -> String
{
return "NSObject+bye"
}
}
class MyObject: NSObject
{
// NOTE: dynamic is required for method-swizzling
@objc dynamic func bonjour() -> String
{
return "MyObject-bonjour"
}
@objc dynamic class func bonjour() -> String
{
return "MyObject+bonjour"
}
let deinitClosure: (() -> Void)?
init(deinitClosure: (() -> Void)? = nil)
{
self.deinitClosure = deinitClosure
super.init()
print("[init] \(self)")
}
deinit
{
print("[deinit] \(self)")
self.deinitClosure?()
}
// WARNING: swizzling `dealloc` in Swift won't work
@objc dynamic func _swift_dealloc()
{
print("_swift_dealloc")
self._swift_dealloc()
}
}