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

Use +initialize instead +load to instantiate iRate singleton #299

Open
rahul-malik opened this issue Jun 24, 2017 · 3 comments
Open

Use +initialize instead +load to instantiate iRate singleton #299

rahul-malik opened this issue Jun 24, 2017 · 3 comments

Comments

@rahul-malik
Copy link

Given that load methods must be evaluated before the main() method executes, I believe it would be better to instantiate the singleton instance using +initialize instead.

Is there a reason the current implementation uses load? I would be happy to put up a patch to address this

@rahul-malik rahul-malik changed the title Use initialize vs load to instantiate iRate singleton Use +initialize instead +load to instantiate iRate singleton Jun 24, 2017
@nicklockwood
Copy link
Owner

Yes, it's because initialize is only called the first time you reference the class, and I want it to be executed even if you don't have any references to iRate in your code (zero-config mode).

@rahul-malik
Copy link
Author

Do you think the most common usage is zero configuration though? The problem with +load is that we'll incur the pre-main cost past on every app load.

We previously had a fork of the project to handle this but I'd like to move us back on to main repository.

Would you be open to a PR that uses a conditional #define to use an +initialize method instead which could be used by consumers that know they are configuring irate?

@bvirlet
Copy link

bvirlet commented Jul 25, 2017

Hello,

I also have another issue with the + load: if we want to subclass iRate to add some functionality, it's impossible to do because + load will instantiate a singleton of type iRate and not iRateSubclass. Then if we access [iRateSubclass shared].myNewProperty we will get a crash.

I feel that load is a bit dangerous in that it's not a very common pattern.

Thanks!

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