瀏覽代碼

增加新建目录前的判断

gaosboy 12 年之前
父節點
當前提交
c8abf63a27
共有 2 個文件被更改,包括 10 次插入7 次删除
  1. 3 3
      Demo/KCHMainViewController.m
  2. 7 4
      Kache/KHolder.m

+ 3 - 3
Demo/KCHMainViewController.m

@@ -52,15 +52,15 @@
     
     self.banner = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 10.0f, 320.0f, 20.0f)];
     self.banner.backgroundColor = [UIColor clearColor];
-    self.banner.textAlignment = UITextAlignmentCenter;
+    self.banner.textAlignment = NSTextAlignmentCenter;
     self.banner.font = [UIFont boldSystemFontOfSize:18];
     [self.view addSubview:self.banner];
     
     self.body = [[UILabel alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 300.0f, 410.0f)];
     self.body.backgroundColor = [UIColor clearColor];
     self.body.numberOfLines = 0;
-    self.body.lineBreakMode = UILineBreakModeWordWrap;
-    self.body.textAlignment = UITextAlignmentLeft;
+    self.body.lineBreakMode = NSLineBreakByCharWrapping;
+    self.body.textAlignment = NSTextAlignmentLeft;
     self.body.text = @"";
     [self.body sizeToFit];
     self.body.frame = CGRectMake(0.0f, 0.0f, 300.0f, self.body.bounds.size.height);

+ 7 - 4
Kache/KHolder.m

@@ -65,10 +65,13 @@
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES);
 	NSString *libDirectory = [paths objectAtIndex:0];
 	NSString *path = [libDirectory stringByAppendingPathComponent:Kache_Objects_Disk_Path];
-    [self.fileManager createDirectoryAtPath:path
-                              withIntermediateDirectories:YES
-                                               attributes:nil
-                                                    error:nil];
+    BOOL isDirectory = NO;
+    if (! [[NSFileManager defaultManager] fileExistsAtPath:path isDirectory:&isDirectory]) {
+        [self.fileManager createDirectoryAtPath:path
+                                  withIntermediateDirectories:YES
+                                                   attributes:nil
+                                                        error:nil];
+    }
     NSMutableArray *copiedKeys = [self.keys mutableCopy];
     while (0 < [copiedKeys count]) {
         // 归档至阈值一半的数据