NSString.getBytes(_:maxLength:usedLength:encoding:options:range:remainingRange:) crash issue

Hello! Recently, the following crash issue began to occur.

0	libswiftCore.dylib	0x000000019ffaa3c8 closure #1 in closure #1 in closure #1 in _assertionFailure+ 238536 (_:_:file:line:flags:) + 228
1	libswiftCore.dylib	0x000000019ffaa2a0 closure #1 in closure #1 in _assertionFailure+ 238240 (_:_:file:line:flags:) + 332
2	libswiftCore.dylib	0x000000019ffa9c2c _assertionFailure+ 236588 (_:_:file:line:flags:) + 184
3	libswiftCore.dylib	0x000000019ffac4fc specialized BidirectionalCollection._index+ 247036 (_:offsetBy:) + 1280
4	libswiftCore.dylib	0x00000001a016d630 String.UTF16View._indexRange+ 2086448 (for:from:) + 184
5	libswiftCore.dylib	0x00000001a018561c __StringStorage.getCharacters+ 2184732 (_:range:) + 112
6	libswiftCore.dylib	0x00000001a0185720 @objc __StringStorage.getCharacters+ 2184992 (_:range:) + 36
7	CoreFoundation	0x00000001a16893e0 __CFStringEncodeByteStream + 1864
8	Foundation	0x00000001a0527c94 -[NSString+ 208020 (NSStringOtherEncodings) getBytes:maxLength:usedLength:encoding:options:range:remainingRange:] + 260

...

It seems like assert is being called. Can you tell me a case that could be the cause? Also, this is a code I have been using for a long time, but recently it started crashing. Have there been any internal changes recently?

Please understand that the entire crash log cannot be attached for security reasons. Any help would be greatly appreciated!

Replies

Have there been any internal changes recently?

Yes. There are internal changes happening all the time. I suspect you’re crashing now because your code is being used with a string that was bridged from Swift, whereas previously it was always seeing a native NSString, but it’s hard to say without more context.

Please understand that the entire crash log cannot be attached for security reasons.

I really need a crash report to assist you properly. Can you post a redacted one? Posting a Crash Report has advice on how redact a crash report while still preserving enough of the format for it to be useful.

Alternatively, can you post a snippet of code, including the actual string you’re using, that reproduces the crash?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"