Strange behaviour with Xcode and iphone
I've stumbled upon what seems like an impossible situation with an iphone app. I have three boolean variables which all are NO (false) and then I test in an if statement whether they is at least one of them as YES (true).
Well, as you can see in the screenshot, the debugger steps inside the if clause and eventually adds the value of BOTTOM_HEIGHT
to the height variable. This seems absolutely backwards, have I found a quantum boolean or something? (jk)
Here is the screenshot:
I have already tried to clear the project, Reset the contents and settings of the simulator and even deleted the Derived Data from the xcode build folder in case it was caching old code and nothing seems to work.
----- Update ------
Ok, it seems that it works ok b开发者_如何学JAVAut the variables after debugging with the ideas provided by Maverick1st aren't being reported correctly and hasAvatar, hasRating and haOpinions are always shown as NO. I've figured out that the problem with the result being incorrect is on the offer
which is a NSManagedObject
is never null despite setting as null when I initialize the object and when I log it I get this:
2011-09-22 10:00:03.889 11870.com[2613:207] offer: (null)
This object gets initialized in a separate project in the workspace that gets added as a static library and I think I've deleted the library's build files so that they get generated again. In fact, I know it since otherwise it would give me a compilation error since on previous version of the library we didn't have the offer property.
I'm gonna do further investigation to see if I find why is this happening.
PS: can someone reedit my post, since it doesn't let me post images yet, thanks
Have you tried formulating explicitly with (hasEdit == YES)-terms?
Try to write the statement
if(hasRating ││ hasAvatars ││ hasOpinions)
as seperate if statements.
---------Edit----------
Ok, so maybe it will work like this way. This is at least how i do those kind of things.
BOOL b_oneOfTheThreeIsTrue;
if(hasRating)
b_oneOfTheThreeIsTrue = true;
if(hasAvatars)
b_oneOfTheThreeIsTrue = true;
if(hasOpinions)
b_oneOfTheThreeIsTrue = true;
Still good to debug and you can check for the one variable in your if statement.
if(b_oneOfTheThreeIsTrue)
doSomething;
Ok, after further investigation I found that there were several problems.
- With the quantum booleans the debugger for the simulator was going "bananas" when running the release build. When running on debug it works as expected.
- The offers never being null turned to be a problem with CoreData returning a
NSNull
object. I found the solution here: if statement fails with variable from CoreData managed object - Another problem I didn't report is that the height of the cell weren't correct but I just reduced one of the measures used to calculate the total height as a workaround since it looks like the offset was constant.
Thanks for all the responses, it was really helpful.
PS: Should I select this answer as correct or wait for voting? Quite new poster here :)
Update:
I finally got to the source of the issue for the third problem ans why it was returning a reference to [NSNull null] instead of nil as it does with the rest of relationships in CodeData.
The secondary project that handles the DAO operations had no target and the target dependency got lost somehow when changing from Xcode 3.2 to Xcode 4.0 a couple of months back. It wasn't giving me a problem with the selector since the model was being copied in a different way.
Well, apparently CodeData has 2 different null states for objects: NSNull
for when the object has not been set and nil when you give the value nil (Which I tent to do in the parse and hence it didn't return NSNull
before)
Anywho, all seems to be working more or less as expected.
精彩评论