grand-central-dispatch

code blocks with Grand Central Dispatch

孤者浪人 提交于 2019-12-12 23:22:02
问题 I'm writing an app using ARC, and I'm wondering if the following will cause a problem. Specifically, I'm creating an object 'A', then using GCD I add a code block to the main thread's queue and in the code block I perform some operations on the weak reference to the object. But by the time the code block is executed, my object has already been nullified. Since the code block only has a weak reference to the object, will this cause a problem? Or does the compiler somehow know to keep a

Downloading images serially in a serial queue very slow

点点圈 提交于 2019-12-12 20:06:08
问题 Requirement - I have a requirement in which I am receiving a JSON dictionary from which I am retrieving an array of images and content text. Then I have to display all the images with corresponding contents in a collection view. Update - Above all I need to calculate the cell size based on image size scaled to the a constant width for which I fell that(may not be correct) I need all images to be downloaded completely then reload collection view Problem - But the problem is that when I

GCD dispatch_after call causing SIGBUS signal

試著忘記壹切 提交于 2019-12-12 18:31:04
问题 I'm using GCD's dispatch_after method when my application is being loaded to perform some behavior. The intended behavior is to wait 3 seconds from the end of applicationDidFinishLaunchingWithOptions to perform a selector that runs in a background queue. I haven't experienced any crashes on my test devices, but I have user crash reports of uncaught SIGBUS signals, the cause being a BUS_ADRALN exception. From my understanding of this code, a BUS_ADRALN error indicates an address alignment

How do I synchronize access to a property that has didSet?

末鹿安然 提交于 2019-12-12 18:08:38
问题 How do I synchronize access of a property that uses didSet (using GCD or objc_sync_enter)? I have a property that has a property observer. How can I use a private queue to synchronize get/set of the property var state: State = .disconnected { // Q: How to sync get/set access here? didSet { // do something } } 回答1: simplest way is using a serial queue import Dispatch struct S { private var i: Int = 0 { didSet { print("someone did set new value:", i) } } private let queue = DispatchQueue(label:

MKOverlayView performance

不问归期 提交于 2019-12-12 17:13:27
问题 I am adding about 3000 MKOverlays to my map, and as you can imagine, it takes a while, up to about eight seconds sometimes. I'm looking for a way to use threading to improve performance, so the user can move the map around while overlays are being added. Preferably, the overlays would be added sequentially, starting with the just the ones within the map's region. I have tried something along these lines with GCD: - (MKOverlayView*)mapView:(MKMapView*)mapView viewForOverlay:(id)overlay { _

How to find out what caused error crash report on IOS device?

拟墨画扇 提交于 2019-12-12 16:08:57
问题 Christ is Risen (with a joy of the Easter Feast)! While testing an app after the small application refactoring i have received an "Crashlytics" crash log. Was trying to change the Model to avoid double synchronization method call(at the same time) by sending all of the next calls(starting from the 2nd call) to the private serial queue. I have added the following code: @interface SynchronizationModel () @property (nonatomic) dispatch_queue_t synchronizationQueue; @end @implementation

Loop within block appending to array in the wrong order - Swift 2.0

痴心易碎 提交于 2019-12-12 14:01:18
问题 I have an array of PFFiles downloaded from Parse, and I am trying to convert them in to an array of NSData (imageDataArray) in order to save them to Core Data. The only problem I seem to be having now is that the elements of imageDataArray are being added in the wrong order, which means the wrong image is found when I search through Core Data. I found this question (Stack Overflow Question) which seems to explain the reason for the problem as being that the block is completing the tasks at

GCD and RunLoops

别来无恙 提交于 2019-12-12 10:02:16
问题 In my app I add an CFMachPortRef (via CFMachPortCreateRunLoopSource ) to a threads CFRunLoop Now i was asking myself, can this be done using GCD? Let's say instead of spawning my own NSThread and add the created CFRunLoopSourceRef to its run loop via CFRunLoopAddSource , add the event port to a dispatch's runloop? I think this will most likely not work due to the inner workings of GCD, but I really don't know. Update I got this so far, however neither the callback function for the event tap

How does a serial dispatch queue guarantee resource protection?

和自甴很熟 提交于 2019-12-12 09:56:37
问题 //my_serial_queue is a serial_dispatch_queue dispatch_async(my_serial_queue, ^{ //access a shared resource such as a bank account balance [self changeBankAccountBalance]; }); If I submit 100 tasks that each access and mutate a bank account balance, I understand that a serial queue will execute each task sequentially, but do these tasks finish sequentially as well when using dispatch_async? What if task #23 that I submit asynchronously to the serial queue takes a really long time to finish?

View-based NSTableView renders blank rows after inserting new rows with animation

五迷三道 提交于 2019-12-12 09:52:56
问题 I have a view-based NSTableView that I'm backing with an `NSMutableArray . Periodically I go out grab some data and want to insert new rows into the table at the top. When I do this without specifying an animation to insertRowsAtIndexes:withAnimation: it seems to work fine for hours on end. However, if I specify an animation, after about 7 or 8 inserts the table view starts to show blank rows where the inserts occurred. Scrolling down and then back up causes the new rows to render properly.