swift - Type does not have a member -


i'm playing around swift playground working on new class. reason keep getting error class "does not have member type" name of constant defined 3 lines earlier. here code:

import foundation class datamodel {     let mycalendar = nscalendar.autoupdatingcurrentcalendar()      var mydata = [nsdate : float]()     let  = nsdate()     let components = mycalendar.components(.calendarunityear | .calendarunitmonth, fromdate: now) } 

xcode beta6 keeps give me error on second last line, saying "datamodel.type not have member named 'mycalendar'

though don't think should make difference, have tried defining mycalendar var.

you cannot initialize instance class property referencing instance property of same class, because it's not guaranteed in order initialized - , swift prohibits that, hence (misleading) compiler error.

you have move initialization in constructor follows:

let components: nsdatecomponents  init() {     self.components = mycalendar.components(.calendarunityear | .calendarunitmonth, fromdate: now) } 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -