Skip to content

Fixed background thread access UI component#114

Merged
krbarnes merged 1 commit intomasterfrom
fix-tableview-ui-access
Oct 17, 2018
Merged

Fixed background thread access UI component#114
krbarnes merged 1 commit intomasterfrom
fix-tableview-ui-access

Conversation

@stevenwenxu
Copy link
Copy Markdown
Contributor

Resolves #113

The tableView.frame was directly accessed in the BlockOperation. As suggested by the main thread checker, this should only be accessed in the main thread.

Copy link
Copy Markdown
Contributor

@krbarnes krbarnes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might capture the frame before starting the operation to avoid the sync.

guard let exceptionHandler = FunctionalTableData.exceptionHandler else { return }
let changes = TableSectionChangeSet()
let exception = FunctionalTableData.Exception(name: $0.name.rawValue, newSections: newSections, oldSections: strongSelf.sections, changes: changes, visible: [], viewFrame: strongSelf.collectionView?.frame ?? .zero, reason: $0.reason, userInfo: $0.userInfo)
var viewFrame: CGRect = .zero
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can write this as:
let viewFrame = DispatchQueue.main.sync { return strongSelf.collectionView?.frame ?? .zero }

@dannbeau
Copy link
Copy Markdown

I might capture the frame before starting the operation

I don't think the public func renderAndDiff is guaranteed to be called on the main queue; at least with the block operation, its guaranteed to be not the main queue, so sync on main queue should be safe from here.

@stevenwenxu stevenwenxu force-pushed the fix-tableview-ui-access branch from 8c2371a to 8dfd483 Compare October 16, 2018 19:56
@stevenwenxu stevenwenxu requested a review from g-Off October 16, 2018 19:57
@krbarnes krbarnes merged commit 7146df1 into master Oct 17, 2018
@krbarnes krbarnes deleted the fix-tableview-ui-access branch October 17, 2018 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants