我正在使用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)
}
}
}
}发布于 2016-01-21 20:17:07
您可以查看NSData和NSJSONSerialization苹果文档中的方法签名更改
在调用函数之前,必须删除错误参数并使用try。
对于选项,您可以将[] ->无选项
try NSData(contentsOfFile: fileName!, options: [])
try NSJSONSerialization.请参阅Correct handling of NSJSONSerialization (try catch) in Swift (2.0)?
并且您必须使用do { And代码} catch {And}捕获错误,或者只是为了测试目的使用try!
https://stackoverflow.com/questions/34933212
复制相似问题