2
这是我目前如何声明我的变量。我通常会在需要时声明它们。宣布这些变量的适当位置在哪里?
//Instantiate Map
let map = MKMapView()
map.frame = CGRect(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.height)
//Edit Properties
map.mapType = MKMapType.standard
map.isZoomEnabled = true
map.isScrollEnabled = true
//Center map in view
map.center = view.center
//Get coordinates from App Delegate
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let coordinates = appDelegate.coordinates
//Set map location
let radius = 1000.0
let region = MKCoordinateRegionMakeWithDistance(coordinates, radius * 2.0, radius * 2.0)
map.setRegion(region, animated: true)
在顶部声明这些变量是否更好?如果我在使用它们时宣布它们,我发现它更容易阅读。
我会删除这些评论。他们不会添加任何通过阅读代码而不明显的新信息 – Alexander