appsquickly / typhoon-example

An example application built with Typhoon dependency injection framework.
Apache License 2.0
251 stars 59 forks source link

Cannot initialise AddCityViewController #27

Closed gavinkilbride closed 9 years ago

gavinkilbride commented 9 years ago

When trying to run the Typhoon example I get the following error when trying to Add a City.

fatal error: use of unimplemented initializer 'init(nibName:bundle:)' for class 'PocketForecast.AddCityViewController'

Apologies if this is a trivial error I'm a windows dev and this is only week two of my first mac.

jasperblues commented 9 years ago

Oops. I'll take a look at this in about 30 minutes. There was an issue that I thought gets fixed in Swift 1.2, perhaps not. . It might be necessary to make a custom initializer besides initWithNibName:bundle: . . will confirm (and explain reason) shortly.

jasperblues commented 9 years ago

@gavinkilbride I have fixed this issue. By the way, I assume you were referring to the Swift sample and not Objective-C (this repo) ? . . it wouldn't happen in Objective-C

Reason for this Error:

Typhoon makes use of the Objective-C runtime for the following:

Being a compiled language, the mechanism that Objective-C uses to provide these features is 'messaging' style of method invocation. With the introduction of Swift, the language reverts back to a very static, C++ 'vtable' style of method invocation. Vtable is very flexible in a 'managed' runtime environment, but locked down when it comes to compiled languages. . . If we extend NSObject then Swift will revert back to using messaging. Additionally we can add the dynamic attribute to a method to tell it to use a messaging style of invocation.

Unfortunately for that particularly method - initWithNibName:bundle, it seems to get vtabled no matter what. Even overriding the method in a subclass doesn't help.

Swift 1.1 had more of these kinds of issues.

I fixed it by providing a customer init method on the AddCityViewController . . . clear?

gavinkilbride commented 9 years ago

That's great Jasper and thank you for taking the time to explain the reason for the bug. I look forward to giving Typhoon a go. I'm now happily checking out the weather at home (Manly Australia).

jasperblues commented 9 years ago

You're welcome :) Happy architecting