nsfilemanager

How to use persist & retrieve an NSCoding compliant object to app Document directory in Swift 3?

核能气质少年 提交于 2019-12-01 12:07:35
Here's a NSCoding compliant object. I would like to save and recover it from the app's documents directory in Swift 3. I imagine it's a save method and recover method. How is this done? import Foundation class Book: NSObject, NSCoding { var title: String var author: String var pageCount: Int var categories: [String] var available: Bool init(title:String, author: String, pageCount:Int, categories:[String],available:Bool) { self.title = title self.author = author self.pageCount = pageCount self.categories = categories self.available = available } // MARK: NSCoding required convenience init?

Copy / Backup Persistent Store

梦想与她 提交于 2019-12-01 11:18:45
问题 Normally when I backed up the core data file for my app, I would just copy the .sqlite file to another location while the app was running. But now that journaling (wal) is enabled, this does not work anymore. I cannot see a way for NSPersistentStoreCordinator or NSManagedObjectContext to write a new file. I'm guessing maybe I have 2 methods: Close the persistent store and opening it again with @{@"journal_mode" : @"DELETE"} and then copy the .sqlite file. Add another persistent store and

How to use persist & retrieve an NSCoding compliant object to app Document directory in Swift 3?

六眼飞鱼酱① 提交于 2019-12-01 10:42:00
问题 Here's a NSCoding compliant object. I would like to save and recover it from the app's documents directory in Swift 3. I imagine it's a save method and recover method. How is this done? import Foundation class Book: NSObject, NSCoding { var title: String var author: String var pageCount: Int var categories: [String] var available: Bool init(title:String, author: String, pageCount:Int, categories:[String],available:Bool) { self.title = title self.author = author self.pageCount = pageCount self

Does File Attribute contain millisecond? Objective-C

给你一囗甜甜゛ 提交于 2019-12-01 10:36:38
I would like to get milliseconds from creation time of file attribute When I get file attribute, I use NSDateFormatter to convert file creation time (NSDate) to NSString. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SS: A"]; ss --> seconds SS --> should be millisecond A --> milliseconds of the date I get 00 for SS and get 54487000 for A. I notice that the last three digits are always zero for NSDate come from file attribute of any files. But when I use the same formatter with the NSDate come from [NSDate date], the last three digits are not zero for A, and SS digit is not always zero.

CPU raises with attributesOfItemAtPath:error:

☆樱花仙子☆ 提交于 2019-12-01 10:23:36
问题 I am using [NSFileManager attributesOfItemAtPath:error:] function for fetching attributes of file. But sometimes my application cpu is going upto 100%. I am using this function for 100k(approx.) files. Sample of my application: 2128 -[NSFileManager attributesOfItemAtPath:error:] 2128 +[NSFileAttributes _attributesAtPath:partialReturn:filterResourceFork:error:] 2123 _attributesAtPath 2072 listxattr 29 realloc 18 realloc 11 szone_size 22 _attributesAtPath 5 _sysenter_trap Can anyone please help

Does File Attribute contain millisecond? Objective-C

拜拜、爱过 提交于 2019-12-01 10:07:07
问题 I would like to get milliseconds from creation time of file attribute When I get file attribute, I use NSDateFormatter to convert file creation time (NSDate) to NSString. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss:SS: A"]; ss --> seconds SS --> should be millisecond A --> milliseconds of the date I get 00 for SS and get 54487000 for A. I notice that the last three digits are always zero for NSDate come from file attribute of any files. But when I use the same formatter with the NSDate

Able to write/read file but unable to delete file SWIFT

半腔热情 提交于 2019-12-01 09:33:11
I store an .jpg image i the iOS documents directory. I can write files and read files but when it comes to deleting them it says that there is no such file but that cannot be because I can read it with the same url. Reading: let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let path = NSURL(fileURLWithPath: paths[0] as String) let fullPath = path.appendingPathComponent(info["pi"] as! String) let data = NSData(contentsOf: fullPath!) Deleting: let fileManager = FileManager.default fileManager.delegate = self let paths = NSSearchPathForDirectoriesInDomains

How to get Remote File Last-Modification Date

筅森魡賤 提交于 2019-12-01 07:07:30
问题 I need to get the file modification date of a remote file. Obviously, attributes in this example returns NULL : - (BOOL) fileHasBeenModifiedSinceLastLaunch { NSError * err = nil; NSDictionary * attributes = [FILEMANAGER attributesOfItemAtPath:[NSURL URLWithString:@"http://www.wrightscs.com/some_file.txt"] error:&err]; NSString * modified = [NSString stringWithFormat:@"%@",[attributes objectForKey:@"NSFileModificationDate"]]; NSString * savedmod = [[NSUserDefaults standardUserDefaults]

NSFileProtectionComplete for iOS 4.0 apps

孤人 提交于 2019-12-01 05:53:23
I saw a WWDC 2010 video about NSFileProtectionComplete and protecting app's data. Are there any examples out there? Does any one have sample code to share? See the NSFileManager class doc: The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting. It's basically file vault for individual files. You just pass the constant when you set the file attributes. To mark a file as protected, you must add an extended attribute to it. The Foundation framework includes two ways to add this attribute: When writing the contents of an NSData

How to save images and recorded files in temp directory?

不问归期 提交于 2019-12-01 05:10:39
I want to store pictures taken from camera and video recordings from my application in a separate folder in temporary directories for a while. And as the task is being completed, they shall be going to save into the database. How do I save pictures taken from camera & video recording files in a separate folder in temp directories? You are looking for this to get tot he caches folder to store temporary files: NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject]; From there you can use NSFileManager to create and remove the directories you