I cloned from https://github.com/facebook/facebook-ios-sdk.git today, and noticed two spots in the code which have this construct:
(id) init {
if ((self == [super init])) {
...
}
}
I would expect self to be assigned here, not tested for equality:
(id) init {
if ((self = [super init])) {
...
}
}
or at the very least:
(id) init {
self = [super init];
if (self) {
...
}
}
This is within src/FBDialog.m and sample/Hackbook/Hackbook/DataSet.m.
(Sorry if this should be in the bug tracker instead; couldn't find a way to actually submit anything there... :-/
It should assign self, because
[super init]may return a different object than self.Checking for equality will often work but isn't required to work. You should always assign.
I believe that recent versions of clang even emit warnings when using
==in this particular case.