gpt4 book ai didi

swift - 我的文档目录有问题

转载 作者:行者123 更新时间:2023-11-30 13:19:17 27 4
gpt4 key购买 nike

当我想在文档目录中创建文件夹时遇到问题当我第一次创建像文件夹(Hello)这样的文件夹时,当我尝试用小写字母创建另一个像(hello)这样的文件夹时,没有做任何事情并且文件夹没有创建,我不知道为什么?但如果我尝试用小空间创建文件夹(hello),那就可以了,它会显示在表格 View 上,我不知道为什么,如果有人可以检查文件夹 hello 和 Hello 是不同的

请帮忙

下面是代码

@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()
}
}

最佳答案

我建议在实际设备上尝试此代码 - iOS 模拟器通常不区分大小写,假设模拟器的底层文件系统使用 HFS+。

关于swift - 我的文档目录有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37923548/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com