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

how to deal with multi initializers? #72

Open
limboy opened this issue Apr 17, 2014 · 3 comments
Open

how to deal with multi initializers? #72

limboy opened this issue Apr 17, 2014 · 3 comments

Comments

@limboy
Copy link

limboy commented Apr 17, 2014

suppose I have a ViewController which can init in multi ways like -initWithCategory:, -initWithTag:, etc. how to deal this scenario? cause objection_initializer seems can be used once.

use one init and multi -configureWithCategory:, -configureWithTag: ?

@limboy limboy changed the title how to deal multi initializers? how to deal with multi initializers? Apr 17, 2014
@NachoSoto
Copy link
Contributor

Classes should only have one designated initializer, so objection_initializer is meant to be used with that one. Do all your initializers end up calling the same one?

@limboy
Copy link
Author

limboy commented Apr 17, 2014

@NachoSoto thanks 4 ur quick reply :)

no, they may call another class instead when using "class cluster", like NSNumber.

@implementation HBBoardsViewController

- (instancetype)initwithFeaturedBoards
{
    HBRecommendBoardsViewController *viewController = [[HBRecommendBoardsViewController alloc] init];
    return viewController;
}

- (instancetype)initWithFollowingBoards
{
    HBFollowingBoardsViewController * followingBoards = [[HBFollowingBoardsViewController alloc] init];
    return followingBoards;
}

- (instancetype)initWithKeyword:(NSString *)keyword
{
    HBSearchBoardsViewController *searchBoards = [[HBSearchBoardsViewController alloc] initWithKeyword:keyword];
    return searchBoards;
}

// ... 
@end

the HBRecommendBoardsViewController, HBFollowingBoardsViewController and HBSearchBoardsViewController are all sub class of HBBoardsViewController

@jdewind
Copy link
Contributor

jdewind commented Apr 17, 2014

Objection will only support one explicit initializer declaration.

In the future it might be a good idea to expand the JSObjectionFactory to take an optional initializer argument.

Right now you could solve this problem by creating a "builder" or "factory" that constructs the objects with their respective initializers. After initializing them you can use the -injectDependencies: message on JSObjectionInjector to ensure that object has been given the appropriate dependencies.

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

3 participants