# Swift delegate (CLLocationManagerDelegateProtocol)

**URL:** <https://discuss.kotlinlang.org/t/swift-delegate-cllocationmanagerdelegateprotocol/14320>\
**Category:** Native\
**Created:** [September 19, 2019, 2:39am UTC](https://discuss.kotlinlang.org/t/swift-delegate-cllocationmanagerdelegateprotocol/14320 "2019-09-19T02:39:08Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![guillodacosta](https://avatars.discourse-cdn.com/v4/letter/g/e47c2d/32.png) [@guillodacosta](https://discuss.kotlinlang.org/u/guillodacosta)\
**Post date:** [September 20, 2019, 7:37pm UTC](https://discuss.kotlinlang.org/t/swift-delegate-cllocationmanagerdelegateprotocol/14320/5 "2019-09-20T19:37:37Z")

</div>

Thanks again @Artyom.Degtyarev  
I did updated the compiler to `1.3.50` and I finally can compile the project but now I see a runtime error when I try to assign the delegate `locationManager.setDelegate(derived)`.

The actual error showing in my xcode on runtime is:

```auto
/Users/teamcity/buildAgent/work/4d622a065c544371/runtime/src/main/cpp/ObjCInterop.cpp:125: runtime assert: Unable to add method to Objective-C class

```

Where teamcity is not even a user from my machine.

I show to you the code like actually I’m working:

```auto
actual fun Location.getLocation(onGetLocation: (location: GeoPoint) -> Unit) {
    val delegate = CLLocationManagerDelegateImpl()
    val derived = CLLocationManagerDelegate(delegate)
    locationManager.setDelegate(derived)
    locationManager.requestWhenInUseAuthorization()
}

class CLLocationManagerDelegateImpl: CLLocationManagerDelegateProtocol, NSObject() {

    override fun locationManager(manager: CLLocationManager, didUpdateLocations: List<*>) {
        didUpdateLocations.last { lastLocation ->
            val location = lastLocation as CLLocation
            location.coordinate.let { print("DelegateImpl found user's latitude: ${it}") }
            return
        }
    }
}

@Suppress("CONFLICTING_OVERLOADS")
class CLLocationManagerDelegate(delegate: CLLocationManagerDelegateProtocol) : CLLocationManagerDelegateProtocol by delegate, NSObject() {

    override fun locationManager(manager: CLLocationManager, didStartMonitoringForRegion: CLRegion) {}

    override fun locationManager(manager: CLLocationManager, didEnterRegion: CLRegion) {}

    override fun locationManager(manager: CLLocationManager, didExitRegion: CLRegion) {}

}

```

By last, I allredy cleaned `deriveddata` and `gradle caches`

---

_[View the full topic](https://discuss.kotlinlang.org/t/swift-delegate-cllocationmanagerdelegateprotocol/14320)._
