Hi
I am an absolute beginner in Swift.
A friend helped me setup a test app that displays a map using Map Kit. This is the part that creates the actually map:
I tried to set mapType to hybridFlyover in different ways, like this for instance:
But everything returns an error...
Can any one help me, please?
Where can I find an explanation of swift syntax?
I am an absolute beginner in Swift.
A friend helped me setup a test app that displays a map using Map Kit. This is the part that creates the actually map:
Code Block class KMLViewerViewController: UIViewController, MKMapViewDelegate { let map = MKMapView() // etc. ... }
I tried to set mapType to hybridFlyover in different ways, like this for instance:
Code Block let map = MKMapView(.mapType = .hybridFlyover )
But everything returns an error...
Can any one help me, please?
Where can I find an explanation of swift syntax?
There is no conenience init for MKMapView that let you declare the mapType as an init parameter.
You should thus write:
Note that
map.mapType = .hybridFlyover
must be inside a func ; it cannot be at the class level just after etc…
Unless you declare it as a computed var:
You should thus write:
Code Block import MapKit class KMLViewerViewController: UIViewController, MKMapViewDelegate { let map = MKMapView() // etc. ... override func viewDidLoad() { super.viewDidLoad() map.mapType = .hybridFlyover } }
Note that
map.mapType = .hybridFlyover
must be inside a func ; it cannot be at the class level just after etc…
Unless you declare it as a computed var:
Code Block var map : MKMapView { let aMap = MKMapView() aMap.mapType = .hybridFlyover return aMap }