Using valueForKeyPath on NSDictionary if a key starts the @ symbol?

后端 未结 5 2063
温柔的废话
温柔的废话 2020-12-15 19:04

I want to use valueForKeyPath on my NSDictionary, but the problem is that one of the keys is a string that starts with the @ symbol. I have no cont

5条回答
  •  感动是毒
    2020-12-15 19:34

    I see that there are 2 ways

    Swizzle

    You can swizzle the valueForKeyPath on NSDictionary to remove the @ symbol, remember to account for @sum, @average, ...

    Override if you're using Mantle

    Override + (id)modelOfClass:(Class)modelClass fromJSONDictionary:(NSDictionary *)JSONDictionary on MTLJSONAdapter, traverse all the keys and remove the @ symbol

提交回复
热议问题