Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
An error occurred. in CDMarkdownImage class -> "let data = try? Data(contentsOf: url)"
Synchronous URL loading of https://upload.wikimedia.org/wikipedia/commons/thumb/1/14/Gatto_europeo4.jpg/250px-Gatto_europeo4.jpg should not occur on this application's main thread as it may lead to UI unresponsiveness. Please switch to an asynchronous networking API such as URLSession.
Goals ⚽
My goal is to asynchronously fetch an image and reflect it in the view to resolve this error.
Implementation Details 🚧
I added the AsyncTextAttachment class to fetch the image asynchronously, and I wrote an extension for NSLayoutManager to track the size of the attachment. When the startAsyncImageDownload() function is executed, a function is called to apply the layout. And when the task is completed, it calls the delegate to notify that it has finished.
Testing Details 🔍
I added "#if os(iOS)" because I tested it only on iOS.
It works well on iOS.