"Objective-C method conflicts with optional requirements method" error after upgrading to Xcode 6.3 (Swift 1.2)

I use the Google Maps iOS SDK in my application, everything worked fine until today. I downloaded Xcode 6.3 and got some errors. All of them are sorted, with the exception of two errors in my MapViewController class that appeared by these two methods:

first method:

func mapView(mapView: GMSMapView!, didTapMarker marker: ExtendedMarker!) -> Bool { ... some code ... } 

with an error:

Objective-C method 'mapView: didTapMarker:' provided by the method 'mapView (: didTapMarker :)' conflicts with the optional requirements method 'mapView (: didTapMarker :)' in the protocol 'GMSMapViewDelegate'

second method:

 func mapView(mapView: GMSMapView!, markerInfoContents marker: ExtendedMarker!) -> UIView! { ... some code ... } 

with an error:

Objective-C method 'mapView: markerInfoContents:' provided by the method 'mapView (: markerInfoContents :)' conflicts with the optional requirements method 'mapView (: markerInfoContents :)' in the protocol 'GMSMapViewDelegate'

I tried to rewrite these methods, but that did not help. I also checked the update of the Google Maps SDK, but the latest update is from February 2015.

I would be grateful for any advice, thanks in advance! :)

+6
source share
3 answers

I would say that your problem is the ExtendedMarker type for the second parameter. Having adopted the protocol, your promises class, which, if it implements the optional mapView:didTapMarker: method, the second parameter can be GMSMarker or any subclass of it.

Your method does not satisfy the interface contract because it only accepts ExtendedMarker instances - which I consider to be a subclass of GMSMarker .

I would define a method something like this. You should be prepared to deal with the Extended ExtendedMarker instances that are being transferred because the contract says you can receive them. Just trying to force a throw can throw an exception.

 func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool { // Non specific ExtendedMarker processing if let marker = marker as? ExtendedMarker { // ExtendedMarker specific processing } // More non specific ExtendedMarker processing } 
+3
source

Unfortunately, I do not have the Google iOS SDK at hand, but can it be that the error is related to the parameters marked as taken with effort? Maybe a forced U-turn is no longer required (I had a similar problem with another method when porting to Swift 1.2, so just guessing)

+1
source

I had the same problem with 'didTapInfoWindowOfMarker'. If you try the following code, this might work for you too:

 func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool { let placeMarker = marker as! ExtendedMarker ... some code ... } 

you can do the same with another. I hope this works for you!

+1
source

Source: https://habr.com/ru/post/985080/


All Articles