How to get Location user with CLLocationManager in swift?

前端 未结 7 2097
鱼传尺愫
鱼传尺愫 2020-11-29 04:49

I have this code on my view controller but this not working:

  import UIKit
  import CoreLocation

  class ViewController: UIViewController, CLLocationManag         


        
7条回答
  •  忘掉有多难
    2020-11-29 05:15

    You need to have init functions.

    Override init(coder:) and init(nibName: bundle:) and add any custom init you want.

    Because you have said that location is not optional, you must initialize it before your super init calls in ALL of your init functions.

    func init() {
    ...
    location = CLLocationManager()
    // either set delegate and other stuff here or in viewDidLoad
    super.init(nibName:nil, bundle:nil)
    // other initialization below
    
    }
    

提交回复
热议问题