Las enumeraciones en Swift son mucho más ponderosas que en Objective-C. Como lo estructura Swift, pueden tener métodos y se pasan como valores:
enum MobileDevice : String{ case iPhone = "iPhone", Android = "Android", WP8 = "Windows Phone8", BB = "BlackBerry" func name() -> String { return self.toRaw() }}let m = MobileDevice.Androidprint(m.name()) // "Android"
A diferencia de Objective-C, las enumeraciones Swift pueden asignar cadenas, caracteres o flotantes como valores para cada miembro, aparte de números enteros. El método conveniente toRaw()
regresa el valor asignado a cada miembro.
Las enumeraciones también se pueden parametrizar:
enum Location{ case Address(street:String, city:String) case LatLon(lat:Float, lon:Float) func description() -> String { switch self { case let .Address(street, city): return street + ", " + city case let .LatLon(lat, lon): return "(\(lat), \(lon))" } }}let loc1 = Location.Address(street: "2070 Fell St", city: "San Francisco")let loc2 = Location.LatLon(lat: 23.117, lon: 45.899)print(loc1.description()) // "2070 Fell St, San Francisco"print(loc2.description()) // "(23.117, 45.988)"
Enviado por khadim hussain 04/11/2019
http://www.aiobjectives.com worldwide.Technology, especially artificial intelligence has made our lives really easy. From the general apps to Alexa in our houses technology has seeped in even without us realizing when this happened. Here is a quick view of future where AI will have significant role in each phase of our life.Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. ... These apps are licensed by manufacturers of Android devices certified under imposed by Google
Enviado por khadim hussain 04/11/2019
http://www.aiobjectives.com worldwide.Technology, especially artificial intelligence has made our lives really easy. From the general apps to Alexa in our houses technology has seeped in even without us realizing when this happened. Here is a quick view of future where AI will have significant role in each phase of our life.Android is a mobile operating system based on a modified version of the Linux kernel and other open source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. ... These apps are licensed by manufacturers of Android devices certified under imposed by Google