Singleton and init with parameter

前端 未结 6 1357
孤街浪徒
孤街浪徒 2020-12-24 07:02

I want to use the singleton pattern in my class which has a private init with parameter. It also has a class function called setup which configures

6条回答
  •  醉话见心
    2020-12-24 07:37

    class Policies{
        static let shared = makeShared!();
        static var makeShared:(()->Policies)?;
    
        init(_ launchOptions:[UIApplicationLaunchOptionsKey:Any]?) {
            super.init();
            //initialization
        }
    }
    extension AppDelegate:UIApplicationDelegate{
        public func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool{
            Policies.makeShared = { Policies(launchOptions) }
        }
    }
    

提交回复
热议问题