一、oc如何將數據寫入到plist文件中
/**
*數組、字典只能將Bool
、NSNumber
、NSString
、NSData
、NSDate
、NSArray
、NSDictionary
寫入屬性列表plist文件
*/
NSValue *value = [NSValue valueWithRange:NSMakeRange(1, 5)];
NSDictionary *dic = @{@"key1":@12345,@"key2":@"tttxxx",@"key3":value};
NSString *homePath = NSHomeDirectory();
NSString *path = [homePath stringByAppendingPathComponent:@"t.plist"];
BOOL success = [dic writeToFile:path atomically:YES];
if (success) {
NSLog(@"write success");
}
二、拆分路徑
NSString *path = @"/Users/apple/testfile.text";
NSArray *pathComps = [path pathComponents];
NSLog(@"%@",pathComps);
屏幕快照 2016-05-26 下午2.12.51.png
三、計算一個目錄的容量大小
NSString *directPath = [homePath stringByAppendingPathComponent:@"test"];
NSDirectoryEnumerator *files = [fileManager enumeratorAtPath:directPath];
NSString *path = [files nextObject];
NSInteger fileNum = 0;
while (path != nil) {
NSLog(@"%@",path);
NSString *path2 = [directPath stringByAppendingPathComponent:path];
NSDictionary *attrDic = [fileManager attributesOfItemAtPath:path2 error:nil];
NSNumber *fileSize = attrDic[NSFileSize];
fileNum += [fileSize intValue];
path = [files nextObject];
}
NSLog(@"目錄的總大小:%d",fileNum);
四、獲取對應的時區時間
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc]init];
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSDate *date = [NSDate date];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [NSDate dateWithTimeInterval:interval sinceDate:date];
NSString * s = [dateFormatter stringFromDate:localeDate];
五、取消延遲執行的函數
延遲執行函數
[self performSelector:@selector(scrollDone) withObject:nil afterDelay:0.5];
在0.5秒內取消執行函數,帶的參數必須一樣,才能取消成功
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(scrollDone) object:nil];