I have tried to do an extension to NSDate. What I wanted is a flag indicating if the NSDate has to be removed later
So I have tried this in playground
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
extension NSDate {
private struct RemovalInformation {
static var removed: Bool = false
}
var removed: Bool {
get {
return (objc_getAssociatedObject(self, &RemovalInformation.removed) as! Bool)
}
set(newValue) {
objc_setAssociatedObject(self, &RemovalInformation.removed, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN)
}
}
}
let date = NSDate()
print( "The Date is: \(date)")
if(date.removed == true) {
print ("removed")
}
But line if(date.removed == true)
produces an error I have no clue how to deal with: "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)"