Objective-C atomic operations/locking access to myLocation property in Google Maps iOS SDK -
this partly question regarding google maps sdk in ios, though perhaps question atomic operations in objective-c.
in app, wish draw gmspolyline on map between user's current location , selected destination. can retrieve user's current location using mylocation
property on gmsmapview
. according documentation mylocation
:
if location enabled, reveals user location dot being drawn.
if disabled, or enabled no location data available, nil. property observable using kvo.
i have code draw polyline takes form:
if (mymapview.mylocation) { // draw polyline between mymapview.mylocation , selected destination }
my concern that, remote possibility, between check if (mymapview.mylocation)
, drawing polyline // draw polyline between mymapview.mylocation , selected destination
, mymapview.mylocation
might become nil
if location lost @ inopportune moment.
so question is, in objective-c, there way me wrap both check mymapview.mylocation
not nil , drawing polyline operation locks access mymapview.mylocation
, can't changed after check before attempting draw polyline. if objective-c provide mechanism, affect have if google library does attempt update mylocation
while locked? update queued until i've finished drawing polyline , release lock?
so guess question atomic transactions in objective-c, in context of google maps library.
i don't know objective c, based on locking in other languages, think want work if done in cooperation third-party library (ie google maps).
so example if somehow lock mymapview.mylocation
while using it, work if google maps sdk promised lock while modifying it, same lock object using. since mymapview.mylocation
can nil
, unlikely work since couldn't use nil
object 'key' lock.
similarly if lock entire gmsmapview
, such none of properties change while lock held, work if google maps sdk promised take same lock before making modifications.
in general, it's not idea lock arbitrary objects third-party libraries, might interfere library's own synchronization (unless library explicitly offers part of interface). vice versa, when writing library use third parties, it's best not implement internal locking on objects library makes public - instead locking should implementated on internal objects - in case user of library tries lock public object.
in case though, avoid problem doing this:
cllocation* location = mymapview.mylocation; if (location) { // draw polyline between location , selected destination }
that way if map view sets .mylocation
property nil
in between check , draw, still have reference cllocation
, can't set nil
.
note though the documentation says:
gmsmapview can read , modified main thread, similar uikit objects. calling these methods thread result in exception or undefined behavior.
it seems gmsmapview
honour same requirement , modify public properties main thread. if code running in main thread (which has to), unlikely map view's properties change in middle of code running.
Comments
Post a Comment