1

私はいくつかのファイル URL を (ドラッグ アンド ドロップで) 受け取り、それらのファイルを処理する単純な Cocoa アプリケーションを作成しています。ドラッグ アンド ドロップ メカニズムを制御するクラス (NSView のサブクラス) があり、Interface Builder (「カスタム クラス」オプションを使用) を介して NSView に割り当てられます。ファイル URL は NSMutableArray に入ります。

次に、これらのファイルの URL を取得して何らかの処理を行う別のクラスを作成します。このクラスには、「do stuff」メソッドを呼び出す NSButton に接続された IBAction もあります。

私の質問は、「ドラッグ アンド ドロップ」クラスから「do stuff」クラスに NSMutableArray (またはそれ自体の配列) からデータを取得する方法と、最善の方法と考えられる方法です。Key Value Coding、Bindings、Core Data などの概念は知っていますが、それらに慣れていないため、学習したくなく、自分のニーズに合わないことに気づきません。

ここで何をすべきか、どのように始めるべきかについての助けをいただければ幸いです。

4

1 に答える 1

-1

If your app is dealing with just one (or very few) arrays, you can easily write them to NSUserDefaults in one class and then retrieve them from the other class. Once retrieved, you can change it how you like and write it back to NSUserDefaults. This has the added benefit of persisting your data on the device from one session to another. Some might say this is overkill, but for small amounts of data, it works very nicely.

write to NSUserDefaults:

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

//Change this line depending on object you arr saving (eg Array)
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstHome"];

[standardUserDefaults synchronize];

get from NSUserDefaults:

NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];

//Change this line depending on object you are saving (eg Array)
BOOL tempBOOL = [standardUserDefaults integerForKey:@"firstHome"];

There are definitely other options, but something like CoreData is overkill for just one array of links.

于 2013-08-22T16:45:36.737 に答える