一些也許會(huì)用到的oc知識(shí)

一、oc如何將數(shù)據(jù)寫入到plist文件中

/**
*數(shù)組、字典只能將BoolNSNumberNSStringNSDataNSDateNSArrayNSDictionary 寫入屬性列表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

三、計(jì)算一個(gè)目錄的容量大小

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);

四、獲取對(duì)應(yīng)的時(shí)區(qū)時(shí)間

    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];

五、取消延遲執(zhí)行的函數(shù)

延遲執(zhí)行函數(shù)

[self performSelector:@selector(scrollDone) withObject:nil afterDelay:0.5];

在0.5秒內(nèi)取消執(zhí)行函數(shù),帶的參數(shù)必須一樣,才能取消成功

[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(scrollDone) object:nil];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容

  • *面試心聲:其實(shí)這些題本人都沒怎么背,但是在上海 兩周半 面了大約10家 收到差不多3個(gè)offer,總結(jié)起來(lái)就是把...
    Dove_iOS閱讀 27,217評(píng)論 30 472
  • 面向?qū)ο笕笾е庋b:就是把相關(guān)的數(shù)據(jù)和代碼結(jié)合成一個(gè)有機(jī)的整體,形成數(shù)據(jù)和操作代碼的封裝體,對(duì)外只提供一個(gè)可以控...
    WangDavid閱讀 1,711評(píng)論 0 2
  • 1.自定義控件 a.繼承某個(gè)控件 b.重寫initWithFrame方法可以設(shè)置一些它的屬性 c.在layouts...
    圍繞的城閱讀 3,484評(píng)論 2 4
  • 接下來(lái)我們看base文件下的Foundation文件夾下文件 Base - Foundation 這個(gè)文件夾里面的...
    充滿活力的早晨閱讀 2,168評(píng)論 0 1
  • 通讀全書的時(shí)候我就一直在思考到底為什么這個(gè)發(fā)生在戰(zhàn)爭(zhēng)年代的小說(shuō)要以“線”來(lái)命名,我想,除了書籍后封面上印上去的故事...
    JoelyZhao閱讀 654評(píng)論 2 3