10

I'm trying to create a custom CLPlacemark using the Intents framework. I'm importing 'Intents' at files beginning.

I found this solution:

let waypointLocation = CLLocation(latitude: 50.00, longitude: 8.00)
let waypointName = "Some Name"

let w1 = CLPlacemark.init(location: waypointLocation,
                                      name: waypointName,
                                      postalAddress: nil)

Unfortunately the above code gives me the following error message:

Ambiguous reference to member 'init(placemark:)'

Any ideas what's wrong?

Documentation:

Dennis
  • 362
  • 4
  • 13

3 Answers3

20

Just found out that in iOS 12 / Xcode 10 you also have to include the Contacts framework, as the postaladdress param has the class CNPostalAddress required for this initializer

import Intents
import Contacts
Rool Paap
  • 1,918
  • 4
  • 32
  • 39
2

By subclassing CLPlacemark it is possible to use the Intents frameworks protocol init(location:name:postalAddress).

Somewhere in your project:

class MyPlacemark: CLPlacemark {}

Your code to create a custom CLPlacemark:

let placeLocation = CLLocation(latitude: 50.00, longitude: 8.00)
let placeName = "Some name"
let customPlacemark = MyPlacemark(location: w1Location, name: w1Name, postalAddress: nil)
Dennis
  • 362
  • 4
  • 13
  • I tried your solution but still get the same error :( What Frameworks to you import? I tried CoreLocation and Intents... Still the error :( – Georg Aug 30 '18 at 06:55
0

You need to use

init(location:name:postalAddress);

The placemarkWithLocation call is objective-C not swift hence why it is throwing that error message.

In the documentation you will see a language selection on the right hand side. init(location:name:postalAddress is the swift call you will need to create a new place mark.

Adam Richardson
  • 2,518
  • 1
  • 27
  • 31