Reputation: 136
I would like to have folders (virtual) for objects in this iOS app. Also, I want users to be able to create their own folders. I am thinking about making an NSMutableArray that would contain dictionaries with unique keys and NSString objects for the folder names. The objects would have a variable that would point to the dictionary key. This way, the folders name can be changed and not affect the contents of the folder. I have thought of quite a few ways to implement this.
What are some best practices in my situation?
Upvotes: 0
Views: 123
Reputation: 47241
I'd go for a simple tree structure with this base class:
@interface Folder
{
NSString *folderName;
NSArray *contents;
}
@property (nonatomic, copy) NSString *folderName;
@property (nonatomic, retain) NSArray *contents;
- (id)initWithName:(NSString *)aName;
// Adds a folder to this folder and returns a reference to it or nil if name is already present
- (Folder *)addFolderWithName:(NSString *)aFolderName;
// Add something, returns false if operation was unsuccessful, for example adding a folder with
// a name that has already been used in this folder
- (BOOL)addContent:(id)someContent;
@end
Contents could be of any type, whatever you need. The methods you need depend on how you like to use the tree. When it comes to trees there is alot possible :)
Upvotes: 1
Reputation: 6621
Use core data and associate the folder metadata with the filename. You'll have to do a lot of defensive coding, but if you use core data you can have arbitrary metadata, good performance, etc.
Upvotes: 0