ios - Swift singleton used with init(coder:) -


i'm trying make reusable ui component using singleton it's same instance used through app when ui component show (only 1 of these can shown @ same time obviously).

so created simple uiview subclass , defined sharedinstance swift 1.2 way. here's code :

import uikit  class myview: uiview {     static let sharedinstance = myview() } 

the thing wondering if there's way make sharedinstance used when view called storyboard (so through init(coder:) method).

in objc easy init methods can return desired object in swift don't know if it's possible (as swift init don't return object).

edit : add context (some people don't understand why i'd want that). i'm trying avoid given ui component on have no control eat memory available.

this component mkmapview doesn't free memory takes after being uninstantiated. tried several things none did give me memory took instantiation of mkmapview.

so trying use same instance of mkmapview everywhere avoid having more used memory necessary.

i asked question have generic answer on topic of having sharedinstance returned when init(coder:) called use component storyboard file without having put on code use sharedinstance.

one way grab scene directly out of storyboard:

static let sharedinstance = (uistoryboard(name: "main", bundle: nil).instantiateviewcontrollerwithidentifier("identifier") as! uiviewcontroller).view 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -