【发布时间】:2016-01-31 21:05:10
【问题描述】:
假设我有一个类let geocoder = CLGeocoder() 的实例。
我现在可以调用geocodeAddressString,这是CLGeocoder 类的一个方法:
geocoder.geocodeAddressString(myObject["Location"] as! String, completionHandler: {
(placemarks, error) -> Void in
...
}
但是,为什么我不能直接执行以下操作?
// I haven't instantiated the `CLGeocoder` class this time
CLGeocoder.geocoder.geocodeAddressString(myObject["Location"] as! String, completionHandler: { (placemarks, error) -> Void in
...
})
例如,我可以这样做:
// I don't instantiate the UIView class here
UIView.animateWithDuration(0.4, animations: {
() in
...
}
什么时候必须实例化一个类,什么时候不应该?
【问题讨论】:
-
这是非常基本的面向对象编程。只需查看文档并了解它是如何实现的。更多阅读,或许可以看到:What is the difference between class and instance methods?
标签: swift core-location