Dispatch_Group crash on iPhone 4s/iOS 8 -
i've written method using dispatch_group
:
class func loadnewevents(incontext context:nsmanagedobjectcontext, completion:(() -> void)?=nil) { ddlogdebug("loading new events") let context = coredatamanager.backgroundcontext() let events = coredatamanager.fetch(event.self, incontext: context) var earliestevent = events.sort({$0.initialtimestamp.integervalue > $1.initialtimestamp.integervalue}).first let group = dispatch_group_create() var loadedevents:[event]? var failure = false while (loadedevents == nil || loadedevents!.count != 0) && !failure { dispatch_group_enter(group); if let earliesttimestamp = earliestevent?.initialtimestamp.longlongvalue { let url = afterurl(earliesttimestamp) getevents(url: url, success: { events in loadedevents = events earliestevent = events.last dispatch_group_leave(group) }, failure: { failure = true dispatch_group_leave(group) } ) } else { break } dispatch_group_wait(group, dispatch_time_forever) } ddlogdebug("loaded new events") }
it works great in ios9 simulator , on iphone5s w/ ios9. on iphone 4s ios8 there crash @ end of method :
exc_breakpoint (code=exc_arm_breakpoint, subcode=0xdefe)
in _dispatch_semaphore_dispose
any idea cause , how fix ?
i found out problem : did not leave group on break
.
to fix called dispatch_group_enter(group)
within if let
since not needed when i'm not doing async call.
Comments
Post a Comment