7

I have a custom navigationBar :

class Name_UINavigationBar: UINavigationBar {
    // code
}

and I want to set it to my navigation controller programmatically. So I tried :

var navController : UINavigationController = UINavigationController(
            navigationBarClass: object_getClass(Name_UINavigationBar),
            toolbarClass: nil)
// code

But it crash saying :

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
    reason: 'MyProject.Name_UINavigationBar is not a subclass of UINavigationBar'
anasaitali
  • 1,504
  • 21
  • 30

2 Answers2

7

Try this.

let navController = UINavigationController(navigationBarClass: YourNavigationBar.self, toolbarClass: nil)

I encountered the same error and was able to get it working again like that.

Isuru
  • 30,617
  • 60
  • 187
  • 303
0

In Swift there is no supported way to get the Class of an object. You're problem is almost certainly to do with the object_getClass method which I believe is no longer supported as of Beta 5.

I imagine APIs like this will either be updated, rewritten or simply deprecated soon. For now you will need to do it in Objective-C.

Infinity James
  • 4,667
  • 5
  • 23
  • 36
  • I'm on xcode 6 beta 7 and it doesn't say anything about object_getClass. But what you say seems to be a good explanation. – anasaitali Sep 09 '14 at 11:05