4

With this code it tells me that 'String' is not convertible to 'NSMutableAttributedString'

var textViewString:NSMutableAttributedString = ""

How do I properly initialize this string as empty? (It needs to be empty as I iterate through a loop appending items to the string.)

2 Answers 2

13

You can define it like this

var textViewString = NSMutableAttributedString(string: "")
Sign up to request clarification or add additional context in comments.

1 Comment

Although you don't need the explicit type since Swift can infer the type from the initializer. Martin's answer is the preferred syntax.
11

You can create an empty mutable attributed string simply with

var textViewString = NSMutableAttributedString()

Comments

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.