Swift - Getter and Setter for Computed Properties as String type -


hello im new swift development no objective-c background, although have strong fundamentals in java, swift has stiff learning curve me, i'll go straight question, ill post code first

 class vehicle {      var gear : string {          {             return self.gear         }          set {             self.gear = newvalue         }     } }  var vehicle = vehicle() vehicle.gear = "adasd" 

im having compiler error saying

./run-swift: line 18: 30295 segmentation fault: 11  gtimeout -k $timeout_kill_after $timeout_duration $swift_compiler -target $target -sdk $sdk $optimization_level $input_file -o $output_file 

i realy dont understand why simple code not compile using string type, if change variable declaration int type , assign value property have no problems @ all.

self.gear here calls getter gear calls self.gear. you've created infinite loop. have similar situation setter. don't need implement get , set if want store property.

final class vehicle {     var gear : string }  var vehicle = vehicle() vehicle.gear = "adasd" 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

java - Copying object fields -

c++ - Clear the memory after returning a vector in a function -