How to check if an NSDocument has unsaved changes? - save

I know how to tell NSDocument that there are new changes, with -(void)updateChangeCount:. But, I can't find a method changeCount or something like this to check if an NSDocument has unsaved changes.
Is there a way to check that?

Are you looking for -[NSDocument isDocumentEdited]?

Related

Core Data attribute crawling as nil after renaming, even after I changed the name back

I foolishly renamed some Core Data entity attributes and ran the app, then realised files I opened were crashing because they did not have the same attribute, so I changed the name back.
However, the attributes I renamed are still crawling as nil even after I changed the name back. Is there any easy fix to this without migration? I'm 99% sure renaming them was the problem as the non-renamed attributes aren't nil. Files made after this also don't throw this error when I load them.
If it helps, I have an unedited copy of the older file, is there any way to swap it out with the current one? Would that work?
If you don't want to add migration, just remove and install the App.
But if you want to rename a property in already published App than you need to add lightweight migration.

How to check if a file is read only?

Neither io nor lfs seem to have an option to check for this. I need to use this feature to simulate some code that does this check.
It seems there's an undocumented permissions field in the table returned by lfs.attributes(). Thanks to #siffiejoe for pointing this out, didn't see it when I read the code.
Another approach is of course to try to read from the file, that will always work but might be slower.
You could also try opening the file and setting a (temporary, of course) read lock on it. Not sure about the portability of file locking in Lua, though.
Note: checking if a file is readable and then doing something can break due to race conditions; the permissions of a file can change between your check and the following action.

Is it safe to delete CFBundleInfoDictionaryVersion?

I don't want my info.plist to be cluttered. Is it safe to delete CFBundleInfoDictionaryVersion? I tried removing it and run and the app still works fine.
No, its not safe.
There's really not more to say here.
EDIT: See what does the InfoDictionary version signify in the information property list (plist file)? for an in-depth answer...

Migrating coreData to a clean start

I'm updating an app to a whole new version (remade). Everything is going to change to be faster and less bugy. As other post suggest I cannot create another version of the model since I don't have the app code to the previous version (I started a new project). All I have is the bundle identifier for it to be an update. I will use core data but I want to delete all the old models and old data for the users that are updating, as if they deleted the app and reinstall it. How do I achieve this? or there's no need to delete anything because is a different model? All i want is to prevent app crash on launch. thanks in advance.
If you tried to open the same persistent store file with a model that doesn't allow Core Data to make sense of it then you'd raise an exception. So probably all you need to do is use a different file — remember that you get to specify the on-disk location in addPersistentStoreWithType:configuration:URL:options:error: — for your persistent store and ask NSFileManager to delete the old one.
I don't think there's a penalty for asking to delete a file that already doesn't exist so no need for any particularly complicated logic. You'd just be duplicating what the file manager does internally anyway.
Alternatively, if you prefer to keep the same file, enclose your call to addPersistentStoreWithType:... in an #try/#catch block and in the #catch just delete the existing file and try the addPersistentStoreWithType:... a second time.

How to set permission for Folder in Blackberry ?

I want to know how to set permission for folder that is created by my app so no one can delete or see that folder.
I think this is not 100% possible, however you may do smth in this direction. Check for FileConnection.setHidden(boolean), FileConnection.setWritable(boolean) and FileConnection.setReadable(boolean).
First of all, the API docs are vague as to whether those methods will have any effect at all on a specific device (meaning a file system).
Secondly, even if you use FileConnection.setHidden(boolean), then it is still possible for another app to "see" your file/dir by using FileConnection.list(String filter, boolean includeHidden). Once one has a path of you hidden dir, he/she can change the hidden attr (and other attrs), so it becomes visible/readable/killable.

Resources