KVC string conversion not working for BOOL value

前端 未结 3 362
我寻月下人不归
我寻月下人不归 2021-01-01 06:03

Hey. I am reading in a string from a file and attempting to use the resulting string to set a BOOL property on an object using the KVC method -setValue:forKeyPath:

3条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-01 06:43

    Add a simple category to your project:

    @implementation NSString (CharValue)
    
    - (BOOL)charValue {
        return [self isEqualToString:@"0"] ? NO : YES;
    }
    
    @end
    

提交回复
热议问题