ios - Unbalanced call to dispatch_group_leave() on CloudKit CompletionBlock -


so building ios app working cloudkit. particular function calls products:

func getallproducts(){      //empty object in singleton class     sharedstore.products.removeallobjects()     var products = nsmutablearray()      //set query     var predicate = nspredicate(value: true)     var query = ckquery(recordtype: "product", predicate: predicate)      //set in query operation     var queryoperation = ckqueryoperation(query: query)      //define method catch fetched records     //define completion block process results     queryoperation.querycompletionblock = { (cursor: ckquerycursor!, error: nserror!) in         if error != nil {             //there error, error delegate             self.delegate?.cloudkitreturnederror(error)         } else {             //there no error             println("no error")             //cursor used know if there more data fetched, check cursor             if cursor != nil {                 //there more data fetch                 println("more data fetched")                 //start new query                 let newoperation = ckqueryoperation(cursor: cursor)                 newoperation.completionblock = queryoperation.completionblock                 newoperation.recordfetchedblock = queryoperation.recordfetchedblock                 self.privatedb.addoperation(newoperation)                 dispatch_async(dispatch_group_enter(<#group: dispatch_group_t#>), <#block: dispatch_block_t##() -> void#>)             } else {                 println("all data fetched")                 self.delegate?.cloudkitreturnedarray!(products, identifier: "storeproducts")             }         }     }      queryoperation.recordfetchedblock = { (record: ckrecord!) in         let product = self.saveproduct(record)          if product.categoryreference == nil {             products.addobject(product)         }     }      //add operation     self.privatedb .addoperation(queryoperation) } 

please note cloudkit communication happens in dedicated cloudkitcontroller class.

when large stacks of data fetched, not load them @ once 'activates' it's cursor. however, when so, apparently calls dispatch_group_leave() somewhere in background. when it's cursor starts receiving data, , completes, querycompletionblock supposed send "finished" message it's delegate, instead this:

libdispatch.dylib`dispatch_group_leave: 0x1088edfd9 <+0>:  movl   $0x1, %eax 0x1088edfde <+5>:  lock    0x1088edfdf <+6>:  xaddq  %rax, 0x40(%rdi) 0x1088edfe4 <+11>: incq   %rax 0x1088edfe7 <+14>: js     0x1088edffe               ; <+37> 0x1088edfe9 <+16>: movabsq $0x7fffffffffffffff, %rcx 0x1088edff3 <+26>: cmpq   %rcx, %rax 0x1088edff6 <+29>: jne    0x1088edffd               ; <+36> 0x1088edff8 <+31>: jmp    0x1088ee00e               ; _dispatch_group_wake 0x1088edffd <+36>: retq    0x1088edffe <+37>: leaq   0x180c8(%rip), %rcx       ; "bug in client of libdispatch: unbalanced call dispatch_group_leave()" 0x1088ee005 <+44>: movq   %rcx, 0x301a4(%rip)       ; gcrannotations + 8 

-> 0x1088ee00c <+51>: ud2

i suppose should call dispatch_group_enter() somehow in code, whole asynchronous thing new me. have read through apple's documentation cannot manage write piece of code job.

the question how prevent getting unbalanced call "dispatch_group_leave()" when cloudkit works cursor retrieve large stacks of data?

any comments highly appreciated.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -