# The peculiar case of NSString bridged strings

**URL:** <https://forums.swift.org/t/the-peculiar-case-of-nsstring-bridged-strings/59774>\
**Category:** Using Swift\
**Tags:** string, bridging\
**Created:** [August 20, 2022, 1:02am UTC](https://forums.swift.org/t/the-peculiar-case-of-nsstring-bridged-strings/59774 "2022-08-20T01:02:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![tera](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/tera/32/38201_2.png) [@tera](https://forums.swift.org/u/tera)\
**Post date:** [August 20, 2022, 1:02am UTC](https://forums.swift.org/t/the-peculiar-case-of-nsstring-bridged-strings/59774/1 "2022-08-20T01:02:22Z")

</div>

Found an interesting peculiarity in Strings bridged from NSString. In the following fragment I run the app and use the same string for string2 variable as the string1 obtained from the stringsdict file:

```swift
    let string1: String = NSLocalizedString("fileCountString", comment: "")
    let string2: String = "You have %#@X@"
    print(string1) // "You have %#@X@"
    print(string2) // "You have %#@X@"
    assert(string1 == string2) // ✅ OK

```

This fragment runs ok and the two strings are obviously equal. So far so good. Now to the odd part:

```swift
    let converted1: String = String.localizedStringWithFormat(string1, 1)
    let converted2: String = String.localizedStringWithFormat(string2, 1)
    print(converted1) // "You have 1 file"
    print(converted2) // "You have %#@X@"
    assert(converted1 == converted2) // 🛑 fails obviously

```

The two "equal" strings passed to `localizedStringWithFormat` give two different results. Feels like magic. Or it's just localizedStringWithFormat implementation compares string references instead of calling `isEqual`.

Interestingly the third string created from the first:

```
let string3 = NSString(string: string1) as String

```

also equal to the other two strings and behaves like string2 (becomes nonlocalizable).

---

<div class="post-metadata">

**Author:** ![David\_Smith](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/david_smith/32/37508_2.png) [@David\_Smith](https://forums.swift.org/u/David_Smith)\
**Post date:** [August 20, 2022, 2:03am UTC](https://forums.swift.org/t/the-peculiar-case-of-nsstring-bridged-strings/59774/2 "2022-08-20T02:03:27Z")

</div>

Should be fixed in [[5.7] Handle long tagged NSStrings by Catfish-Man · Pull Request #60477 · apple/swift · GitHub](https://github.com/apple/swift/pull/60477)
