1

我正在编写一个简单的 Cocoa 应用程序,它采用一些文件 URL(通过拖放),然后对这些文件进行处理。我有一个控制拖放机制的类(NSView 的子类),并通过 Interface Builder(使用“自定义类”选项)分配给 NSView。文件 URL 进入 NSMutableArray。

然后我有另一个类应该接受这些文件 URL 并用它们做一些事情。这个类还有一个连接到调用“do stuff”方法的 NSButton 的 IBAction。

我的问题是,我怎样才能以及什么被认为是最好的方法,将数据从 NSMutableArray(或其自身的数组)从“拖放”类获取到“做事”类。我知道键值编码、绑定和核心数据等概念,但是我不熟悉它们,不想学习并意识到它不适合我的需求。

任何关于我应该在这里做什么以及我应该如何开始的帮助将不胜感激。

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 回答