ios - Do something BEFORE unwind segue (swift) -


i have unwind segue goes previous controller , saves image phasset library. unwind segue works, saving works, issue unwinds before image saves. because of that, image doesn't presented on view controller unwinded to, since view controller presented before picture saved (it takes little time image save, whereas goes view controller quickly). wondering if there way unwind previous controller when after photo has been saved, not right away.

here code:

override func prepareforsegue(segue: uistoryboardsegue, sender: anyobject?) {     if segue.identifier == "savepicture" {          //image saved         let newimage = self.appraisalpic.image          //store picture phassets         let priority = dispatch_queue_priority_default         dispatch_async(dispatch_get_global_queue(priority, 0), {             phphotolibrary.sharedphotolibrary().performchanges({                 let createassetrequest = phassetchangerequest.creationrequestforassetfromimage(newimage)                 let assetplaceholder = createassetrequest.placeholderforcreatedasset                 let albumchangerequest = phassetcollectionchangerequest(forassetcollection: self.assetcollection, assets: self.photosasset)                 albumchangerequest.addassets([assetplaceholder])                 }, completionhandler: {(success, error)in                     dispatch_async(dispatch_get_main_queue(), {                         nslog("adding image library -> %@", (success ? "success":"error!"))                  //need code here doesn't segue until after picture saved                     })             })          })     } } 

this expression: dispatch_async(dispatch_get_global_queue(priority, 0)

will perform in background (until again explicitly on main queue).

simply eliminate dispatch_async calls work on main thread. if takes long, notify user knows there short wait until unwind segue fires.


Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -