IOS-809 fix Core Data reported concurrency rule violation IOS-809
authorbuff <andreas@pep-project.org>
Thu, 16 Nov 2017 12:43:28 +0100
branchIOS-809
changeset 3419f4c5d2ec661f
parent 3418 ba9c0add0cb4
child 3420 1eb4c8bb9cea
IOS-809 fix Core Data reported concurrency rule violation
pEpForiOS/UI/EmailDisplay/EmailListViewController.swift
     1.1 --- a/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Thu Nov 16 11:57:30 2017 +0100
     1.2 +++ b/pEpForiOS/UI/EmailDisplay/EmailListViewController.swift	Thu Nov 16 12:43:28 2017 +0100
     1.3 @@ -164,33 +164,35 @@
     1.4          cell.setContactImage(image: row.senderContactImage)
     1.5          
     1.6          let op = BlockOperation() { [weak self] in
     1.7 -            // ... and expensive computations in background
     1.8 -            guard let strongSelf = self else {
     1.9 -                // View is gone, nothing to do.
    1.10 -                return
    1.11 -            }
    1.12 -            
    1.13 -            var senderImage: UIImage?
    1.14 -            if row.senderContactImage == nil {
    1.15 -                // image for identity has not been cached yet
    1.16 -                // Get and cache it here in the background ...
    1.17 -                senderImage = strongSelf.model?.senderImage(forCellAt: indexPath)
    1.18 -
    1.19 -                // ... and set it on the main queue
    1.20 -                DispatchQueue.main.async {
    1.21 -                    if senderImage != nil && senderImage != cell.contactImageView.image {
    1.22 -                        cell.contactImageView.image  = senderImage
    1.23 +            MessageModel.performAndWait {
    1.24 +                // ... and expensive computations in background
    1.25 +                guard let strongSelf = self else {
    1.26 +                    // View is gone, nothing to do.
    1.27 +                    return
    1.28 +                }
    1.29 +                
    1.30 +                var senderImage: UIImage?
    1.31 +                if row.senderContactImage == nil {
    1.32 +                    // image for identity has not been cached yet
    1.33 +                    // Get and cache it here in the background ...
    1.34 +                    senderImage = strongSelf.model?.senderImage(forCellAt: indexPath)
    1.35 +                    
    1.36 +                    // ... and set it on the main queue
    1.37 +                    DispatchQueue.main.async {
    1.38 +                        if senderImage != nil && senderImage != cell.contactImageView.image {
    1.39 +                            cell.contactImageView.image  = senderImage
    1.40 +                        }
    1.41                      }
    1.42                  }
    1.43 -            }
    1.44 -
    1.45 -            let pEpRatingImage = strongSelf.model?.pEpRatingColorImage(forCellAt: indexPath)
    1.46 -
    1.47 -            // In theory we want to set all data in *one* async call. But as pEpRatingColorImage takes
    1.48 -            // very long, we are setting the sender image seperatelly.
    1.49 -            DispatchQueue.main.async {
    1.50 -                if pEpRatingImage != nil {
    1.51 -                    cell.setPepRatingImage(image: pEpRatingImage)
    1.52 +                
    1.53 +                let pEpRatingImage = strongSelf.model?.pEpRatingColorImage(forCellAt: indexPath)
    1.54 +                
    1.55 +                // In theory we want to set all data in *one* async call. But as pEpRatingColorImage takes
    1.56 +                // very long, we are setting the sender image seperatelly.
    1.57 +                DispatchQueue.main.async {
    1.58 +                    if pEpRatingImage != nil {
    1.59 +                        cell.setPepRatingImage(image: pEpRatingImage)
    1.60 +                    }
    1.61                  }
    1.62              }
    1.63          }