# StringBuilder

**URL:** https://talk.remobjects.com/t/stringbuilder/25975
**Category:** Elements RTL
**Created:** [January 4, 2022, 3:17am UTC](https://talk.remobjects.com/t/stringbuilder/25975 "2022-01-04T03:17:27Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 4, 2022, 3:17am UTC](https://talk.remobjects.com/t/stringbuilder/25975/1 "2022-01-04T03:17:27Z")

</div>

Hi,

In RTL2 for toffee stringbuilder is mapped to Foundation.NSMutableString. On a stringbuilder I can do ToString. Where does ToString come from ? It’s not part of the StringBuilder class, on NSString or NSObject.

It looks like on watchos it doesnt exist, I get

‘NSInvalidArgumentException’, reason: ‘-[\_\_NSCFString ToString]: unrecognized selector sent to instance 0x600002afcf60’

terminating with uncaught exception of type NSException

CoreSimulator 783.5 - Device: Apple Watch Series 7 - 45mm

Cheers,  
John

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 4, 2022, 12:13pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/2 "2022-01-04T12:13:43Z")

</div>

> [@JohnMoshakis](#):
>
> In RTL2 for toffee stringbuilder is mapped to Foundation.NSMutableString. On a stringbuilder I can do ToString. Where does ToString come from ? It’s not part of the StringBuilder class, on NSString or NSObject.

ToString should map to `description` on Cocoa, unless explicitly implemented/overriden.

> [@JohnMoshakis](#):
>
> It looks like on watchos it doesnt exist, I get
> 
> ‘NSInvalidArgumentException’, reason: ‘-[\_\_NSCFString ToString]: unrecognized selector sent to instance 0x600002afcf60’
> 
> terminating with uncaught exception of type NSException
> 
> CoreSimulator 783.5 - Device: Apple Watch Series 7 - 45mm

Hmm. same is fine on macOS or iOS, or you didn’t test?

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 4, 2022, 2:09pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/3 "2022-01-04T14:09:38Z")

</div>

Thanks. Yes I tested on macos

That error is saying that the method doesnt exist ?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 4, 2022, 6:05pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/4 "2022-01-04T18:05:33Z")

</div>

yeah, ToString _won’t_ exist, it’s called `description`, the compiler should handle this. I’ll try too. Island or Toffee V1 or ToffeeV2?

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 4, 2022, 6:07pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/5 "2022-01-04T18:07:29Z")

</div>

FWIW, this is fine for me on Toffee/macOS:

```auto
      writeLn('The magic happens here.');
      var x := new StringBuilder;
      x.Append("Hello");
      writeLn($"x {x}");
      writeLn($"x.ToString {x.ToString}");

```

but it might also matter how you call ToString/how ToString gets called implicitly.

**Update** also fine on ToffeeV2 and pure Island (macOS; im not in a position to test watchOS without losing a day and my sanity 😉

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 4, 2022, 6:14pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/6 "2022-01-04T18:14:25Z")

</div>

Its Toffee v1. It also works for me with macos.

The stack seems to indicate its coming from JsonTokenizer in the parse method. I’ll have a go later will just a simple example and see if that works.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 4, 2022, 6:31pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/7 "2022-01-04T18:31:41Z")

</div>

> [@JohnMoshakis](#):
>
> It also works for me with macos.

:(. thats gonna make this tricky.

> [@JohnMoshakis](#):
>
> The stack

Can you share this stack, and the line of user code that it starts with?

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 4, 2022, 7:14pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/8 "2022-01-04T19:14:50Z")

</div>

I’ll create an example that just uses stringbuilder and see if that has the same issue

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 4, 2022, 8:11pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/9 "2022-01-04T20:11:42Z")

</div>

![Screen Shot 2022-01-04 at 3.04.18 PM](https://talk.remobjects.com/uploads/default/original/3X/7/1/714d06fd023c7269d1a71330d180a20c13635129.png)  
[ToffeeWatchLibrary.zip](https://talk.remobjects.com/uploads/short-url/vcL8LZhXyaZXIVM5W6Ax54ZilI8.zip) (110.6 KB)  
That is my static library. Im just building the Toffee watch os version

This is swift xcode project

> **[MyWatchApp.zip](https://drive.google.com/file/d/12RQ1AUwPotrQ1PmVFVglcRq7hewf9EiK/view?usp=sharing)**
>
> Google Drive file.

---

<div class="post-metadata">

### Author: ![RemObjectsSoftware](https://talk.remobjects.com/user_avatar/talk.remobjects.com/remobjectssoftware/32/15947_2.png) [@RemObjectsSoftware](https://talk.remobjects.com/u/RemObjectsSoftware)
#### Post date: [January 4, 2022, 8:53pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/10 "2022-01-04T20:53:01Z")

</div>

Logged as [bugs://E25606](https://www.remobjects.com/portal/bugs/?id=E25606).

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 4, 2022, 8:54pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/11 "2022-01-04T20:54:41Z")

</div>

thanx.

if you replace exit with

writeLn(builder);  
//writeLn(builder.ToString);  
result := builder as Stting

does it work? (even if you cant see the writeLn probably):?

```auto
      var builder := new StringBuilder;
      builder.Append('hello ');
      builder.Append('from ');
      builder.Append('StringBuilder');
      exit builder.ToString;

```

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 5, 2022, 12:19am UTC](https://talk.remobjects.com/t/stringbuilder/25975/12 "2022-01-05T00:19:35Z")

</div>

result := builder as String

worked

---

<div class="post-metadata">

### Author: ![ck](https://talk.remobjects.com/user_avatar/talk.remobjects.com/ck/32/8740_2.png) [@ck](https://talk.remobjects.com/u/ck)
#### Post date: [January 5, 2022, 9:28am UTC](https://talk.remobjects.com/t/stringbuilder/25975/13 "2022-01-05T09:28:24Z")

</div>

So this is a little trickier than it sounds. ToString is an extension method:

```auto
extension method Foundation.NSObject.ToString: PlatformString;public;
begin
  result := description;
end;

```

@mh I think this will need debugging on a watch.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 5, 2022, 12:28pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/15 "2022-01-05T12:28:44Z")

</div>

John: are you linking in libToffee for this one?

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 5, 2022, 2:02pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/16 "2022-01-05T14:02:11Z")

</div>

Yes I am

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 5, 2022, 2:26pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/17 "2022-01-05T14:26:10Z")

</div>

damn. SOund slike maybe a linker issue eliminating the symbol :(.

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 5, 2022, 2:30pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/18 "2022-01-05T14:30:39Z")

</div>

Can you send me your wacthOS exe binary?

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 5, 2022, 3:48pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/19 "2022-01-05T15:48:03Z")

</div>

[MyWatchApp WatchKit Extension.appex.zip](https://talk.remobjects.com/uploads/short-url/zDlL6n4wyJuCcenSNVAvmocUfGT.zip) (627.6 KB)

---

<div class="post-metadata">

### Author: ![mh](https://talk.remobjects.com/user_avatar/talk.remobjects.com/mh/32/18050_2.png) [@mh](https://talk.remobjects.com/u/mh)
#### Post date: [January 6, 2022, 9:27pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/20 "2022-01-06T21:27:53Z")

</div>

Do you have `-ObjC` in the linker flags in Xcode? if not, can you add it?

---

<div class="post-metadata">

### Author: ![JohnMoshakis](https://talk.remobjects.com/user_avatar/talk.remobjects.com/johnmoshakis/32/2286_2.png) [@JohnMoshakis](https://talk.remobjects.com/u/JohnMoshakis)
#### Post date: [January 6, 2022, 9:36pm UTC](https://talk.remobjects.com/t/stringbuilder/25975/21 "2022-01-06T21:36:02Z")

</div>

I dont and it fixes it 🙂 What does that do ?

[Next page](https://talk.remobjects.com/t/stringbuilder/25975.md?page=2)
