剛才發現一個靈異現象,還沒找到原因,先記錄一下:
我的MainViewController裡有2個輔助類的引用:
@implementation YLSMainViewController YLSLogoutDelegate *logoutDelegate; YLSBackupDelegate *backupDelegate; YLSResumeDelegate *resumeDelegate;
backupDelegate = [YLSBackupDelegate new]; resumeDelegate = [YLSResumeDelegate new];
- (id)init { if(self = [super init]){ tasks = [NSMutableArray new]; // 備份任務在下面依次添加 [tasks addObject:[YLSMemberBackupTask new]]; [tasks addObject:[YLSEmployeeBackupTask new]]; [tasks addObject:[YLSServiceBackupTask new]]; [tasks addObject:[YLSShowBackupTask new]]; [tasks addObject:[YLSBillBackupTask new]]; [tasks addObject:[YLSUserBackupTask new]]; [tasks addObject:[YLSEnterpriseBackupTask new]]; } return self; }
- (id)init { if(self = [super init]){ tasks = [NSMutableArray new]; // 恢復任務在下面依次添加 [tasks addObject:[YLSEmployeeResumeTask new]]; } return self; }
2013-12-17 16:40:42.306 NailShop[13926:456b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[YLSEmployeeResumeTask doBackup:]: unrecognized selector sent to instance 0xecb8990'
從異常信息看到,BackupDelegate的實例變量tasks裡,存放的居然是ResumeDelegate的同名實例變量tasks裡的對象……然後DEBUG又發現一個問題,BackupDelegate的init()方法執行了2遍,ResumeDelegate是正常的只執行一遍
反復檢查沒發現什麼問題,最後只好把ResumeDelegate裡的那個NSMutableArray的變量名改成resumeTasks,避免重名
問題是解決了,但是實在太靈異了……有人知道這個問題的原因嗎?