Comments (4)
The normal way to use TLIPT with Core Data is:
- Don't specify an
identifierKeyPath
. By default, TLIPT identifies managed object by theirobjectID
. - Call
[NSManagedObjectContext obtainPermanentIDsForObjects:error:]
on newly created objects to prevent the ID from changing when the object is saved.
Can you do that?
from tlindexpathtools.
Wowie. In short, yes, I could.
If in the eyes of TLIPT what I've done is somehow really stupid (which I don't think is, given that identifierKeyPath:
is a part of the TLIPT API) then fair enough, I'll just stick to that opinionated use with Core Data.
The surprising crash behaviour is also seen in #22 — may be the thing that's more effective than investing any to fix the issue is just to provide more useful error messages.
I see TLIPT as a dependable component that connects data to my UI, and so to get crashes from it is really unsettling. When it works though it works beautifully, so thanks for that. =]
If only I had the time to delve into TLIPT's internals and philosophy + a workflow for submitting patches (from Cocoapods it's not trivial) I'd love to contribute back. For now I'm satisfied with the workaround.
That's not to say this issue doesn't need addressing!
from tlindexpathtools.
TLIPT provides multiple ways to identify objects. From the API documentation:
TLIndexPathDataModel
needs to be able to identify items in order to keep an internal
mapping between items and index paths and to track items across versions of the data
model. It does not assume that the item itself is a valid identifier (for example,
if the item doesn not implementNSCopying
, it cannot be used as a dictionary key).
So the following set of rules are used to locate a valid identifier. Each rule
is tried in turn until a non-nil value is found:
- If
identifierKeyPath
is specified (through an appropriate initializer),
the data model attempts to use the item's value for this key path. If the key
path is invalid for the given item, the next rule is tried.- If the item is an instance of
TLIndexPathItem
, the value of theidentifier
property is tried.- If the item is an instance of
NSManagedObject
, theobjectID
property is used.- If the item conforms to
NSCopying
, the item itself is used.- If all else fails, the item's memory address is returned as a string.
The default behavior works in for the most common cases, but ultimately, the onus is on you to select an appropriate identifier. If you choose to use identifierKeyPath
then you must ensure that the value doesn't change throughout the object's lifecycle.
I'm not sure there's an issue to fix here other than touching up the documentation.
from tlindexpathtools.
The point is, TLIPT shouldn't crash and burn if those conditions are not satisfied. A more helpful error, rather than documentation, is the fix.
i.e. with respect I don't think leaving codepaths to error states in the form of NSInvalidArgumentException
thrown from [__NSArrayM insertObject:atIndex:]
inside of TLIPT is a good idea, when all the user really needs to get going again is a pointer back to the documentation, or indeed, #31, this discussion.
#22 is related — the difference there is that it's not a crash that happens in TLIPT, but an eventual consistency problem in CollectionView (just as ugly, really).
For this one, onus may be on the user to select the correct identifier but I think you'll agree it's the onus of TLIPT not do throw NSArray index out of bounds exceptions under any circumstances. That's the responsibility of Foundation
;)
from tlindexpathtools.
Related Issues (20)
- TLCollectionViewController with fetchRequest delete NSManagedObject fault crash HOT 2
- Changing the TLIndexPathDataModel while animations under way causes crash HOT 1
- DataModel+IndexPathUpdates do not detect modified Core Data model objects HOT 2
- Realm HOT 3
- Same item in multiple sections: Possible? HOT 2
- Swift support HOT 4
- Warning : Duplicate Item Ignored (Noob Question) HOT 2
- Wrong optionality on controller: willUpdateDataModel: HOT 2
- Swift support HOT 1
- Swift Implementation Question HOT 2
- TLCollapsibleTableViewController
- Crash when reordering items HOT 2
- Unable to get dynamic height working HOT 4
- Cocoa Pod HOT 2
- TLTreeTableViewController: Keep only one expanded parent (close others) HOT 2
- NSManagedObject changes not detected by TLIndexPathController HOT 19
- Analysis Warning -- FYI HOT 1
- Another Suggestion Needed : Boxing Swift Structs HOT 4
- Non-ideal hash calculation HOT 3
- Drawback in case of adding dynamic data from API in multilevel expandable tableview/accordion HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tlindexpathtools.