Can't convert signed char type with OCNumber
I want to convert "-1" with OCNumber to NSNumber, but after use: var oc_n = OCNumber("NSNumber", "numberWithChar:", [-1]);
then oc_n.charValue() return "255", how to resolve this issue, please?
Test: XCode->Edit Scheme->Run->Build Configuration->Debug: oc_n.charValue() return -1; XCode->Edit Scheme->Run->Build Configuration->Release: oc_n.charValue() return 255;
Why?
How should I get a signed return value after an jspatch call? I need -1 but not 255 on native.
- 过程:
用jspatch重写了接口,返回的代码是:
getSignedKey: function() {
var oc_n = OCNumber("NSNumber", "numberWithChar:", [-1]);
console.log("get value:"+ oc_n.charValue());
return oc_n.charValue();
}
console log是:
"get value:-1"
我的本地接口获取到的值却有不同:
char signKey = self.getSignedKey();
NSLog("the signed key: %d, %@", signKey, @(signKey));
``
- 测试结果:
- XCode->Edit Scheme->Run->Build Configuration->Debug:
获取到的值: "the signed key: -1, -1"
- XCode->Edit Scheme->Run->Build Configuration->Release:
获取到的值: "the signed key: 255, -1"
-
问题:
release模式,获取到的为啥是-1的补码255?
-
要求:
期望: getSignedKey()接口返回的值,总是-1, 而不是补码.
-
影响: 而我的存储字典里的键值对key是用的signed char类型如:
signed char aKey = -1;[dictionary setObject:@"value_1" forKey:@(aKey)];` 当我通过getSignedKey()接口,获取到 'signedKey'后,去查找字典, 前者能成功匹配, 而后者不能匹配到key; -
请问这个问题怎么解决?
建议尝试:
- 看 release 和 debug 的build settings 有什么不同
- 测试直接在OC调 numberWithChar,再输出 charValue 看是不是结果一样