Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Ben Holland
PLUS
Ben Holland
Courses Plus Student 4,062 Points

Im trying to use SwiftLocation and Moya and i keep on getting this an Underlying() error when trying to get location

I'm trying to get the latitude and longitude to use in the forecast.io weather API and I keep on getting this error.

Underlying(Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}) And here is my code:

import Foundation import Moya import SwiftLocation import CoreLocation

//Important Data private let apiKey = "e7ad7026728abc35fce4c397fd5405d6"

var lat: String = "" var long: String = "" var request = LocationManager.shared.observeLocations(.Block, frequency: .OneShot, onSuccess: {location in lat = String(location.coordinate.latitude) long = String(location.coordinate.longitude)

}, onError: {_ in })

let ForecastProvider = MoyaProvider<ForecastIO>()

public enum ForecastIO { case getWeatherdata }

extension ForecastIO: TargetType {

public var baseURL: NSURL {
    return NSURL(string: "https://api.forecast.io/forecast/\(apiKey)/\(lat),\(long)")!
}

public var path: String {
    switch self {
    case .getWeatherdata:
        return "/"
    }
}

public var method: Moya.Method {
    switch self {
    case .getWeatherdata:
        return .GET
    }
}

public var parameters: [String: AnyObject]? {
    switch self {
    case .getWeatherdata:
        return ["units": "si"]
    }
}

public var sampleData: NSData {
    switch self {
    case .getWeatherdata:
        let data = NSData()
        return data
    }
}

}