This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// objc | |
@interface ObjcClass<T> : NSObject | |
@property(nonnull) T property; | |
@end | |
// swift | |
protocol ContainGenericType { | |
associatedtype T | |
var property: T { get } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Obj2 { | |
var tag: String | |
init(_ tag: String) { | |
self.tag = tag | |
} | |
func defer1() { | |
print(tag, #function, "start", CFGetRetainCount(self)) | |
defer { print(tag, #function, "defer", CFGetRetainCount(self)) } | |
print(tag, #function, "end", CFGetRetainCount(self)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do { | |
let obj2 = NSObject() | |
CFGetRetainCount(obj2) // 2 | |
let test = { CFGetRetainCount(obj2) } | |
CFGetRetainCount(obj2) // 3 | |
test() // 4 | |
CFGetRetainCount(obj2) // 3 | |
} |