【发布时间】:2016-01-21 20:01:37
【问题描述】:
我正在使用 MapKit 的教程http://www.raywenderlich.com/90971/introduction-mapkit-swift-tutorial
使用 Swift 1.2 和 Xcode 6.3 进行教学。但是,在我的项目中,我遇到了一些错误。下面的代码直接来自
的教程我在下面标记为 (A) 和 (B) 的代码中拆分了相关行。各自的错误如下:
(A) `缺少参数标签“rawValue”。在调用中 - 添加 rawValue 参数标签没有帮助
(B) 调用中的额外参数“错误” - 删除“错误”参数没有帮助
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)
}
}
}
}
【问题讨论】:
标签: swift swift2 mapkit xcode7