mysterioustrousers / MTMigration

Manages blocks of code that only need to run once on version updates in iOS apps.
BSD 2-Clause "Simplified" License
914 stars 50 forks source link

Adding a hasAppBeenUpdated property #21

Open ChocoChipset opened 9 years ago

ChocoChipset commented 9 years ago

I came across the following scenario:

I have a cache file that I would like to flush on every app update. With the current implementation MTMigration it currently looks like:

[MTMigration applicationUpdateBlock:^{
    flushCache();
}];

if (isCacheAvailable) {    // (1)
    loadCache();
} else {
    writeCache();
}

However, unless a synchronization method is introduced, there is no guarantee that the cache file will be flushed before (1).

Adding a hasAppBeenUpdated property would allow the synchronous execution of code in an easier way:

if (isCacheAvailable && 
    [MTMigration hasAppBeenUpdated] == NO) {
    loadCache();
} else {
    writeCache();
}

Let me know what you think, @pwightman

revolter commented 9 years ago

Why not move the if and else blocks inside the applicationUpdateBlock's completion block?