How to create a custom getter method in swift 4
问题 I am trying to create a custom setter method for my property. Below is my code. I am getting a waring Attempting to access 'myProperty' within its own getter var myProperty:String{ get { if CONDITION1 { return CONDITION1_STRING }else if CONDITION2 { return CONDITION2_STRING }else{ return myProperty } } set{ } } What is wrong in my code. can any body help to fix this. 回答1: Create a backing ivar and add a custom setter: private _myProperty: String var myProperty: String { get { if CONDITION1 {