Skip to content

Instantly share code, notes, and snippets.

@jpmcglone
Created April 22, 2019 14:55
Show Gist options
  • Save jpmcglone/1734135ca22913076af77c6a87b6cc22 to your computer and use it in GitHub Desktop.
Save jpmcglone/1734135ca22913076af77c6a87b6cc22 to your computer and use it in GitHub Desktop.
import Foundation
class Weak<T> {
private weak var _value: AnyObject?
var value: T? { return _value as? T }
init(_ value: T) {
_value = value as AnyObject
}
}
extension Array {
mutating func cleanup<T>() where Element == Weak<T> {
self = self.filter { $0.value != nil }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment