ios - Is there a way to create a custom class that I can mutate? -


currently, i've made custom class called songnames. here's code it:

  import foundation  class songattributes { private var _songtitle: string! private var _songurl: string!  var songtitle: string {     return _songtitle }  init(songtitle: string, songurl: string) {     _songurl = songurl     _songtitle = songtitle  } var songurl: string {     return _songurl }  } 

i have no problem setting values class. instance, might write:

var songattribute = songattributes(songtitle: "that's like", url: "some url") 

however, if try change properties of variable created, saying:

songattribute.songtitle = "locked out of heaven" 

i message: "error: songtitle property"

that being said, there way mess songname class these properties can changed, , not get-only?

if want properties settable there no need dance private properties. also, properties should not implicitly unwrapped, since setting them in initialiser.

import foundation  class songattributes {     var songtitle: string     var songurl: string      init(songtitle: string, songurl: string) {         self.songurl = songurl         self.songtitle = songtitle      } } 

note that, convention, class , struct names should start capital letter.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -