Objective C中的callback之一

2021-08-16 22:00:36 字數 4652 閱讀 3048

oc中的callback有四種型別:

下面是第一種:nsrunloop

////  bnrlogger.h

//  tocrunloopa

////

#import

@inte***ce bnrlogger : nsobject

@property(nonatomic)

nsdate

*lasttime;

- (nsstring *)lasttimerstring;

- (void)updatelasttimer:(nstimer *)t;

@end

////  bnrlogger.m

//  tocrunloopa

////

#import "bnrlogger.h"

@implementationbnrlogger

- (nsstring *)lasttimerstring

return [dateformatter stringfromdate:self.lasttime];

}- (void)updatelasttimer:(nstimer *)t

@end

////  main.m

//  tocrunloopa

////

#import

#import "bnrlogger.h"

int main(int argc, const

char * argv)

return0;

}result:

2018-03-13 23:06:48.385109+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:48.385832+0800 tocrunloopa[70235:4288894] created dateformatter

2018-03-13 23:06:48.388740+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:48

2018-03-13 23:06:50.389817+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:50.390015+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:50

2018-03-13 23:06:52.385937+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:52.386101+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:52

2018-03-13 23:06:54.389943+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:54.390161+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:54

2018-03-13 23:06:56.389912+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:56.390110+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:56

2018-03-13 23:06:58.385713+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:06:58.385988+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:06:58

2018-03-13 23:07:00.385853+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:07:00.386030+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:07:00

2018-03-13 23:07:02.386859+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:07:02.387024+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:07:02

2018-03-13 23:07:04.390148+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:07:04.390356+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:07:04

2018-03-13 23:07:06.390241+0800 tocrunloopa[70235:4288894] i want to see the timer here:

2018-03-13 23:07:06.390478+0800 tocrunloopa[70235:4288894] just set time to 2018313下午11:07:06-

-------------------------------持續每2秒輸出一次

javascript中apply與call函式

首先,function是乙個指向function物件,函式名是乙個指向函式的指標。那麼在函式體內,就會有乙個作用域,即this關鍵字。this關鍵字指的是函式執行的作用域,舉個例子來說,上面這段 中的函式funca定義在全域性環境中,那麼函式體內的this即window物件。我們定義funcb函式的...

JavaScript中apply和call的理解

這兩個方法作用是相同,只是用法不同,null 代表不需要改變this的指向 console.log math.max.call null,1,2,3,4,5,6,1000 var obj1 var obj2 window.name window var getname function getnam...

Objective C中的快取

nscache可以設定數量限制,通過countlimit與 totalcostlimit來限制cache的數量或者限制cost。當快取的數量超過countlimit,或者cost之和超過totalcostlimit,nscache會自動釋放部分快取。例子如下 可以看到,cache中只保留了最新的30...