In your "answer" you include the code:
+(void)initialize
{
titles = @[NSLocalizedString(@"CODE", nil), NSLocalizedString(@"ERROR", nil), NSLocalizedString(@"TROUBLESHOOTING", nil)];
}
This is indeed the source of your issue. It's wise to be very careful when implementing +load
or +initialize
. @bbum has a great article on exactly that topic.
+initialize
is invoked the first time the class (or category) is touched - when the class is initialized +initialize
is called by the class loading mechanism. There is no guarantee of when in the class loading process this may happen, which is part of your problem.
In your case you are using NSLocalizedString
- which under the hood can be fairly heavy. It has dependancies on several other classes (NSString
, etc) and can potentially access the file system. As @bbum points out in his article, that can lead to serious trouble. In your case, this may be a nasty deadlock.
Move your titles = @[NSLocalizedString...
line to a more appropriate place in your object, like an initializer, awakeAfterUsingCoder:, etc. and your immediate problem should be solved. After doing so you should check your entire codebase for instances where +initialize
and +load
are implemented and audit them to make sure those uses are in line with @bbum 's recommendations.