Skip to content

Can't call init with data #46

Open

Description

@mikegunning

Hey! Really excited to get this project working for me.

I have a number of views and view controllers I would like to test. I am using Realm in-memory to create Realm Objects to pass into my inits to instantiate my views and view controllers.

failed: caught "NSInvalidArgumentException", "-[StoriesASDetailViewController initWithStory:]: unrecognized selector sent to instance 0x7fa5fbe07ce0"

No matter what I try, be it a cell or tableviewcontroller, I just keep getting the error above.

Any advice?

`
+(UIView *)viewForData:(NSDictionary *)data reuseView:(UIView *)reuseView size:(LYTViewSize *)size context:(id _Nullable __autoreleasing *)context {

        StoryModel *story = [[StoryModel alloc] initWithDictionary:data error:nil];

        StoryRealm *local = [[StoryRealm alloc] initWithStoryModel:story];

        StoriesASDetailViewController *footer = [[StoriesASDetailViewController alloc] initWithStory:local];

        StoryDetailCell *cell = [footer.collectionNode cellForItemAtIndexPath:0];

        *context = footer;

        return cell;

}
`

Activity

  1. plivesey commented on Mar 13, 2018

    @plivesey
    Contributor

    It's crashing on that 3rd line right? Where is [StoriesASDetailViewController initWithStory:] defined in your project? I assume it's in the main app bundle?

    My guess is for some reason that code isn't being included in your test project.

    Another thing to check - if you just create a regular unit test and write:

            StoriesASDetailViewController *footer = [[StoriesASDetailViewController alloc] initWithStory:nil];
    

    Does it crash also?

  2. mikegunning commented on Mar 14, 2018

    @mikegunning
    Author

    Yes crashing on the third line. I am using the same approach in separate unit tests in the same target using:
    StoriesASDetailViewController *footer = [[StoriesASDetailViewController alloc] initWithStory:nil];

    I have tried a number of UITableCell and other UIViewController where I pass in an object into the init, and I get the same error each time....

    If possible, could you expand on the sample Objective-C example like the swift example?

  3. plivesey commented on Mar 14, 2018

    @plivesey
    Contributor

    Could you send a full stack trace of the crash? The other thing I was going to suggest was ensuring that the file was added to the target, but looks like you've already verified that.

  4. plivesey commented on Mar 14, 2018

    @plivesey
    Contributor

    Another thing to try (not sure if this will work), when when you get this error:

    failed: caught "NSInvalidArgumentException", "-[StoriesASDetailViewController initWithStory:]: unrecognized selector sent to instance 0x7fa5fbe07ce0"

    po [0x7fa5fbe07ce0 class]
    

    and see what it prints out (haven't tried it so don't know if this will work)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions