> 爲你們總結一份完整的2020年《大廠最新常問iOS面試題+答案》,**面試題合集答案**、**複習資料**,均有**完整PDF版**,須要的小夥伴加iOS技術分享羣:761407670,羣文件直接獲取!git
題目來源自這裏,筆者對知識類問題和經驗類問題作了解答,答案有遺漏的地方但願你們能補充,這是你能用到的面試題(一)github
是一個與線程相關的機制,能夠理解爲一個循環,在這個循環裏面等待事件而後處理事件.而這個循環是基於線程的,在Cocoa中每一個線程都有它的runroop,經過他這樣的機制,線程能夠在沒有事件要處理的時候休息,有事件運行,減輕CPU壓力,這題能夠衍生出爲何在滑動時會致使定時器失敗,在下面有解答面試
Toll-Free Bridging用於在Foundation對象與Core Foundation對象之間交換數據,俗稱橋接數據庫
__bridge
橋接之後ARC會自動2個對象__bridge_retained
橋接須要手動釋放Core Foundation對象__bridge
橋接,若是Core Foundation對象被釋放,Foundation對象也同時不能使用了,須要手動管理Core Foundation對象__bridge_transfer
橋接,系統會自動管理2個對象@property
只會生成setter和getter方法的聲明這裏舉個例子,點擊cell之後以動畫形式改變cell高度數組
@interface ViewController () @property (nonatomic, strong) NSIndexPath *index; @end @implementation ViewController static NSString *ID = @"cell"; - (void)viewDidLoad { [super viewDidLoad]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID]; cell.textLabel.text = [NSString stringWithFormat:@"%ld",(long)indexPath.row]; return cell; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 20; } - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if(self.index == indexPath){ return 120; } return 60; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { self.index = indexPath; [tableView deselectRowAtIndexPath:indexPath animated:TRUE]; // 重點是這2句代碼實現的功能 [tableView beginUpdates]; [tableView endUpdates]; }
定時器裏面有個runoop mode,通常定時器是運行在defaultmode上可是若是滑動了這個頁面,主線程runloop會轉到UITrackingRunLoopMode中,這時候就不能處理定時器了,形成定時器失效,緣由就是runroop mode選錯了,解決辦法有2個,一個是更改mode爲NSRunLoopCommonModes(不管runloop運行在哪一個mode,都能運行),還有種辦法是切換到主線程來更新UI界面的刷新服務器
由於這些產生的動畫只是假象,並無對layer進行改變.那麼爲何會這樣呢,這裏要講一下圖層樹裏的呈現樹.呈現樹其實是模型圖層的複製,可是它的屬性值表示了當前外觀效果,動畫的過程實際上只是修改了呈現樹,並無對圖層的屬性進行改變,因此在動畫結束之後圖層會恢復到原先狀態網絡
Security
框架自定義一個keychain的類app
#import <Security/Security.h> @implementation YCKKeyChain + (NSMutableDictionary *)getKeychainQuery:(NSString *)service { return [NSMutableDictionary dictionaryWithObjectsAndKeys: (__bridge_transfer id)kSecClassGenericPassword,(__bridge_transfer id)kSecClass, service, (__bridge_transfer id)kSecAttrService, service, (__bridge_transfer id)kSecAttrAccount, (__bridge_transfer id)kSecAttrAccessibleAfterFirstUnlock,(__bridge_transfer id)kSecAttrAccessible, nil]; } + (void)save:(NSString *)service data:(id)data { // 得到搜索字典 NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; // 添加新的刪除舊的 SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery); // 添加新的對象到字符串 [keychainQuery setObject:[NSKeyedArchiver archivedDataWithRootObject:data] forKey:(__bridge_transfer id)kSecValueData]; // 查詢鑰匙串 SecItemAdd((__bridge_retained CFDictionaryRef)keychainQuery, NULL); } + (id)load:(NSString *)service { id ret = nil; NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; // 配置搜索設置 [keychainQuery setObject:(id)kCFBooleanTrue forKey:(__bridge_transfer id)kSecReturnData]; [keychainQuery setObject:(__bridge_transfer id)kSecMatchLimitOne forKey:(__bridge_transfer id)kSecMatchLimit]; CFDataRef keyData = NULL; if (SecItemCopyMatching((__bridge_retained CFDictionaryRef)keychainQuery, (CFTypeRef *)&keyData) == noErr) { @try { ret = [NSKeyedUnarchiver unarchiveObjectWithData:(__bridge_transfer NSData *)keyData]; } @catch (NSException *e) { NSLog(@"Unarchive of %@ failed: %@", service, e); } @finally { } } return ret; } + (void)delete:(NSString *)service { NSMutableDictionary *keychainQuery = [self getKeychainQuery:service]; SecItemDelete((__bridge_retained CFDictionaryRef)keychainQuery); }
在別的類實現存儲,加載,刪除敏感信息方法框架
// 用來標識這個鑰匙串 static NSString * const KEY_IN_KEYCHAIN = @"com.yck.app.allinfo"; // 用來標識密碼 static NSString * const KEY_PASSWORD = @"com.yck.app.password"; + (void)savePassWord:(NSString *)password { NSMutableDictionary *passwordDict = [NSMutableDictionary dictionary]; [passwordDict setObject:password forKey:KEY_PASSWORD]; [YCKKeyChain save:KEY_IN_KEYCHAIN data:passwordDict]; } + (id)readPassWord { NSMutableDictionary *passwordDict = (NSMutableDictionary *)[YCKKeyChain load:KEY_IN_KEYCHAIN]; return [passwordDict objectForKey:KEY_PASSWORD]; } + (void)deletePassWord { [YCKKeyChain delete:KEY_IN_KEYCHAIN]; }
__weak
修飾外部指針__weak typeof(self) weakSelf = self;
__strong typeof(self) strongSelf = weakSelf;
__block
修飾外部變量performSelector:withObject:afterDelay:
方法時,先判斷但願調用的方法是否存在respondsToSelector:
if([[NSUserDefaults standardUserDefaults] objectForKey:ID] == nil){ NSLog(@"沒有設置"); }
爲你們總結一份完整的2020年《大廠最新常問iOS面試題+答案》,面試題合集答案、複習資料,均有完整PDF版,須要的小夥伴加iOS技術分享羣:761407670,羣文件直接獲取!異步