Saturday, 15 January 2011

ios - Using IBoutlet in constant initalization -



ios - Using IBoutlet in constant initalization -

i want utilize iboutlet mapview in mapmanager. realise connection have nowadays mapview mapmanager. thought work:

@iboutlet var mapview: mkmapview! var locationmanager = cllocationmanager() var userlocation: mkuserlocation! allow mapmanager: mapmanager = mapmanager(mapview : mapview)

now, wonder if right way it. mean, going utilize mapview in model isn't best thing do. how realise idea?

i think code should not compile, because when initializing mapmanager implicitly referencing self, unavailable until class properties have been initialized.

i solve problem defining implicitly unwrapped mapmanager property:

var mapmanager: mapmanager!

which initialized when mapview set:

@iboutlet var mapview: mkmapview! { didset { self.mapmanager = mapmanager(mapview: mapview) } }

of course of study before referencing mapmanager have sure mapview has been initialized, otherwise runtime exception raised.

ios xcode swift

No comments:

Post a Comment