I want to send the attributedString to the server along with all attribute information and then receive this on another device and display the attributedString in UITextView again. I have created a Transformable attribute in CoreData with NSAttributedString as custom class. i get the UITextView attributedString and save it in CoreData and later on retrieve it and display back on UITextView. This all works fine, however my use case requires me to send the formatted text along with all attributes information to server using REST API. I tried following solutions but none of them worked:
Convert NSAttributedString to String (Problem: it removes the formatting information)
serialise NSAttributedString object using NSKeyedArchiver.archivedData and then send the resultant Data to server (Problem: I get error in POST method)
serialise NSAttributedString and convert the resultant Data to string using testString.data(using: String.Encoding.utf8) (Problem: When i try to convert this string back to Data i get error)
Can anybody guide me in this, if i am approaching this problem the right way or not? I am open to upgrading to latest Swift version if there is any new feature which i can use to solve this problem. Any kind of help is appreciated.
Thank you
Affan
Convert NSAttributedString to HTML.
I think solved your problem.
How do i convert NSAttributedString into HTML string?
Display HTML data in a label or textView
Related
I am getting a SSML text in the JSON and trying to find out a standard way to parse this SSML format i.e
"text" : [ "<speak>Screen title <break strength='weak '/> Sign In <break strength='weak '/> </speak>" ]
for my tts application. But I find no way except doing manually. I need to fetch out the real string to be played using AVSpeechSynthesizer. Has anyone tried this before? Help!
Currently it is uttering the complete text->value with tags.
Well, I fixed it using the regular expression to parse SSML tags as suggested by #Carpsen90. There is no other way I found. But, thanks for all your help!
I have a JSON file like this. I have to make bold part of string which is shown in JSON. How can I make parse this JSON?
It looks to me like you would first want to use NSJSONSerialization (Or just JSONSerialization in Swift 3) to convert your JSON to an object graph. Once you've done that, you should be able to navigate to the interestLabel keys in your data and fetch those strings.
You'll then need to parse those tagged strings somehow. If the only thing you need to do is to find <b> and </b> bold tags, and no other tags will ever appear in your data then you could probably write your own code. If the strings might have other tags and/or more complex HTML structure then you might want to use an XML/HTML parser. I suggest taking a look at this tutorial: https://www.raywenderlich.com/14172/how-to-parse-html-on-ios
I know how upload and save file. But how to upload the file without saving on disk and display text-data in TextArea or TextField.
When using the vaadin upload you should be able to use a ByteArrayOutputStream instead of a FileOutputStream.
So just use the sample from the book of vaadin but use a ByteArrayOuputStream instead.
When the uploadSucceeded method is called, you take the ByteArrayOutputStream, convert it into a string (Beware of the correct encoding) and set it as the value of your TextArea/Field.
I am writing a utility app for some coworkers. The app is essentially a custom notepad, with buttons that represent the shorthand they use to transcribe a task. All of the buttons add a string to arrays that I have set up to hold the transcript, and I add the strings to the row arrays like this.
[currentRow addObject:#"("];
Some of the shorthand needs to be written in subscript, and some in superscript. There are not Unicode characters for all of the characters that I need, so I have been trying to sort through the code around Attributed Strings,but I'm not quite getting it. Does anyone have advice on this or some sample code?
Also, after this transcript is printed to the screen during transcription, I send it to an email message body.. so I assume I'll need to worry about formatting there as well. I am currently using plain text, but the email could be HTML. Thanks!
If you display the text in a WebView you can use html tags to set superscript. It also has the advantage to run on older iOS versions and you can reuse the text in your mail.
NSString *myText=#"This text contains <sub>subscript</sub> and <sup>superscript</sup> text.";
[self.myWebView loadHTMLString:myText baseURL:nil];
I got an app, where i download data through JSON. But when i am trying to show NSStrings i see something like this:
\u041e\u041d\u0410!!! etc.
How can I decode it into normal symbols?
in our team for this problem we create our own decoder
You'll see \u041e\u041d\u0410!!! only in NSLog's console view.. just assign NSSTring's value to some UILabel or UITextField it will show properly
If you log just for example nsdictioanry you will see unicode \u041e\u041d\u0410, but if you will log NSString (objectForKey:#"key") it will be ok.