KVC string conversion not working for BOOL value
问题 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: . However, this breaks with an exception: -[NSCFString charValue]: unrecognized selector sent to instance 0x7fff711023b0 . I'm guessing this is because BOOL is typedef'd from char. Is there a way around this? Thanks! 回答1: When setting a BOOL property using KVC, you need to pass an NSNumber object. What you could do in your case is