Tag: grand central dispatch

对多个位置进行地理编码 – 了解何时调用“所有”完成块

我正在使用CoreLocation的地理编码器来获取多个地图项的CLLocation坐标。 地理编码器在完成时为每个项目调用完成块。 当所有包含asynchronous地理编码调用的调用完成后,如何创build一个类似的块function? (我可以使用手动计数器,但必须有一个更优雅的解决scheme) 这是我迄今为止的地理编码function。 它通过一系列位置项目进行循环,并为每个项目启动一个新的地理编码过程。 -(void)geoCodeAllItems { for (EventItem* thisEvent in [[EventItemStore sharedStore] allItems]) { if (![thisEvent eventLocationCLLocation]){ //Only geocode if the item has no location data yet CLGeocoder *geocoder = [[CLGeocoder alloc]init]; [geocoder geocodeAddressString:[thisEvent eventLocationGeoQuery] completionHandler:^(NSArray *placemarks, NSError *error) { if (error){ NSLog(@"\t Geo Code – Error – Failed to geocode"; return; } […]

如何从asynchronous属性的getter返回?

我已经覆盖了一个请求在线服务获取结果的getter。 如何强制getter只返回来自同步块的结果? @interface MyClass () @property (nonatomic, strong) NSMutableDictionary* myDictionary; @end @implementation MyClass -(NSMutableDictionary*) myDictionary { dispatch_async(queue, ^{ /* perform online request */ dispatch_sync(dispatch_get_main_queue(), ^{ // I need to obtain lock until this line gets executed and only then return }); }); } @end 用相当不错的谷歌search至less3小时,我遇到了dispatch_group_async , dispatch_semaphore和__block 。 我不知道我是否用错了,但没有达到目的。 更新1: myDictionary是一个asynchronous属性。 我想看看是否可以通过getter本身来实现。

swift 3中的dispatchqueue显示为未parsing的标识符

我正尝试在主线程上asynchronous录制/录制video。 但是,当我调用dispatch.main.async ,我总是得到错误: use of unresolved identifier DispatchQueue 从WWDC到苹果的文档,我都到处寻找,但我没有看到这种types的弃用证据。 这里是代码: if !self.cameraEngine.isRecording { if let url = CameraEngineFileManager.temporaryPath("video.mp4") { self.cameraButton.setTitle("stop recording", forState: []) self.cameraEngine.startRecordingVideo(url, blockCompletion: { (url: NSURL?, error: NSError?) -> (Void) in if let url = url { DispatchQueue.main.async { self.cameraButton.setTitle("start recording", for: .normal) CameraEngineFileManager.saveVideo(url, blockCompletion: { (success: Bool, error: Error?) -> (Void) in […]

dispatch_after等同于NSOperationQueue

我将我的代码从常规GCD移到NSOperationQueue,因为我需要一些function。 我的很多代码依赖dispatch_after才能正常工作。 有没有办法与NSOperation做类似的事情? 这是我需要转换为NSOperation的一些代码。 如果你能提供一个使用这个代码来转换它的例子,那就太好了。 dispatch_queue_t queue = dispatch_queue_create("com.cue.MainFade", NULL); dispatch_time_t mainPopTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(timeRun * NSEC_PER_SEC)); dispatch_after(mainPopTime, queue, ^(void){ if(dFade !=nil){ double incriment = ([dFade volume] / [self fadeOut])/10; //incriment per .1 seconds. [self doDelayFadeOut:incriment with:dFade on:dispatch_queue_create("com.cue.MainFade", 0)]; } });

大中央调度没有块

是否有可能使用GCD没有块? 有没有一种方法可以像使用_f变体那样使用GCD,正如mikeash在post中所说的那样。 我四处搜寻,双方都没有证据。 这是可能的或不可能的。 如果可以的话请举个例子。 / Selvin

任何方式使dispatch_queue_t单线程工作?

这是我的代码: @interface MyObject () @property(nonatomic) dispatch_queue_t queue; @end @implementation MyObject { NSThread *_check; } – (id)init { self = [super init]; if (self) { _queue = dispatch_queue_create("com.Thread.queue", NULL); dispatch_async(_queue, ^{ _check = [NSThread currentThread]; //for ex. thread number = 3 //some code here… }); } return self; } – (void)someMethod:(MyObjClass *)obj { dispatch_async(_queue, ^{ //need […]

IOS大中央调度与callback方法

我没有使用GCD或multithreading在我的应用程序,但我遇到了一种情况,我需要运行一个或两个方法closures另一个线程。 一旦这个方法完成,我需要从callback中使用主线程调用另一个方法。 我一直在寻找如何检测线程何时完成操作,但仍然不太清楚的主题。 我创build了一个testing应用程序,并使用viewDidLoad方法作为一个简单的例子。 – (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{ NSLog(@"viewDidLoad called"); sleep(5); // simulating a thread being tied up for 5 seconds dispatch_async(dispatch_get_main_queue(), ^{ [self callbackMethod]; // method called after above thread has completed running }); }); } 这个例子是否适用于我想要做的事情? […]

我应该避免在全局队列中创buildJSContexts?

我刚刚从客户的设备上得到了一个崩溃日志,而且在这里崩溃了: dispatch_async(dispatch_get_global_queue(0, 0), ^{ JSContext *javaScriptContext = [[JSContext alloc] init]; 这里是崩溃日志: Thread 11 Crashed: 0 JavaScriptCore 0x31009cd6 WTFCrash + 54 1 JavaScriptCore 0x30e0edf6 WTF::OSAllocator::reserveAndCommit(unsigned long, WTF::OSAllocator::Usage, bool, bool, bool) + 166 2 JavaScriptCore 0x30e0ed2a WTF::OSAllocator::reserveUncommitted(unsigned long, WTF::OSAllocator::Usage, bool, bool, bool) + 14 3 JavaScriptCore 0x30e14736 JSC::JSStack::JSStack(JSC::VM&, unsigned long) + 74 4 JavaScriptCore 0x30e146d2 JSC::Interpreter::Interpreter(JSC::VM&) + […]

GCD:如何更改定时器的启动间隔

无论如何,这可能听起来是一个新手问题,我对GCD很陌生 我有以下代码: int interval = 2; int leeway = 0; dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); if (timer) { dispatch_source_set_timer(timer, dispatch_walltime(DISPATCH_TIME_NOW, NSEC_PER_SEC * interval), interval * NSEC_PER_SEC, leeway); dispatch_source_set_event_handler(timer, ^{ [self someMethod]; }); dispatch_resume(timer); } 哪些方法是: – (void)someMethod { NSLog(@"Thread 1"); } 如何在某些方法中更改timer的启动间隔属性?

如何检查dispatch_async块是否已经完成运行

所以基本上我需要能够在一个块完成运行后运行一个segue。 我有一个块做了一些JSON的东西,我需要知道什么时候已经完成运行。 我有一个我叫做json_queue的队列。 jsonQueue = dispatch_queue_create("com.jaboston.jsonQueue", NULL); 然后我有一个dispatch_async块的语法: dispatch_async(jsonQueue, ^{ [self doSomeJSON]; [self performSegueWithIdentifier:@"modaltomenu" sender:self]; }); 它不会让我表演:“[self performSegueWithIdentifier:@”modaltomenu“sender:self];” 尝试从主线程或Web线程以外的线程获取Weblocking。 这可能是从辅助线程调用UIKit的结果。 现在崩溃… 我在哪里可以检查发现什么时候线程已经完成了它的肮脏的工作,所以我可以打电话给赛格? 谢谢可爱的人。 PS:啤酒和ups,泰迪熊和花朵,谁可以帮助<3。