{"id":20838824,"url":"https://github.com/royalicing/glaarrayediting","last_synced_at":"2026-05-30T10:31:36.418Z","repository":{"id":22299790,"uuid":"25634657","full_name":"RoyalIcing/GLAArrayEditing","owner":"RoyalIcing","description":"Editable array for Cocoa/Touch models with convenient interface and friendly implementation","archived":false,"fork":false,"pushed_at":"2015-05-05T03:12:42.000Z","size":316,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-18T23:44:08.809Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RoyalIcing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-23T11:57:37.000Z","updated_at":"2015-05-05T03:12:44.000Z","dependencies_parsed_at":"2022-08-20T05:21:09.671Z","dependency_job_id":null,"html_url":"https://github.com/RoyalIcing/GLAArrayEditing","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FGLAArrayEditing","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FGLAArrayEditing/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FGLAArrayEditing/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RoyalIcing%2FGLAArrayEditing/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RoyalIcing","download_url":"https://codeload.github.com/RoyalIcing/GLAArrayEditing/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243196663,"owners_count":20251861,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T01:11:37.943Z","updated_at":"2025-12-17T11:09:29.020Z","avatar_url":"https://github.com/RoyalIcing.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"GLAArrayEditing\n===============\n\n## Convenient and powerful API, simple implementation\n\nIf you need a reorderable list of items in your application, you can use a raw `NSMutableArray`, implement the key-value-observing compatible methods, or write custom methods to perform the same concepts again and again of adding, removing, replacing, and reordering.\n\nThe **GLAArrayEditing** protocol allows you to present a powerful, consistent, and safe interface for any array of items in your public API. Behind the scenes **GLAArrayEditor** allows your implementation to be just two methods: one to copy items and one to edit.\n\n### Get changes\n\nUse the `-changesMadeInBlock:` method of `GLAArrayEditor` to track the added, removed, or replaced objects. Its return value provides access these combined changes as simple properties.\n\n### Indexers\n\nIndexers allow array items to be looked up quickly by key. Any changes to the array update the index efficently.\n\n### Stores\n\nThe `GLAArrayEditor` class supports stores, so your list of items can be loaded from disk, and also automatically saved after any changes. For using Mantle objects stored as JSON, see the [GLAArray-Mantle respository.](https://github.com/BurntCaramel/GLAArray-Mantle)\n\n### Table View Dragging\n\nUse the `GLAArrayTableDraggingHelper` to easily enable rearranging in your `\u003cGLAArrayEditing\u003e`-supported table data source.\n\nYou can easily create your own classes that conform to the `GLAArrayEditing` protocol.\n\n## Example\n\n### Your public model API\n\n```objective-c\n@interface ExampleObjectWithListOfCollections : NSObject\n\n// The simple public API:\n- (NSArray *)copyCollections;\n- (void)editCollectionsUsingBlock:(void (^)(id\u003cGLAArrayEditing\u003e collectionListEditor))block;\n\n// Or the more convenient public API.\n// Set .changeCompletionBlock on the result from -useCollections to update when the collections change.\n- (id\u003cGLALoadableArrayUsing\u003e)useCollections;\n\n@end\n\nextern NSString *ExampleObjectWithListOfCollectionsCollectionsDidChangeNotification;\n```\n\n### Your implementation\n\n```objective-c\n@interface ExampleObjectWithListOfCollections ()\n\n@property(nonatomic) GLAArrayEditor *collectionsArrayEditor;\n\n@end\n\n@implementation ExampleObjectWithListOfCollections\n\n- (NSArray *)copyCollections\n{\n\treturn [(self.collectionsArrayEditor) copyChildren];\n}\n\n- (void)editCollectionsUsingBlock:(void (^)(id\u003cGLAArrayEditing\u003e collectionListEditor))block\n{\n\tGLAArrayEditor *arrayEditor = (self.collectionsArrayEditor);\n\tGLAArrayEditorChanges *changes = [arrayEditor changesMadeInBlock:block];\n\t\n\t// Now respond to the changes made:\n\t// Added:\n\t// changes.addedChildren\n\t// Removed:\n\t// changes.removedChildren\n\t// Replaced\n\t// changes.replacedChildrenBefore\n\t// changes.replacedChildrenAfter\n\t\n\t[[NSNotificationCenter defaultCenter]\n\t\tpostNotificationName:ExampleObjectWithListOfCollectionsCollectionsDidChangeNotification\n\t\tobject:self\n\t];\n}\n\n- (id\u003cGLALoadableArrayUsing\u003e)useCollections\n{\n\tGLAArrayEditorUser *arrayEditorUser = [[GLAArrayEditorUser alloc] initWithLoadingBlock:^GLAArrayEditor *(BOOL createAndLoadIfNeeded) {\n\t\treturn (self.collectionsArrayEditor);\n\t} makeEditsBlock:^(GLAArrayEditingBlock editingBlock) {\n\t\t[self editCollectionsUsingBlock:editingBlock];\n\t}];\n\t\n\t// Observes all edits, not just the ones done by this 'user'.\n\t[arrayEditorUser\n\t\tmakeObserverOfObject:self\n\t\tforChangeNotificationWithName:ExampleObjectWithListOfCollectionsCollectionsDidChangeNotification\n\t];\n\n\treturn arrayEditorUser;\n}\n\n- (instancetype)init\n{\n    self = [super init];\n    if (self) {\n        _collectionsArrayEditor = [GLAArrayEditor new];\n    }\n    return self;\n}\n\n@end\n\nNSString *ExampleObjectWithListOfCollectionsCollectionsDidChangeNotification =\n@\"ExampleObjectWithListOfCollectionsCollectionsDidChangeNotification\";\n```\n\n## The GLAArrayEditing methods\n\n```objective-c\n@protocol GLAArrayInspecting \u003cNSObject\u003e\n\n@property(readonly, nonatomic) NSUInteger childrenCount;\n\n- (NSArray *)copyChildren;\n- (id)childAtIndex:(NSUInteger)index;\n- (NSArray *)childrenAtIndexes:(NSIndexSet *)indexes;\n\n- (NSArray *)resultsFromChildVisitor:(GLAArrayChildVisitorBlock)childVisitor;\n\n// Working with unique children\n- (id)firstChildWhoseKey:(NSString *)key hasValue:(id)value;\n- (NSUInteger)indexOfFirstChildWhoseKey:(NSString *)key hasValue:(id)value;\n- (NSIndexSet *)indexesOfChildrenWhoseResultFromVisitor:(GLAArrayChildVisitorBlock)childVisitor hasValueContainedInSet:(NSSet *)valuesSet;\n\n- (NSArray *)filterArray:(NSArray *)objects whoseResultFromVisitorIsNotAlreadyPresent:(GLAArrayChildVisitorBlock)childVisitor;\n\n@end\n\n\n@protocol GLAArrayEditing \u003cGLAArrayInspecting\u003e\n\n- (void)addChildren:(NSArray *)objects;\n- (void)insertChildren:(NSArray *)objects atIndexes:(NSIndexSet *)indexes;\n- (void)removeChildrenAtIndexes:(NSIndexSet *)indexes;\n- (void)replaceChildrenAtIndexes:(NSIndexSet *)indexes withObjects:(NSArray *)objects;\n- (void)moveChildrenAtIndexes:(NSIndexSet *)indexes toIndex:(NSUInteger)toIndex;\n\n- (void)replaceAllChildrenWithObjects:(NSArray *)objects;\n\n- (BOOL)removeFirstChildWhoseKey:(NSString *)key hasValue:(id)value;\n\n- (id)replaceFirstChildWhoseKey:(NSString *)key hasValue:(id)value usingChangeBlock:(id (^)(id originalObject))objectChanger;\n\n@end\n\n\n@protocol GLALoadableArrayUsing \u003cNSObject\u003e\n\n@property(copy, nonatomic) GLAArrayInspectingBlock changeCompletionBlock;\n\n@property(readonly, nonatomic) BOOL finishedLoading;\n\n- (NSArray *)copyChildrenLoadingIfNeeded;\n- (id\u003cGLAArrayInspecting\u003e)inspectLoadingIfNeeded;\n- (void)editChildrenUsingBlock:(GLAArrayEditingBlock)block;\n\n@property(nonatomic) id representedObject;\n\n@end\n```\n\n## Origin\n\nThis was made during the creation of [my file management app Blik](http://www.burntcaramel.com/blik/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fglaarrayediting","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Froyalicing%2Fglaarrayediting","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Froyalicing%2Fglaarrayediting/lists"}