我用Swift 2将Xcode 6更新为Xcode 7 beta.我收到此错误,我无法找到解决方法,请帮助我.谢谢.这是我的代码:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [AnyObject]) {
let location = locations.last as! CLLocation
let center = CLLocationCoordinate2D(latitude: location.coordinate.latitude, longitude: location.coordinate.longitude)
let region = MKCoordinateRegion(center: center, span: MKCoordinateSpan(latitudeDelta: 0.01, longitudeDelta: 0.01))
self.map.setRegion(region, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
Objective-C method 'locationManager:didUpdateLocations:' provided by method 'locationManager(_:didUpdateLocations:)' conflicts with optional requirement method 'locationManager(_:didUpdateLocations:)' in protocol 'CLLocationManagerDelegate'
昨天我更新到El Capitan beta 2和Xcode 7 - beta是强制性的.所以我将我的应用程序更新为Swift 2,并且新的错误出现在json字符串中.这是我的代码:
let jsonData:NSDictionary = NSJSONSerialization.JSONObjectWithData(urlData!, options:NSJSONReadingOptions.MutableContainers ) as! NSDictionary
这是错误: Call can throw , but it is not marked with 'try' and the error is not handled
嗨我用Xcode 7将我的项目从Swift更新到Swift2,我得到了这个CoreData错误:
Extra argument 'error' in call
Run Code Online (Sandbox Code Playgroud)
在这一行
if coordinator!.addPersistentStoreWithType(NSSQLiteStoreType, configuration: nil, URL: url, options: nil, error: &error) == nil {
Run Code Online (Sandbox Code Playgroud)
编辑
这是我的代码:
lazy var persistentStoreCoordinator: NSPersistentStoreCoordinator? = {
// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail.
// Create the coordinator and store
var …Run Code Online (Sandbox Code Playgroud) 我正在使用Xcode 7将我的应用程序更新为Swift 2.这是我的ViewController viewDidLoad的代码.
override func viewDidLoad() {
super.viewDidLoad()
// Get an instance of the AVCaptureDevice class to initialize a device object and provide the video
// as the media type parameter.
let captureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
// Get an instance of the AVCaptureDeviceInput class using the previous device object.
var error:NSError?
let input: AnyObject! = AVCaptureDeviceInput.deviceInputWithDevice(captureDevice, error: &error)
if (error != nil) {
// If any error occurs, simply log the description of it and don't continue any more.
print("\(error?.localizedDescription)") …Run Code Online (Sandbox Code Playgroud) 嗨我的应用程序第一次运行时崩溃了.这是我的代码:
let State = save.stringForKey("StateSave")
let City = save.stringForKey("CitySave")
let Vehicle = save.stringForKey("ModelNumberSave")
let ExtensionPeriod = save.stringForKey("ExtensionPeriodChoosed")
let Location = "Location"
if ExtensionPeriod == nil {
let name = ""
var FieldChoosed: Void = save.setObject(name, forKey: "ExtensionPeriodChoosed")
save.synchronize()
}
save.synchronize()
var DetailNames = ["\(State!)","\(City!)","\(Location)","\(Vehicle!)","\(ExtensionPeriod!)"]
Run Code Online (Sandbox Code Playgroud)
我得到了nil这条线:
var DetailNames = ["(State!)","(City!)","(Location)","(Vehicle!)","(ExtensionPeriod!)"]
实际上ExtensionPeriod是nil.但我不明白为什么...... ExtensionPeriod是nil,但是我写的代码ExtensionPeriod会像""所以不是nil.请帮我.