How to “fake” ivars in an Obj-C category (iPhone)

后端 未结 5 1121
鱼传尺愫
鱼传尺愫 2021-02-09 16:13

Update:

iPhone OS 3.1 has associated objects. However, the iPhone simulator does not. If you want to test associated objects code in the simulator, you should file a bug

5条回答
  •  醉梦人生
    2021-02-09 16:35

    I'll add an answer.

    I found the original blog post, it was from Steve Degutis.

    It basically involves replacing NSObject's methods for valueForUndefinedKey:, setValue:ForUndefinedKey:, and dealloc. Then using a static Dictionary to store any undefined keys.

    Just about as nasty and fun as Louis's solution.

提交回复
热议问题