nsfilemanager

FileManager.default.removeItem not removing file [duplicate]

被刻印的时光 ゝ 提交于 2019-12-01 04:20:36
This question already has an answer here: Objc save a file to the tmp/ with URL it is not working 1 answer UIImage(contentsOfFile:) returning nil despite file existing in caches directory [duplicate] 1 answer NSURL path vs absoluteString 2 answers I'm trying to remove a file from the documents directory using FileManager.default.removeItem but is not deleting the file on the simulator. Here is my code: if let dir = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first { do{ let path = dir.appendingPathComponent(file).absoluteString do{ try FileManager.default.removeItem(atPath

FileManager.default.removeItem not removing file [duplicate]

天涯浪子 提交于 2019-12-01 02:02:15
问题 This question already has answers here : Objc save a file to the tmp/ with URL it is not working (1 answer) UIImage(contentsOfFile:) returning nil despite file existing in caches directory [duplicate] (1 answer) NSURL path vs absoluteString (2 answers) Closed 2 years ago . I'm trying to remove a file from the documents directory using FileManager.default.removeItem but is not deleting the file on the simulator. Here is my code: if let dir = fileManager.urls(for: .documentDirectory, in:

Download font .ttf file from web and store on iPhone

半世苍凉 提交于 2019-11-30 18:38:29
问题 Is it possible to download .ttf file from web and store it on iPhone. Then use that for for labels and all other stuff ? Because my client want to control fonts from database and don't want to just drop fonts to xcode project right away. So in future if he wants to change font, he will add new font to database, app will recognize new font on web (thats already done with images, not a problem), download it and use as font. Thanks. 回答1: The fonts have to be set in the plist of your app, and

FileManager says file doesn't exist when it does

£可爱£侵袭症+ 提交于 2019-11-30 17:45:51
问题 I have a use case that requires a UIImage to be saved to the documents directory - then the UIImage needs to be converted into a PDF and saved to the documents directory. CODE TO CONVERT TO PDF var filePath = NSString(string: self.selectedMedia!.imagePath!) if FileManager().fileExists(atPath: filePath as String) { filePath = filePath.deletingPathExtension as NSString filePath = NSString(string: filePath.appendingPathExtension("PDF")!) if let image = UIImage(data: self.selectedMedia?.image! as

Getting bundle file references / paths at app launch

ぃ、小莉子 提交于 2019-11-30 16:53:53
Suppose I have an arbitrary set of files included in the Main App Bundle. I would like to fetch the file URLs for those at launch and store them somewhere. Is this possible using NSFileManager ? The documentation is unclear in that regard. Note: I only need the file URLs, I do not need to access the actual files. You can get the URL of a file in the main bundle using NSString *path = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"jpeg"]; NSURL *url = [NSURL fileURLWithPath:path]; You can write this URL to, for example, a property list file in the Documents directory: NSString

Open File Dialog crashes in Swift

大憨熊 提交于 2019-11-30 16:33:43
I would like to use the open file dialogs from NSFilemanager but my code crashes sometimes and sometimes works and I do not know why. Sometimes it works 100%, sometimes the window is empty, sometimes the background behind the dialog ist shown in the window. When a craash occurs, "signal:SIGABRT" is shown in Xcode. func openfiledlg (title: String, message: String) -> String { var myFiledialog: NSOpenPanel = NSOpenPanel() myFiledialog.prompt = "Öffnen" myFiledialog.worksWhenModal = true myFiledialog.allowsMultipleSelection = false myFiledialog.canChooseDirectories = false myFiledialog

Open File Dialog crashes in Swift

谁都会走 提交于 2019-11-30 16:19:00
问题 I would like to use the open file dialogs from NSFilemanager but my code crashes sometimes and sometimes works and I do not know why. Sometimes it works 100%, sometimes the window is empty, sometimes the background behind the dialog ist shown in the window. When a craash occurs, "signal:SIGABRT" is shown in Xcode. func openfiledlg (title: String, message: String) -> String { var myFiledialog: NSOpenPanel = NSOpenPanel() myFiledialog.prompt = "Öffnen" myFiledialog.worksWhenModal = true

NSFileManager watch directory

妖精的绣舞 提交于 2019-11-30 13:04:40
问题 How would you monitor a directory with NSFileManager ? I would like to able to detect when a file is deleted/added in my documents directory while my app is running. 回答1: Look Kernel Queues: An Alternative to File System Events in Apple documentation. There is an example for iOS in AVPlayerDemo (look DirectoryWatcher class). Also, check Directory Monitor blog post. 回答2: Here's my version of DirectoryWatcher written in Swift using GCD instead of Mach and using a closure instead of a delegate

NSFileManager - Check file size?

℡╲_俬逩灬. 提交于 2019-11-30 11:28:14
I am recording sound file in one of my apps. I am trying to figure out how to get the file size of the recorded file? I know how to get it and it's path, I just can not figure out how to get the file size. Thanks Shani you can use : - (NSDictionary *)attributesOfItemAtPath:(NSString *)path error:(NSError **)error to get the file property dictionary and can fetch [dictObject valueForKey@"NSFileSize"]; 来源: https://stackoverflow.com/questions/8844044/nsfilemanager-check-file-size

How to create directory using Swift code (NSFileManager)

ⅰ亾dé卋堺 提交于 2019-11-30 11:17:20
问题 I'm having some trouble with converting Objective-C code to create a directory for Swift. Objective-C: NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@"/MyFolder"]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath