Reputation: 1199
I'm using a tutorial for MapKit http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial
It is taught using Swift 1.2 and Xcode 6.3. In my Project, however, I am getting some errors. The code below is directly from the tutorial at
I've broken out the relevant lines in the code below labeled as (A) and (B). The respective errors are as follows:
(A) `Missing argument label 'rawValue.' in call - Adding the rawValue argument label does not help
(B) Extra argument 'error' in call - Removing the 'error' argument does not help
import UIKit
import MapKit
class ViewController: UIViewController {
@IBOutlet weak var mapView: MKMapView!
var artworks = [Artwork]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let initialLocation = CLLocation(latitude: 21.282778, longitude: -157.829444)
centerLocationOnMap(initialLocation)
mapView.delegate = self
// show artwork on map
let artwork = Artwork(title: "King David Kalakaua",
locationName: "Waikiki Gateway Park",
discipline: "Sculpture",
coordinate: CLLocationCoordinate2D(latitude: 21.283921, longitude: -157.831661)
)
mapView.addAnnotation(artwork)
}
let regionRadius: CLLocationDistance = 1000;
func centerLocationOnMap(location: CLLocation) {
let regionCoordinates = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius * 2.0, regionRadius * 2.0)
mapView.setRegion(regionCoordinates, animated: true)
}
func loadInitialData() {
let fileName = NSBundle.mainBundle().pathForResource("PublicArt", ofType: "json");
var readError : NSError?
(A)
var data: NSData = NSData(contentsOfFile: fileName!, options: NSDataReadingOptions(0), error: &readError)!
var error: NSError?
(B)
let jsonObject: AnyObject! = NSJSONSerialization.JSONObjectWithData(data,
options: NSJSONReadingOptions(0), error: &error)
.
if let jsonObject = jsonObject as? [String: AnyObject] where error == nil,
let jsonData = JSONValue.fromObject(jsonObject)?["data"]?.array {
for artworkJSON in jsonData {
if let artworkJSON = artworkJSON.array,
// 5
artwork = Artwork.fromJSON(artworkJSON) {
artworks.append(artwork)
}
}
}
}
Upvotes: 0
Views: 139
Reputation: 274
The methods signature change in swift 2 You can look at NSData and NSJSONSerialization apple documentations
You must remove the errors parameters and use try before calling the functions
And for options you can put [] -> no options
try NSData(contentsOfFile: fileName!, options: [])
try NSJSONSerialization.
see Correct handling of NSJSONSerialization (try catch) in Swift (2.0)?
And you must to catch the errors with a do { code } catch { }, or just for test purpose use try!
Upvotes: 1