Developed an app that doesn't have any problems in debug mode and crashes directly in release mode.
After a period of positioning finally positioned to the following section of the code:
E_bz_testtype type = [dic[@ "type"] integervalue];
Calling code = [NSString stringWithFormat:@ "%@", Nsstringfrome_bz_testtype (type)];
Where enumeration definitions and enumeration translations are defined in Chinese as follows:
//enumeration in a XXDefine.htypedef ns_enum (Nsinteger, E_bz_testtype) {Ke_bz_testtype_none=0, Ke_bz_testtype_one=1,};//translation function DefinitionNSString *nsstringfrome_bz_testtype (e_bz_testtype type);//the translation function is implemented in a XXDEFINE.MNSString *nsstringfrome_bz_testtype (e_bz_testtype type) {Switch(type) { CaseKe_bz_testtype_none:return @"No"; CaseKe_bz_testtype_one:return @"a"; default: Break; }}
Note The above code:
1. Code is not inside any class
2. The default of the translation function is break, and no value is returned.
3. In debug/release mode, the translation function does not produce any errors or any warnings
For note 3rd, if you change the translation function implementation to the following, an error will occur
NSString *nsstringfrome_bz_testtype (e_bz_testtype type) { switch (type) { Case ke_bz_testtype_none: return@ " no "; default : Break ; }}
So here's the problem:
When the type in the calling code does not belong to any one of the enumerations, for example, type = 100
When using a translation function:
The DEBUG mode is: 100 strings returned
And in release mode it's a direct crash.
Therefore, the translation function can only be modified as follows:
NSString *nsstringfrome_bz_testtype (e_bz_testtype type) {Switch(type) { CaseKe_bz_testtype_none:return @"No"; CaseKe_bz_testtype_one:return @"a"; default: return @"Unknown"; }}
So there's no problem.
I think this is the result of the Release mode code optimization.
IOS enum C method DEBUG, release of a hidden pit