Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get Typhoon to work in Swift project #356

Closed
alexmaie opened this issue May 24, 2015 · 7 comments
Closed

Can't get Typhoon to work in Swift project #356

alexmaie opened this issue May 24, 2015 · 7 comments

Comments

@alexmaie
Copy link

Hey guys,

I have the following class

public class HuntConfiguration: NSObject {

    public var tasks =  [ParticipantTaskGroup]();

    var configurationSource : ConfigurationSourceProtocol;

    public init(Configsource: ConfigurationSourceProtocol ) {

        configurationSource = Configsource;

        var result = configurationSource.getTaskGroups();

        switch(result){
        case .Success(let t ):
            tasks = t;
        case .Failure:
          ExceptionBridge.throwExceptionWithString("No configuration loaded")
        }
    }
}

and Assembly

public class ApplicationAssembly: TyphoonAssembly {


    public dynamic func configuration() -> AnyObject{
        return TyphoonDefinition.withClass(HuntConfiguration.self){
            (definition) in

            definition.useInitializer("initWithConfigsource:") {
                (initializer) in

                initializer.injectParameterWith(FileConfigurationSource());
            }

           definition.scope = TyphoonScope.Singleton;
        }
    }


}

Now, if i want to resolve the HuntConfiguration class

    let assembly = ApplicationAssembly().activate()
    var config = assembly.configuration() as? HuntConfiguration;

I get an exception in method

- (BOOL)isClassMethodOnClass:(Class)_class
{
    BOOL instanceRespondsToSelector = [_class instancesRespondToSelector:_selector];
    BOOL classRespondsToSelector = [_class respondsToSelector:_selector];

    if (!instanceRespondsToSelector && !classRespondsToSelector) {
        [NSException raise:NSInvalidArgumentException
                    format:@"Method '%@' not found on '%@'. Did you include the required ':' characters to signify arguments?",
         NSStringFromSelector(_selector), NSStringFromClass(_class)];
    }

    return classRespondsToSelector && !instanceRespondsToSelector;
}

I don't know how to solve the problem

@jasperblues
Copy link
Member

Hi @alexmaie ! Sorry for the delay in reply. The best place to ask general questions is StackOverflow - usually gets a faster response.

Can you post the actual error that was thrown?

@alexmaie
Copy link
Author

Yo @jasperblues

This is the error

2015-05-27 18:06:15.513 BeaconTreasureHunt[1371:65098] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Method 'initWithConfigsource:' not found on 'BeaconTreasureHunt.HuntConfiguration'. Did you include the required ':' characters to signify arguments?'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001015a9c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000100e86bb7 objc_exception_throw + 45
    2   CoreFoundation                      0x00000001015a9b9d +[NSException raise:format:] + 205
    3   Typhoon                             0x000000010095eb3e -[TyphoonMethod(InstanceBuilder) isClassMethodOnClass:] + 238
    4   Typhoon                             0x000000010095df47 -[TyphoonMethod(InstanceBuilder) createInvocationWithContext:completion:] + 135
    5   Typhoon                             0x0000000100966698 -[TyphoonComponentFactory(InstanceBuilder) initializeInstanceWithDefinition:args:] + 872
    6   Typhoon                             0x0000000100966226 -[TyphoonComponentFactory(InstanceBuilder) buildInstanceWithDefinition:args:] + 246
    7   Typhoon                             0x0000000100966ef9 -[TyphoonComponentFactory(InstanceBuilder) buildSharedInstanceForDefinition:args:] + 281
    8   Typhoon                             0x000000010096d260 -[TyphoonComponentFactory(TyphoonDefinitionRegisterer) newOrScopeCachedInstanceForDefinition:args:] + 400
    9   Typhoon                             0x000000010096c684 -[TyphoonComponentFactory instantiateIfEagerSingleton:] + 116
    10  Typhoon                             0x000000010096c587 __53-[TyphoonComponentFactory instantiateEagerSingletons]_block_invoke + 103
    11  CoreFoundation                      0x00000001014dff22 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
    12  CoreFoundation                      0x00000001014df67c -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 300
    13  Typhoon                             0x000000010096c4fb -[TyphoonComponentFactory instantiateEagerSingletons] + 139
    14  Typhoon                             0x000000010096bbe1 -[TyphoonComponentFactory _load] + 97
    15  Typhoon                             0x000000010096a886 -[TyphoonComponentFactory load] + 150
    16  Typhoon                             0x00000001009517ed +[TyphoonStartup injectInitialFactoryIntoDelegate:] + 61
    17  Typhoon                             0x00000001009513f9 __60+[TyphoonStartup swizzleSetDelegateMethodOnApplicationClass]_block_invoke + 313
    18  UIKit                               0x000000010199c4f4 -[UIApplication _setDelegate:assumeOwnership:] + 32
    19  UIKit                               0x00000001019a28e1 UIApplicationMain + 1251
    20  BeaconTreasureHunt                  0x00000001007ff2e7 main + 135
    21  libdyld.dylib                       0x00000001031aa145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

@jasperblues
Copy link
Member

Be sure to mark the initializer as dynamic otherwise Swift will optimize it in a way that it can't be invoked via the ObjC runtime:

public dynamic init(Configsource: ConfigurationSourceProtocol ) 

@jasperblues
Copy link
Member

@alexmaie Let's move this question over to StackOverflow. It look like a config issue, however if we discover a bug, we can open one here.

@alexmaie
Copy link
Author

Hey Jasper

SOrry for my late response, but I had to work on another project and couldnt test out the dynamic addition. Because of Protocol ConfigurationSourceProtocol, that was using an generic enum, I could not get the project to compile. I had to remove the generic enum and afterwards everything worked fine :)

@jasperblues
Copy link
Member

@alexmaie Glad to hear its working now. . yes, Typhoon is a little more tricky with Swift, but at least the syntax in Swift is nice to look at :)

@alexmaie
Copy link
Author

I agree :) . Would have hoped to come up with a better error handling
mechanism then passing around NSError or Enums. It's a pity that Exceptions
can't be used :(

On Sat, May 30, 2015 at 2:59 PM, Jasper Blues notifications@github.com
wrote:

@alexmaie https://github.com/alexmaie Glad to hear its working now. .
yes, Typhoon is a little more tricky with Swift, but at least the syntax in
Swift is nice to look at :)


Reply to this email directly or view it on GitHub
#356 (comment)
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants