Skip to content

Instantly share code, notes, and snippets.

@ezura
ezura / retain.swift
Created April 22, 2017 05:04
strong var で参照が 2 増える件
do {
let obj2 = NSObject()
CFGetRetainCount(obj2) // 2
let test = { CFGetRetainCount(obj2) }
CFGetRetainCount(obj2) // 3
test() // 4
CFGetRetainCount(obj2) // 3
}
@ezura
ezura / obj.swift
Created April 22, 2017 02:44
retain count 調べ
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))
@ezura
ezura / CodePiece.swift
Created November 27, 2016 07:21
Segmentation fault: 11 (´・ω・`)? #swift #CodePiece
// objc
@interface ObjcClass<T> : NSObject
@property(nonnull) T property;
@end
// swift
protocol ContainGenericType {
associatedtype T
var property: T { get }
}