0

I've seen other questions on here asking about text markdown not displaying in Swift but nothing directly related to AWS Amplify. I've tried the solutions such as the one linked below but nothing has worked so far.

SwiftUI Text Markdown dynamic string not working

I'm using AWS Amplify to send news articles to my app and the text body of the article is formatted as an optional string. Here is how it is setup in my Model:

public struct Article: Model {
public var body: String?

I've tried using

Text(.init(article.body ?? "Body"))

and

Text(try! AttributedString(markdown: article.body ?? "Body"))

But each method doesn't seem to work. Below is a snippet of the text body that I'm trying to have display new lines.

The Cubs defeated the Reds 4-2 in the second-ever Field of Dreams MLB game in Iowa, and both teams relished the experience.\n\nThe Cubs won MLB's 2022 Field of Dreams game over the Reds 4-2. Here is a look at the best moments from Thursday's action.

Before integrating AWS Amplify I was testing with local JSON files that I was loading into my app and the formatting was displaying properly.

What am I missing and/or not understanding?

8
  • Does your string actually have new line characters or does it literally have a slash and then an n? Commented Aug 13, 2022 at 16:08
  • It literally has a slash and then an n. This worked fine when I was loading the text into a non-optional string from a JSON file and displaying it with a Text object in swift. Commented Aug 13, 2022 at 16:18
  • 1
    That's because strings loaded from JSON have the two characters ` and n` translated into a newline character for you. If you want that behavior your have two options: 1) Put actual newline characters into AWS 2) Search and replace the two literal characters ` n` and replace them with a newline character Commented Aug 13, 2022 at 16:21
  • I just tried adding new line characters in AWS and it appears correct in the markdown but when the article loads in Swift they are getting ignored. So it looks like my example above but instead of having \n\n it appears as the experience.The Cubs Commented Aug 13, 2022 at 16:56
  • It's likely that you're still misunderstanding the difference. How did you enter the newline characters? By pressing return? Or did you once again enter \n as two characters? Commented Aug 13, 2022 at 16:57

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.