0

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?

5
  • At least you have to declare a return type in the 3 functions at the bottom as they clearly return something. Commented Nov 21, 2015 at 15:45
  • 1
    1. What is this? 2. Your returning methods are missing a return signature. 3. You're assigning methods, not calling them. Commented Nov 21, 2015 at 15:46
  • 1
    @EricD. maybe it's JavaSwift ;-) Commented Nov 21, 2015 at 15:48
  • Yes, it is JavaSwift, and I"m working on knowing how to simply use Swift. Commented Nov 21, 2015 at 16:41
  • @EricD. What does an appropriate return signature look like? I looked around and couldn't track it down. Commented Nov 21, 2015 at 16:45

2 Answers 2

1

You are trying to assign a function self.restrictToAngle to getAngle, a variable of type [AnyObject]! (i.e. an array).

Sign up to request clarification or add additional context in comments.

Comments

1

As @EricD and others pointed out, there are quite a lot of issues. For understanding how function definition, calls & return type work in swift, check this Apple documentation page.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.