I'm about to write a small protocol with a default extension which can decide if all parameters are set. (Swift 2.2)
My idea was to use the Mirror type and get all the child elements of the given type, than iterate through them. Like this:
var isComplete: Bool {
get {
return Mirror(reflecting: self).children.reduce(true) { return $0 && $1.value != nil } // <- Error, because value is not Optional
}
}
The problem is in the type of the child, which is:
typealias Child = (label: String?, value: Any)
So i can't just check if it is nil, because it is not Optional. If is use print($1.value)
it prints out nil, so there must be some pointer magic behind that.
Any ideas how to check the memory address of that. Or maybe some easier way to implement this functionality
Aucun commentaire:
Enregistrer un commentaire