dispatch_once
在我將項目轉換爲ARC之後,調用導致崩潰(在模擬器中)。我的原始問題是,我有一個單身人士對象的+(SingletonClass)共享{... dispatch_once(...,^ {})中有EXC_BAD_ACCESS
(在objc_retain調用中)崩潰; ...}方法恰好在dispatch_once調用之前的一行。基於測井公司dispatch_once通話導致崩潰
和斷點我的代碼都沒有運行到dispatch_once調用的塊。
我不知道原因,所以我只是註釋掉dispatch_once電話。沒有這個電話,我的應用程序沒有崩潰。
之後,我已經試圖把dispatch_once在我的應用程序調用前面的方法。基於這一點,我知道Xcode指向dispatch_once調用之前的那一行,而不管dispatch_once調用的方法如何。
這對我來說是一個謎最主要的是,如果我運行在模擬器應用程序,這是唯一的可重複性。在設備上運行應用程序沒有任何問題。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"I will crash if you won't delete the dispatch_once after me and you run me in the iOS Simulator... If you run me on a device there won't be any problem with me...");
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
int a = 42;
});
return NO;
}
讓我們看看一些代碼^^ 100個原因,爲什麼會發生這種情況 –
沒有什麼弧會改變..和那個確切的代碼不會崩潰對我來說(只是試過) –
我已經添加了一個示例代碼的原始問題。 – stoflow