Swift: Tipo de valor recursivo
Eu tenho uma estrutura na qual desejo ter uma variável global do tipo Struct ?. Este exemplo é essencialmente uma versão mais curta da estrutura que estou criando atualmente.
struct SplitString { //splits a string into parts before and after the first "/"
var preSlash: String = String()
var postSlash: SplitString? = nil
init(_ str: String) {
var arr = Array(str)
var x = 0
for ; x < arr.count && arr[x] != "/"; x++ { preSlash.append(arr[x]) }
if x + 1 < arr.count { //if there is a slash
var postSlashStr = String()
for x++; x < arr.count; x++ {
postSlashStr.append(arr[x])
}
postSlash = SplitString(postSlashStr)
}
}
}
No entanto, ele lança o erro:
Recursive value type 'SplitString' is not allowed
Existe alguma maneira de contornar isso? Qualquer ajuda seria ótimo. Obrigado :)
Edit: Caso seja relevante, estou programando no iOS, não no OSX.
Edit: Se eu tiver:
var split = SplitString("first/second/third")
Eu esperaria que a divisão fosse:
{preSlash = "first", postSlash = {preSlash = "second", postSlash = {preSlash = "third",
postSlash = nil}}}