I am presently working on a first Swift project, and making a newcomer's errors.
The class I am working on is meant to export three of its methods to global variables:
var getAngle:[AnyObject]!; var getHours:[AnyObject]! var getMinutes:[AnyObject]!; class GpsViewController : UIViewController { // .... required init() { // super.init(); formatter.dateFormat = "yyyy-MM-dd"; parser.locale = NSLocale(localeIdentifier: "en_US_POSIX"); parser.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ"; getAngle = self.restrictToAngle; getHours = self.restrictToHours; getMinutes = self.restrictToMinutes; } func getHourAndAngle() { // Hour hand angle in radians from 12 o'clock position, clockwise. var now = NSDate(); var today = now; var todayFormatted = this.formatter(today); var yesterday = today.dateWithTimeIntervalSinceNow(-24 * 60 * 60); var yesterdayFormatted = this.formatter(yesterday); var tomorrow = today.dateWithTimeIntervalSinceNow(24 * 60 * 60); var tomorrowFormatted = this.formatter(tomorrow); var yesterdaySunset = this.presentLocation[yesterdayFormatted]["sunset"]; var todaySunrise = this.presentLocation[todayFormatted]["sunrise"]; var todaySunset = this.presentLocation[todayFormatted]["sunset"]; var tomorrowSunrise = this.presentLocation[tomorrowFormatted]["sunrise"]; var duration = 0.0; var position = 0.0; var startingHour = 18; var offset = 0.0; if now.isLessThanDate(todaySunrise) { length = todaySunrise.timeIntervalSinceDate(yesterdaySunset); position = now.timeIntervalSinceDate(yesterdaySunset); offset = -0.5; } else if now.isLessThanDate(todaySunset) { length = todaySunset.timeIntervalSinceDate(todaySunrise); position = now.timeIntervalSinceDate(todaySunrise); offset = 0.5; startingHour = 6; } else { length = tomorrowSunrise.timeIntervalSinceDate(todaySunset); position = now.timeIntervalSinceDate(todaySunset); offset = 1.5; } var proportion = position / length; var angle = M_PI + (2 * M_PI * (proportion + offset)); var hours = floor(24 * 60 * 60 * ((1 + proportion + offset) % 1.0) / (60 * 60)); var minutes = floor(24 * 60 * 60 * (1 + proportion + offset) % 60 * 60); return ["angle": angle, "hour": hour, "minutes": minutes]; } func restrictToHours() { return getHoursMinutesAngle["hour"]; } func restrictToAngle() { return getHoursMinutesAngle["angle"]; } func restrictToMinutes() { return getHoursMinutesAngle["minutes"]; } // ... } I'm getting several errors, including in init()'s assignment of getAngle, "Value of type GpsViewController has no member restrictToAngle".
Could you tell me what the n00b errors are here?
this? 2. Your returning methods are missing a return signature. 3. You're assigning methods, not calling them.