Created
May 14, 2017 08:18
-
-
Save orxelm/e236c10f00d8dd11be7da760abe7ffb1 to your computer and use it in GitHub Desktop.
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
extension NSPointerArray { | |
func addObject(_ object: AnyObject?) { | |
guard let strongObject = object else { return } | |
let pointer = Unmanaged.passUnretained(strongObject).toOpaque() | |
addPointer(pointer) | |
} | |
func insertObject(_ object: AnyObject?, at index: Int) { | |
guard index < count, let strongObject = object else { return } | |
let pointer = Unmanaged.passUnretained(strongObject).toOpaque() | |
insertPointer(pointer, at: index) | |
} | |
func replaceObject(at index: Int, withObject object: AnyObject?) { | |
guard index < count, let strongObject = object else { return } | |
let pointer = Unmanaged.passUnretained(strongObject).toOpaque() | |
replacePointer(at: index, withPointer: pointer) | |
} | |
func object(at index: Int) -> AnyObject? { | |
guard index < count, let pointer = self.pointer(at: index) else { return nil } | |
return Unmanaged<AnyObject>.fromOpaque(pointer).takeUnretainedValue() | |
} | |
func removeObject(at index: Int) { | |
guard index < count else { return } | |
removePointer(at: index) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment