Anton
Anton

Reputation: 4018

iOS: How to determine which file is newer in iCloud (version vs last modified date)?

I know that I can get two pieces of information about an iCloud file: the version and last modified date. The question is, when I'm dealing with two iCloud files that have the same name, would it be better to use the version or last modified date to figure out which is more recent?

It seems to me like last modified date would theoretically be more accurate, but I see many tutorials saying the version should be used to compare two files to determine which one is newer.

I would like to know what the better practice is, and why.

Upvotes: 1

Views: 420

Answers (1)

Tom Harrington
Tom Harrington

Reputation: 70966

Last modified date is good when you're on a single computer and the system time is consistent. When you're working with iCloud you have at least three system times to think about-- the local time on at least two user devices, plus whatever the iCloud server thinks the time is. Even with NTP there's no guarantee of absolute synchronization.

NSFileVersion exists to get around this-- you can ask it for the latest version of a file, and it's supposed to find the right one. It might well have its own bugs that affect the accuracy of the result, but it's at least intended to get you the right answer regardless of time synchronization.

Upvotes: 1

Related Questions