Conversation
09c9afb to
cedd0a5
Compare
mokagio
left a comment
There was a problem hiding this comment.
I refined the implementation to avoid changing the way existing consumers of the library store the DB.
@jleandroperez @jkmassel can I ask you for a new round of review?
| @property (nonnull, nonatomic, strong) NSManagedObjectContext *managedObjectContext; | ||
| @property (nonnull, nonatomic, strong) NSManagedObjectModel *managedObjectModel; | ||
| @property (nonnull, nonatomic, strong) NSPersistentStoreCoordinator *persistentStoreCoordinator; |
There was a problem hiding this comment.
I had to add the annotation here too to avoid warnings. It makes the diff a bit noisier but it's good to have it anyways.
The implementation of all those getters makes sure they are not nil, or rather, fails if they are, so nonnullable seemed appropriate.
There was a problem hiding this comment.
Yup that's the perfect approach Gio!
| /// the app is running and where to save the store. | ||
| /// | ||
| /// The `super` `init` method defaults to `false` for backward compatibility. | ||
| - (nonnull instancetype)initWithSandboxedMode:(BOOL)sandboxed NS_DESIGNATED_INITIALIZER; |
There was a problem hiding this comment.
I wonder whether the parameter should be an enum instead:
_ = TracksContextManager(storeLocation: .applicationSupport)
// or
_ = TracksContextManager(storeLocation: .documents)I'm on the fence and might sit overnight. Regardless, because the changes doesn't affect existent consumers thanks to the init override below, I think it's okay to merge this as it is and then I can follow up with a refactor if we think it's worth it.
There was a problem hiding this comment.
To be entirely honest, I would keep the initializer simple, and just switch to the Application Support folder.
Something in the lines of:
- If a
Documentsfolder already exists, use it - Otherwise, check if a folder in
Applications Supportexists, and use it - If none of the above, create a new folder in
Applications Support
WYDT?
There was a problem hiding this comment.
I'm ok with either approach. I like how pretty the enum is, but I like how much work @jleandroperez's isn't 😄
|
|
||
| - (instancetype)initWithSandboxedMode:(BOOL)sandboxed { | ||
| self = [super init]; | ||
| if (!self) { return nil; } |
There was a problem hiding this comment.
This should never happen so I defined the initializer as nonnullable. In Swift land, that would be the case.
There was a problem hiding this comment.
Standard ObjC, exactly!
jleandroperez
left a comment
There was a problem hiding this comment.
@mokagio sir!! Few changes suggested:
- Initializer fix (would prevent leaking memory)
- ApplicationSupport API simplification (not required, not a blocker either!!)
As per the initializer detail, 10000% up to you!
- Taking that parameter isn't a problem at all
- It can be solved without specifying if we're sandboxed or not, as well. Yet another alternative, is to just always use the Application Support path, and migrate legacy databases, if needed
I would take the easiest path. As usual 😄
| @implementation TracksContextManager | ||
|
|
||
| - (instancetype)init { | ||
| return [[TracksContextManager alloc] initWithSandboxedMode:true]; |
There was a problem hiding this comment.
This initializer returning a new instance, rather than the one being initialized.
You would typically instantiate a Context Manager like this:
TracksContextManager *manager = [[TracksContextManager alloc] init];
allocreserves memory for the objectinitis expected to initialize the instance
In this case, init is alloc'ating more memory, and returning yet another instance.
There was a problem hiding this comment.
Thank you for this! Gosh 😳 I'm really rusty at writing Objective-C 🤦
I felt like there was something wrong with that, but it compiled and the tests passed so I shrugged it off.
Interestingly, Xcode also gives me a warning about it
It either came after I wrote the code and moved on or after I added the NS_DESIGNATED_INITIALIZER annotation. Regardless, I shouldn't have missed it... 😳
| abort(); | ||
| } | ||
|
|
||
| return applicationSupportURL; |
There was a problem hiding this comment.
You can proooobably simplify this API as follows:
NSURL *appSupportURL = [[[NSFileManager defaultManager] URLsForDirectory:NSApplicationSupportDirectory inDomains:NSUserDomainMask] lastObject];
(The Application Support path is expected to always be there!)
|
Thanks @jleandroperez for the great review! Regarding the init, I like the idea of keeping it simple and eventually migrate everything to Application Support. I haven't tried, but I think that even to just check whether a file exists in the Documents folder from a non-sandboxed app, macOS would request the user for permission. If that's the case, then we'd be back to square one, because the real aim of this change is avoid that behavior in non-sandboxed apps. I really like the migration idea, but I think it needs more experimenting and might be best for a dedicated PR. |
jleandroperez
left a comment
There was a problem hiding this comment.
@mokagio One tiny comment sent away (apologies I missed that!!).
Other than that, please
when ready!!
| return [self applicationSupportURLForContainerApp]; | ||
| } else { | ||
| return [self applicationDocumentsDirectory]; | ||
| } |
There was a problem hiding this comment.
@mokagio Is it possible this logic is inverted? (sandboxed > Documents Directory?).
Otherwise non sandboxed apps would still trigger the Documents Folder alert perhaps?
There was a problem hiding this comment.
You are totally right!
I didn't notice because the tests were inverted, too 🤦♂️
fcfec20 to
aeb61db
Compare
|
😫 I feel like I'm in a deadlock... There's some inconsistent issue with the tests, which doesn't happen with the Xcode 12, but I can't upgrade to Xcode 12 because the pod validation fails. Inconsistent as in this: |
aeb61db to
9eb9300
Compare
9eb9300 to
a074e1f
Compare
a074e1f to
61a05f6
Compare
This will allow us to add the conditional logic for the sandbox vs non-sandbox location later on.
We'll need this later to make the custom init with the sandbox mode flag non-nullable.
This should have always been the case, but somehow I got confused and didn't realize my mistake. Thanks @jleandroperez for picking this up! Goes to show that tests are only good when written properly! https://github.com/Automattic/Automattic-Tracks-iOS/pull/147/files/3e38df8087e7b38a76b45acc5e89527746b4145b#r498830462
61a05f6 to
9d50fde
Compare
|
For the record, Cocoapods had issues finding the Sodium-Fork framework. Workaround involved running Thank you Gio!! |


See #146.
This is just a test to verify my internal non-sandboxed macOS app works fine when using Application Support.Update: we decided to merge this change, but in a way that wouldn't change the behavior of Simplenote macOS.
To test these changes: