Je dois obtenir la classe comme réponse après le changement de casse dans swift, j'ai des problèmes de compilation avec cette fonction.besoin d'obtenir une classe après le commutateur cas dans swift?
func getOptClass(signal : String) -> AnyClass{
var result = AnyClass
switch(signal){
case "IntRR":
result = BPMClass.self
break
case "BPM":
result = BPMClass.self
break
case "ECG":
result = ECGClass.self
break
default:
result = nil
break
}
return result
}
Voici l'erreur:
Swift Compiler Error Group
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:68:18: Expected member name or constructor call after type name
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:68:18: Use '.self' to reference the type object
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:72:22: Cannot assign value of type 'BPMClass.Type' to type 'AnyClass.Protocol' (aka 'AnyObject.Type.Protocol')
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:76:22: Cannot assign value of type 'BPMClass.Type' to type 'AnyClass.Protocol' (aka 'AnyObject.Type.Protocol')
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:80:22: Cannot assign value of type 'ECGClass.Type' to type 'AnyClass.Protocol' (aka 'AnyObject.Type.Protocol')
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:84:22: Nil cannot be assigned to type 'AnyClass.Protocol' (aka 'AnyObject.Type.Protocol')
/Users/gab/Desktop/desktopAppli/mobileApp/mobileApp/GlobalCstes.swift:87:12: Cannot convert return expression of type 'AnyClass.Protocol' (aka 'AnyObject.Type.Protocol') to return type 'AnyClass' (aka 'AnyObject.Type')
Pouvez-vous inclure l'erreur que vous obtenez? Les gens seront en mesure d'aider beaucoup plus si vous avez cette information. –