0

We're working on an app that saves a lot of stuff in to Core Data. The stuff it saves is mainly NSDate NSNumber & NSString but it also saves many images and videos as NSData. I'm trying to change it so that these files are instead saved to local storage and a file name is saved in core data instead, then we just load it up from the local storage, hopefully saving time when accessing core data and making it a bit more stable.

After discussing it, we thought it would be easiest to override encodeWithCoder and initWithCoder so that we can just intercept the calls to save the data and save them on the file system instead. Then I found out that NSData is actually a part of a class cluster and so overriding the functions is harder then it seems.

So then I read about method swizzling where you can just swap one implementation for another. I Googled around and found this, and also found a post on Stack Overflow saying to use that article, but it didn't really help me and I'm still non the wiser on how I would do what I need.

Could anyone point me in the right direction or give me some of their own pointers on how I would do this?

Thanks,

4

1 に答える 1

2

これらをスウィズルする方法はありません-私を信じてください:)

説明どおりに保存したい場合は、その実装をクラスのアーカイブ メソッドの実装 (サブクラスではなく、スウィズルではなく、これらのオブジェクトを含むクラス) に配置します。

于 2012-05-24T09:07:28.493 に答える