创建并且获取图片沙盒路径
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
}
//创建并且获取图片沙盒路径
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
}
相关文章推荐
- codeforces Codeforces Round #318 div2 A. Bear and Elections 【优先队列】
- 对集合应用符号 | & ^ -
- Activity的启动模式
- 详解C++右值引用
- VS用OLE方式对Excel进行读写操作
- 初学者如何创建 Git 仓库(使用 sourceTree)
- 垃圾收集器与内存分配策略
- [leetcode]Ugly Number C语言
- MySQL索引 查看、创建、删除
- 正则表达式学习
- C++STL 库中set容器应用
- nginx编译选项的选择----nginx的学习之路
- UVa 1262 - Password(组合数)
- 编译错误解决NO architectures to compile for。。。
- leetcode 019_Valid Parentheses
- Linux系统启动流程
- JVM内存管理机制
- 转发离线安装 Android Studio 更新
- TreeSet是可以对字符串进行排序 的, 因为字符串已经实现了Comparable接口。
- Java I/O输入输出流