Ich habe versucht, eine Erweiterung für NSDate zu erstellen. Was ich wollte, ein Flag, das anzeigt, ob die NSDate späterSwift Extension-Ausnahme Die Ausführung wurde unterbrochen, Grund: EXC_BAD_INSTRUCTION (Code = EXC_I386_INVOP, Subcode = 0x0)
entfernt werden müssen, damit habe ich versucht, dies in Spielplatz
//: 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")
}
Aber Linie if(date.removed == true)
erzeugt einen Fehler, ich habe keine Ahnung, wie zu behandeln: „EXC_BAD_INSTRUCTION (code = EXC_I386_INVOP, Subcode = 0x0)“
Danke Kumpel, du hast meinen Tag gemacht. Ich dachte, es könnte eine winzige Sache sein, aber der ganze Ausdruck war mir zu neu, als ich es vollständig verstehen konnte. Mit dem, was Sie erwähnt haben, verstehe ich die ganze Sache ein bisschen mehr. Danke, Mann. –