I have a struct Person estende OptionSetType. Più tardi nel codice, come posso utilizzare un'istruzione switch per verificare se un'istanza di Person è più di un valore?Passa a corrispondere a più casi da OptionSetType
Grazie
struct Person: OptionSetType {
let rawValue: Int
init(rawValue: Int){
self.rawValue = rawValue
}
static let boy = Person(rawValue: 1 << 0)
static let young = Person(rawValue: 1 << 1)
static let smart = Person(rawValue: 1 << 2)
static let strong = Person(rawValue: 1 << 3)
}
//later declared
var him: Person!
//later initialised
him = [.boy, .young]
//now test using a switch block
Switch (him) {
case .boy & .young // <----- How do you get this to work?
}
Come ci si prova per lui == giovane e forte?
Come testarlo contiene giovani e ragazzi?
La linea "se lo == youngBoy" dà l'errore Uso di non risolti Identifier "youngBoy", ho aggiornato la mia domanda per includere più opzioni. Grazie per l'eccellente spiegazione :) –
'youngBoy' è dichiarato nel primo snippet di codice del mio post. – rickster