小编Bar*_*mre的帖子

Swift 5.0:不推荐使用'withUnsafeBytes':使用`withUnsafeBytes <R>(...)

我以前在Swift 4.2中使用以下代码来生成ID:

public static func generateId() throws -> UInt32 {
    let data: Data = try random(bytes: 4)
    let value: UInt32 = data.withUnsafeBytes { $0.pointee } // deprecated warning!
    return value // + some other stuff 
}
Run Code Online (Sandbox Code Playgroud)

withUnsafeBytes在Swift 5.0上已弃用。我该如何解决?

unsafe-pointers deprecated swift

35
推荐指数
3
解决办法
8882
查看次数

为什么LocationManager多次调用startUpdatingLocation?

为什么位置管理员startUpdatingLocation不止一次打电话?有时它会调用一次,有时它会调用三次.我不知道为什么; 也许你可以帮助我.我有来自GitHub的代码.

import UIKit
import CoreLocation

class ViewController: UIViewController, CLLocationManagerDelegate
{

    let locationManager = CLLocationManager()

    override func viewDidLoad()
    {
        super.viewDidLoad()

        self.locationManager.delegate = self
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
        self.locationManager.requestWhenInUseAuthorization()
        self.locationManager.startUpdatingLocation()
    }

    override func didReceiveMemoryWarning()
    {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        CLGeocoder().reverseGeocodeLocation(manager.location!, completionHandler: {(placemarks, error) -> Void in

            if (error != nil)
            {
                print("Error: " + error!.localizedDescription)
                return
            }

            if placemarks!.count > 0 {
                if let pm = …
Run Code Online (Sandbox Code Playgroud)

location locationmanager swift

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