FMDB () {FMDB () {FMDB ();




Error message

I. Original code:






The original code

At that time, I was also confused, so I looked up some information, but most of them are introduced to say that there is no correlation caused by xiB file Settings, but in fact I am in the dictionary setting value when this error occurred.

Since then, I have not found a solution because I did not carefully check the error information and the concept of basic knowledge was vague.

However, after asking my friends today, I found that I made a mistake in my basic point and forgot the attributes of the dictionary.

Ii. Code Description:



[dict setValue:(nullable id) forKey:(nonnull NSString *)];

This method is NSObject inheriting from the NSKeyValueCoding protocol, so anything that inherits NSObject will have this method. But when the dictionary sets this method, it is adding key-value pairs to the dictionary. NSDictionary is an immutable dictionary, which can only change the value corresponding to the existing key, not the new key value pair. NSMutableDictionary, on the other hand, is a mutable dictionary to which new key-value pairs can be added using this method. So all you need to do is change the dictionary property from immutable to mutable.

Note: confused by such basic things, it is really drunk, only blame themselves did not learn the basic knowledge. We must learn the basics well!

Iii. Code after correction:






The corrected code

Iv. Supplementary:


SetValue: forkey: and property

For dictionaries:

Is to add a unique label to the value to facilitate identification. Value is the main cause, and a unique label for the key is added only when value is present.

For property:

Is an assignment to the created property. It’s only when you have a property property, a key; There will be an assignment, value.


SetValue: forkey: setValue: forkey: setValue: forkey:

SetValue: forkey:

(1) Value can be nil, but when value is nil, the removeObject: forkey: method is automatically called;

(2) The key can only be an NSString.

SetObject: forkey:

(1) Value cannot be nil, otherwise an error will be reported;

(2) Keys can be of any type. If the key starts with @ (for example, NSDictionary), you are advised to use ObjectForkey.


Good good study, day day up! ^_^