drawStatusChangedHandler

935
4
Jump to solution
11-22-2016 07:10 AM
BrianFlood1
New Contributor III

has the drawStatusChangedHandler block been removed at 100? thanks

0 Kudos
1 Solution

Accepted Solutions
RyanOlson1
Esri Contributor

It has been removed in favor of KVO on the `drawStatus` property:

```

import UIKit

import ArcGIS

private var myKVOContext = 0

class ViewController: UIViewController {

    

    let mapView = AGSMapView(frame: CGRect.zero)

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        mapView.frame = view.bounds

        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        view.addSubview(mapView)

        

        mapView.map = AGSMap(basemapType: .streets, latitude: 0, longitude: 0, levelOfDetail: 0)

        

        mapView.addObserver(self, forKeyPath: "drawStatus", options: .new, context: &myKVOContext)

        

    }

    

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

        

        if context == &myKVOContext{

            if keyPath == "drawStatus"{

                print("drawStatus changed: \(mapView.drawStatus.rawValue)")

            }

        }

        else{

            super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)

        }

        

    }

}


```

View solution in original post

4 Replies
RyanOlson1
Esri Contributor

It has been removed in favor of KVO on the `drawStatus` property:

```

import UIKit

import ArcGIS

private var myKVOContext = 0

class ViewController: UIViewController {

    

    let mapView = AGSMapView(frame: CGRect.zero)

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        mapView.frame = view.bounds

        mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]

        view.addSubview(mapView)

        

        mapView.map = AGSMap(basemapType: .streets, latitude: 0, longitude: 0, levelOfDetail: 0)

        

        mapView.addObserver(self, forKeyPath: "drawStatus", options: .new, context: &myKVOContext)

        

    }

    

    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

        

        if context == &myKVOContext{

            if keyPath == "drawStatus"{

                print("drawStatus changed: \(mapView.drawStatus.rawValue)")

            }

        }

        else{

            super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)

        }

        

    }

}


```

BrianFlood1
New Contributor III

thank you, works as expected

0 Kudos
JamesRichards1
Occasional Contributor

Brian,

If your going to be using KVO much, check out Facebook's KVOController library:

https://github.com/facebook/KVOController

It's block based API makes wiring up KVO events much cleaner in code.

Cheers,

James

BrianFlood1
New Contributor III

thanks james, I'll take a look

0 Kudos