请帮助
以下是代码
@IBAction func btnMakeFolder(sender: AnyObject) {
var checkFoundAlbum:Bool = false // for check the folder if is found it or not
let c = NSCharacterSet.whitespaceCharacterSet()
if folderNameTextField.text?.stringByTrimmingCharactersInSet(c) != "" {
let fileManager = NSFileManager.defaultManager()
do {
let document = try fileManager.URLForDirectory(.DocumentDirectory, inDomain: .UserDomainMask, appropriateForURL: nil, create: false)
// her i check the album is he exists or not
let getFolders = try fileManager.contentsOfDirectoryAtURL(document, includingPropertiesForKeys: nil, options: .SkipsHiddenFiles)
for folder in getFolders {
if folder.lastPathComponent!.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) == folderNameTextField.text!.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet()){
checkFoundAlbum = true
}else {
checkFoundAlbum = false
}
}
// her for create folder and display the alert for the user
if checkFoundAlbum == false{
let folderUrl = document.URLByAppendingPathComponent(folderNameTextField.text!)
try fileManager.createDirectoryAtURL(folderUrl, withIntermediateDirectories: true, attributes: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}else {
let alertController = UIAlertController(title: "Album Exists", message: "This Album Already Exists,Please Change The Name", preferredStyle: .Alert)
let alertAction = UIAlertAction(title: "OK", style: .Default, handler: { (alertAction:UIAlertAction) in
})
alertController.addAction(alertAction)
self.presentViewController(alertController, animated: true, completion: nil)
}
}catch {
print(error)
}
}else {
alert()
}
}
答案 0 :(得分:0)
我建议在实际设备上尝试此代码 - 假设模拟器的基础文件系统使用HFS +,iOS模拟器通常不区分大小写。