2

When I cast UIApplication.shareApplication() to my custom class AutoLogoutUIApplication, I got an error like below when I use Swift.

Could not cast value of type 'UIApplication' (0x28f4408) to 'Porject_Name.AutoLogOutUIApplication' (0x1f50d0).

Here is my code in swift:

let app = UIApplication.sharedApplication() as! AutoLogOutUIApplication
app.enableAutoLogout = false

In objective-c :

((AutoLogOutUIApplication *)[UIApplication sharedApplication]).enableAutoLogout = NO;

Here is my AutoLogOutUIApplication class:

class AutoLogOutUIApplication: UIApplication {
   //properties
}

Please help!

vichhai
  • 2,548
  • 2
  • 15
  • 25
  • Your shared application isn't an instance of `AutoLogoutUIApplication`. Have you removed the `@UIApplicationMain` line from your app delegate and added a new `main.swift` file? http://stackoverflow.com/questions/24020000/subclass-uiapplication-with-swift – Paulw11 May 24 '16 at 02:39
  • @Paulw11 can you show me by example with coding? – vichhai May 24 '16 at 04:08
  • Refer to the question I linked to – Paulw11 May 24 '16 at 04:57

0 Answers0