You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
SR-10080 Unexpected behaviour with String/Range bridged from NSString/NSRange
Issue Description:
If you have a string bridged to objc and back to swift, range will be wrong:
letstring="You’ll be happy one day."letrange= string.range(of:"day")!
letnsString=NSMutableString()
nsString.append(string)letbridgedBack= nsString.copy()as!StringletnsRange=NSRange(range, in: bridgedBack)// Crash here because of out of boundsprint(nsString.substring(with: nsRange))// Location of NSRange is 22, but should be 20
Crash will not happen, however, if I didn't create mutable string, but just bridged Swift String to NSString, so:
letstring="You’ll be happy one day."letrange= string.range(of:"day")!
letnsString= string asNSStringletbridgedBack= nsString asStringletnsRange=NSRange(range, in: bridgedBack)// No crash, everything as expectedprint(nsString.substring(with: nsRange))
As a workaround, you could add bridgedBack + "" to make it work
letstring="You’ll be happy one day."letrange= string.range(of:"day")!
letnsString=NSMutableString()
nsString.append(string)letbridgedBack= nsString.copy()as!StringletnsRange=NSRange(range, in: bridgedBack +"")// No crash, everything as expectedprint(nsString.substring(with: nsRange))
The text was updated successfully, but these errors were encountered:
I believe this is correct behavior; unlike NSRange, a Range<String.Index> in one String cannot be used with another String. But @milseman can confirm/deny.
Environment
Swift 5.0.1
Additional Detail from JIRA
md5: ece32cfe96d1ab6bf46997a365bb2677
relates to:
Issue Description:
If you have a string bridged to objc and back to swift, range will be wrong:
Crash will not happen, however, if I didn't create mutable string, but just bridged Swift String to NSString, so:
As a workaround, you could add
bridgedBack + ""
to make it workThe text was updated successfully, but these errors were encountered: