什么時(shí)候用assign女器、什么時(shí)候用retain和copy呢毅糟?
推薦做法是NSString用copy
delegate用assign(且一定要用assign),
非objc數(shù)據(jù)類型腰池,比如int隙疚,float等基本數(shù)據(jù)類型用assign(默認(rèn)就是assign)壤追,
而其它objc類型,比如NSArray供屉,NSDate用retain行冰。
參考來(lái)源:http://www.cnblogs.com/andyque/archive/2011/08/03/2125728.html
賦值的時(shí)候同時(shí)會(huì)執(zhí)行一些任務(wù)。
比如:
NSTimer *timer = [NSTimer sheduledTimerWithTimeInterval: 5.0 targer: self selector:@selector(outPutLogs) userInfo: nil repeat: YES];
在給timer賦值的同時(shí)贯卦,會(huì)注冊(cè)執(zhí)行重復(fù)調(diào)用outPutLogs 方法资柔。
再比如:
__block UIBackgroundTaskIdentifier taskId;
taskId = [applacation beginBackgrondTaskWithExpirationHandler: ^{
[applacation endBackgroundTask: taskId];
}];
在用戶出發(fā)home鍵之后焙贷,應(yīng)用需要更多的時(shí)間處理數(shù)據(jù)撵割,在這里賦值給taskId的同時(shí),系統(tǒng)會(huì)根據(jù)用戶注冊(cè)了beginBackgrondTaskWithExpirationHandler: 方法而延長(zhǎng)后臺(tái)時(shí)間辙芍。