Error in swift 'split' function

IDE: Visual Studio 2015 Community
Version: 9.0.97.2071
Target Android (not tested with other targets)
Description: Swift code with wrong behaviour:

var S: String = "1,,"
var Parts = S.split(",")

Expected Behavior:

Parts[0] = "1"
Parts[1] = ""
Parts[2] = ""

Actual Behavior:

Parts[0] = "1"
// If I try to access Parts[1] or Parts[2], java.lang.ArrayIndexOutOfBoundsException ocurrs

Yup, funnily i just found and fixed that same issue for RTL2; will need to apply the same fix to SwiftBaseLibrary. currently SBL just passes thru to java.String.split(), which unfortunately drops off empty items at the end :(.

—marc

1 Like

Actually, i can only fix this for SwiftString (which is not active yet on SBL to act as the main String type). Swift.String currently is just an alias for the platform-native string types, so it has no choice but to use the platform’s implementation of split() :(.

Workaround, use latest SBL from GitHub once my fix is committed, and convert to a SwiftSting and call split() on that. In a future update of Elements and SBL, SwiftString will drop in to become the default string type when using SBL — but it’s not quite ready for that yet.

1 Like