Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to determining the current version of a versioned CoreData model #364

Merged
merged 2 commits into from
Aug 2, 2018

Conversation

rpassis
Copy link
Contributor

@rpassis rpassis commented Jul 30, 2018

The current implementation for generating versioned CoreData models and selecting the current active version uses alphabetical sorting. This can work for most simple projects but is likely to break for less conventional setups.

A better solution is to parse the .xccurrentversion file which is included inside the CoreData versioned model. This file is in plist format and is created automatically by Xcode.

This is a fix for issue #362

@rpassis
Copy link
Contributor Author

rpassis commented Jul 30, 2018

One thing to note is that the alphabetical order implementation here will break even for very basic use cases. A very simple versioned model could look like this

Model.xcdatamodel
Model 1.xcdatamodel
Model 2.xcdatamodel

When applying the existing sort logic and taking the last item as the current CoreData model you will end up with

Model 1.xcdatamodel
Model 2.xcdatamodel
Model.xcdatamodel

And Model.xcdatamodel incorrectly set as the current version.

I'd suggest we should just remove the alphabetical fallback completely but I can't be certain that all CoreData models do include a .xccurrentversion file indicating what the current version is (based on my own tests it does but this doesn't seem to be documented anywhere).

@rpassis rpassis changed the title Improvements to determining the current version of a versioned CoreData model Improvements to determining the current version of a versioned CoreData model (fix #362) Jul 30, 2018
@rpassis rpassis changed the title Improvements to determining the current version of a versioned CoreData model (fix #362) Improvements to determining the current version of a versioned CoreData model Jul 30, 2018
Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rpassis, looks great!

fileReferencesByPath[fileReferenceKey] = versionGroup
return versionGroup
} else {
guard path.extension == "xcdatamodeld" else {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we keep the if as opposed to the guard? Not being a xcdatamodeld is not a failing case, and we may handle other filetypes differently in the future as well.
Additionally it will make these diffs easier to read.

@rpassis
Copy link
Contributor Author

rpassis commented Jul 31, 2018

@yonaskolb thanks for the feedback! I've addressed your comment and pushed a new commit.

Copy link
Owner

@yonaskolb yonaskolb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @rpassis!

@yonaskolb yonaskolb merged commit 907e276 into yonaskolb:master Aug 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants