discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMutableString -initWithFormat appends to existing text


From: Ivan Vučica
Subject: Re: NSMutableString -initWithFormat appends to existing text
Date: Wed, 18 Apr 2018 09:29:40 +0000



On 18 Apr 2018, at 09:23, Mick Bert <micbert75@gmail.com> wrote:

2018-04-18 9:52 GMT+02:00 H. Nikolaus Schaller <hns@goldelico.com>:

-init or -initWithFormat: should be called only once and only after +alloc.
You use stringWithCapacity which has already been initialized.

Use -setString:@"" followed by -appendWithFormat: instead.

Thanks a lot!
Now it works as expected.

It may, but invoking init multiple times is still a bad idea.


One question more. I am writing in a text file, by formatting NSString
objects to give to NSFileHandle -writeData.
Is it the preferable way? Are there any other class to work with
text-oriended files?

If you don’t need anything more, NSString includes writeToFile:.

What does a ‘text oriented file’ mean? You still have a format, whether that’s Windows-style INI, or JSON, or the ASCII and XML property list formats that are first-class citizens under GNUstep and similar systems? 

For portability of data to other languages, I’d say writing JSON is simplest. NSJSONSerialization is what you want.


Attachment: signature.asc
Description: Message signed with OpenPGP


reply via email to

[Prev in Thread] Current Thread [Next in Thread]