Where to put .xib file inside framework project?

后端 未结 2 606
天命终不由人
天命终不由人 2021-02-05 16:05

I lost half a day figuring this and I can\'t see a straight forward solution online.

I created an iOS CocoaTouch Framework. I have some private and public classes in it

2条回答
  •  不知归路
    2021-02-05 16:57

    Generic solution for controllers with .xib file

    public extension UIViewController {
    
        //** loads instance from right framework bundle, not main bundle as UIViewController.init() does
        private static func genericInstance() -> T {
            return T.init(nibName: String(describing: self), bundle: Bundle(for: self))
        }
    
        public static func instance() -> Self {
            return genericInstance()
        }
    }
    

    Use as

    YourViewController.instance()
    

提交回复
热议问题