如何用swift使用CoreLocation?
我试过用我的Swift应用程序使用CoreLocation,但没有运气。 我有以下令人难以置信的简单的代码:
(我链接了CoreLocation库。)
import UIKit import CoreLocation @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var locationManager: CLLocationManager = CLLocationManager() locationManager.delegate = self
在最后一行,我得到错误“预期的声明”。
我究竟做错了什么?
提前致谢!
下面的代码locationManager.delegate = self
是一个语句。 您需要在AppDelegate方法之一中执行它。 例如:
class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate { var window: UIWindow? var locationManager: CLLocationManager = CLLocationManager() func application(application :UIApplication, didFinishLaunchingWithOptions launchOptions:NSDictionary>) -> Bool { locationManager.delegate = self } }
- 在Swift中解码一个string
- 在Swift 2中使用'kGMSMarkerAnimationPop'错误
- 在Swift中NSlogging / println SQLite数据库文件的位置
- Swift 3 JSON NSFastEnumerationIterator没有下标成员
- 当我按下应用程序中的button时,如何打开Google地图?
- 在Swift中使用以编程方式创build的UITableViewCell子类
- 例外情况:在使用之前,Google Maps SDK for iOS必须通过进行初始化
- 将Swiftstring转换为数组
- expression式types“NSMutableArray!” 没有更多的上下文是模棱两可的