How do I access an enum from another class in Swift? -


say have following example:

class classone {     enum color {         case red         case blue     }      func givecolor() -> color {         return .red     } }  class classtwo {     let classone = classone()     var color: color = classone.givecolor() } 

the compiler complains doesn't know color in classtwo. how best handle this?

your color enumeration nested type -- you'll access classone.color. moreover, can't assign 1 property in declaration that. leave unassigned , in init():

class classone {     enum color {         case red         case blue     }      func givecolor() -> color {         return .red     } }  class classtwo {     let classone = classone()     var color: classone.color      init() {         self.color = self.classone.givecolor()     } } 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -

jquery - Keeping Kendo Datepicker in min/max range -