Thursday, March 26, 2015

Two bugs in comparison operation in objective c

Two kinds of bug may happen in ios comparison operation:

1. compare NSNumber to integer
NSNumber cannot be used to compare with an integer directly using == operator, as

NSNumber num=...;
if (num == 0){
}
will fail, as == in objective c will compare two objects are refer to the same one, instead [NSNumber isEquelToNumber:] should be used to compare NSNumber. However, the below code still does not work

NSNumber* num =...;
if ([num isEqualToNumber: 0]){
...
}
as isEqualToNumber requires the input parameter also a NSNumber object, passing a integer will throw exception.

So the correct comparison with integer should be
if (num.intValue ==0){
}
assume num is not nil.


2. condition operation
NSString a = "a";
NSString b= "";
NSString c="c";
NSString d="d";
NSString c= a+b?c:d;

The expected result is "ad", however, the actual result is "ac", as + has priority over :, so the above expression is equal to (a+b)?c:d, as a+b is always true, so c is used instead of d.
The fix is explicitly set the priority as a+ (b?c:d), which will generate the result of "ad";

Monday, March 23, 2015

Symbolize ios crash report based on app bundle and dSYM file with Xcode 8

If you archive the ios build from one box and need to symbolize the ios crash report from another box, then you need to do it with the following command
1. First copy application dSYM file,  and device crash report (.crash) file into the same folder on mac

2. open terminal app into the above folder

3 run the below command from terminal
export DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer

4.run the below command from terminal to generate the symbolized crash log

/Applications/Xcode.app/Contents/SharedFrameworks/DVTFoundation.framework/Versions/A/Resources/symbolicatecrash ./devicecrashreport.crash > symbolized.crash

If there are spaces on the above file name, then add single quotation mark around the file name

5. after the new symbolized crash report file (symbolized.crash) is generated on the same folder, double click it from Finder to show the symbolized file in console app




If the symbolization failed, then likely the crash report does not match the binary build, using the below steps to verify it:
1.from crash report, get the build uuid immediately after 'Binary Images" within <>.

2.from the bundle file, run the below command from terminal
xcrun dwarfdump --uuid <PATH_TO_APP_EXECUTABLE>

The file at PATH_TO_APP_EXECUTABLE must be an executable file, not an .app bundle or .ipa file.

3. The two UUID must match.