Reputation: 13371
I've recently upgraded my Xcode version to 4.2 - and now it's giving a load of warnings/issues from the Three20 source - and by a load of warnings I mean around 30 warnings.
Most of them seem to be the following:
Property access result unused - getters should not be used for side effects.
Here are a few examples from just one file in the Three20 source:
TTMessageController.m - line 542
- (NSString*)subject {
self.view; // << warning here
for (int i = 0; i < _fields.count; ++i) {
id field = [_fields objectAtIndex:i];
if ([field isKindOfClass:[TTMessageSubjectField class]]) {
UITextField* textField = [_fieldViews objectAtIndex:i];
return textField.text;
}
}
return nil;
}
TTMessageController.m - line 556
- (void)setSubject:(NSString*)subject {
self.view; // << warning here
for (int i = 0; i < _fields.count; ++i) {
id field = [_fields objectAtIndex:i];
if ([field isKindOfClass:[TTMessageSubjectField class]]) {
UITextField* textField = [_fieldViews objectAtIndex:i];
textField.text = subject;
break;
}
}
}
TTMessageController.m - line 576
- (void)setBody:(NSString*)body {
self.view; // << warning here
_textEditor.text = body;
}
I could go on... and on.
But why does three20 do this? - It seems strange to just call a getter and do nothing with it - is it some kind of initialisation?
Whatever it is - Xcode 4.2 doesn't seem to like it... how can I get rid of these warnings?
Upvotes: 1
Views: 395
Reputation: 5932
No need to fix these issues yourself. All the complier warning in three20 have been fixed in the latest development branch.
You can download the development branch from here: https://github.com/facebook/three20/tree/development
Upvotes: 2
Reputation: 27597
Adding self.view
to those methods will make sure that the view is actually loaded and initialized.
A UIViewController
derived object will usually not load the actual view until it is forced to do so. Commonly once that view is added onto a superview/window.
By referencing a view controller's view this way, you force that view to be loaded right away.
Three20 does this within property setters and getters to work around a faulty program flow.
Lets assume it was not doing so and lets also assume you call one of those setters/getters before the view (and its subviews) is/are initialized. As a result, for example the setBody: method would try to assign the given string towards a nil-object. It would not crash but also would not have any effect.
This way of working within viewcontrollers does however lead to a bypass on lazy loading of the connected views. Overall there is no need to worry, it will work properly but I would always recommend against doing it the way three20 does. Do resist on "fixing" these warnings by removing these lines as Three20 itself relies on these side effects of its getter-methods. As per the comment from xlc0212, you may however change these lines to [self view];
, the result will remain but the warnings will disappear.
From my experience, even though Three20 will throw warnings like crazy on Xcode4/LLVM3, you should generally not encounter real-life issues. It never failed for me.
Upvotes: 3