您的位置:首页 > 其它

创建并且获取图片沙盒路径

2015-08-30 16:06 190 查看
关键代码:


//创建并且获取图片沙盒路径


func imageFilePath(imageUrl :
NSString) ->
String

{


//找到caches文件夹


var cachesPath:
AnyObject? = (NSSearchPathForDirectoriesInDomains(NSSearchPathDirectory.CachesDirectory,
NSSearchPathDomainMask.UserDomainMask,
true)
as
NSArray).lastObject


//创建图片文件夹


var downloadImagesPath :
String
= cachesPath!.stringByAppendingPathComponent("DownloadImages")


//初始化一个文件管理器


var fileManager =
NSFileManager.defaultManager()


//判断是否存在

如果不存在创建


if (!fileManager.fileExistsAtPath(downloadImagesPath))

{

fileManager.createDirectoryAtPath(downloadImagesPath, withIntermediateDirectories:
true, attributes:
nil, error:
nil)

}


//将url中的
/
转成 _


var imageName = imageUrl.stringByReplacingOccurrencesOfString("/",
withString:
"_")


var imageFilePath = downloadImagesPath.stringByAppendingPathComponent(imageName)
as
NSString;


return imageFilePath

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: