0

I am trying to add 1 library in to my code but after adding framework using pod install and converting the code to Swift 3, I am getting the above mentioned error here.

public override init() {
        super.init()
        size = UIApplication.shared.delegate!.window!!.bounds.size //Error here
    }

Thanks for your suggestions.

WasimSafdar
  • 1,044
  • 3
  • 16
  • 39
  • 1
    Duplicate of http://stackoverflow.com/questions/34034271/swift-sharedapplication-is-unavailable-use-view-controller-based-solutions or http://stackoverflow.com/questions/32609776/uiapplication-sharedapplication-is-unavailable ? – Martin R Oct 07 '16 at 11:30
  • It is not duplicate because that is for "sharedapplication()". I checked stackoverflow and then posted my question. – WasimSafdar Oct 07 '16 at 11:36
  • 1
    `sharedApplication` was renamed to `shared` in Swift 3, so it *could* be the same problem. – Martin R Oct 07 '16 at 11:37
  • If it is named shared then why there is error. I just updated my cocoa pods and error remains. There is no solution given for Swift 3 on stack. – WasimSafdar Oct 07 '16 at 11:42
  • Tried both solutions before posting this question. "self.extensionContext?" does not exists in Swift 3. – WasimSafdar Oct 07 '16 at 11:44

1 Answers1

4

If you only want the main screen's bounds you can get them by using the following code.

let mainScreenSize = UIScreen.main.bounds.size
nishith Singh
  • 2,968
  • 1
  • 15
  • 25