小编Spt*_*bo 的帖子

无法快速获取当前纬度和经度的城市名称

我正在尝试使用CLGeocoder().reverseGeocodeLocation.

它给了我国家名称、街道名称、州和许多其他东西,但没有城市。我的代码有什么问题吗?

这是我的代码:

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations[0]
    CLGeocoder().reverseGeocodeLocation(location) { (placeMark, error) in
        if error != nil{
            print("Some errors: \(String(describing: error?.localizedDescription))")
        }else{
            if let place = placeMark?[0]{
                print("country: \(place.administrativeArea)")

                self.lblCurrentLocation.text = place.administrativeArea
            }
        }
    } }
Run Code Online (Sandbox Code Playgroud)

我也使用下面的代码。但对我不起作用。这是另一种方式。

        let geoCoder = CLGeocoder()
    let location = CLLocation(latitude: (self.locationManager.location?.coordinate.latitude)!, longitude: (self.locationManager.location?.coordinate.longitude)!)
    geoCoder.reverseGeocodeLocation(location, completionHandler: { (placemarks, error) -> Void in

        // Place details
        var placeMark: CLPlacemark!
        placeMark = placemarks?[0]

        // Address dictionary
        print(placeMark.addressDictionary …
Run Code Online (Sandbox Code Playgroud)

ios currentlocation clgeocoder swift

6
推荐指数
1
解决办法
4508
查看次数

更新核心数据 swift 4 上的对象

我在核心数据实体中有几项作业,其 jobId 为 -1。我需要获取所有这些项目并通过在我的对象中通过 updateMyJobs 方法传递的正确 id 更新 jobId。我还没有提取 NSManagedObject 类来处理核心数据(即 - 我已经将实体检查为类定义)

这是我的代码:

func updateMyJobs(jobId: Int){
    managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
    let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "DBJobsNearBy")
    fetchRequest.predicate = NSPredicate(format: "jobId = '-1'")
    let result = try? managedObjectContext.fetch(fetchRequest)
    let resultData = result as! [DBJobsNearBy]
    for object in resultData {
        print(object.jobId)
        if object.jobId == -1 {
            object.setValue("\(jobId)", forKey: "jobId")
        }
    }
    do {
        try managedObjectContext.save()
        print("saved!")
    } catch let error as NSError  {
        print("Could not save \(error), \(error.userInfo)")
    }
}
Run Code Online (Sandbox Code Playgroud)

我传递了一些整数值并调用上面的方法来更新这样的项目。 …

core-data ios objectid swift

2
推荐指数
1
解决办法
1万
查看次数

可选类型“Any?”的值 没有打开

我正在尝试实现 facebook 登录。从https://www.youtube.com/watch?v=MNfrBdyEvmY学习,但有上述类型的错误。这是我的代码:

let parameters = ["fields": "email, first_name, last_name, picture.type(large)"]
    FBSDKGraphRequest(graphPath: "me", parameters: parameters).start { (connection, result, error) in
        if error != nil{
            print(error ?? "error")
            return
        }
        if let email = result["email"] as? String{
            print("Email: \(email)")
        }
    }
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明 请帮我解决一下这个。谢谢

optional any facebook-login swift

1
推荐指数
1
解决办法
5381
查看次数