0

I am using a var for IPAddress, for which i wanted to remove trailing slash (/). Now i see a warning that 'var' is deprecated. In such case how can i use removeAtIndex method in new style?

    if ipAddress.characters.last == "/" {
        ipAddress.removeAtIndex(ipAddress.endIndex.predecessor())
    }
Stephen
  • 3,359
  • 4
  • 20
  • 30
  • I can see no `var` in your code. It would be helpful to provide a *self-contained* example exhibiting the problem. – Martin R Apr 14 '16 at 07:06
  • you should provide a wider scope of your code, this one isn't enough to detect you var case. – turushan Apr 14 '16 at 07:08

1 Answers1

1

Remove var from the function parameter declaration and then create a mutable copy:

func myFunc(ipAddress: String) { // remove the var if you write here var ipAddress
    var ipAddress = ipAddress
    // change ipAddress here
}

var is only deprecated in function arguments.

See here the original change request: https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md

Darko
  • 9,655
  • 9
  • 36
  • 48
  • Doing so also giving warning. i wanted to know if var is removed, how do we use removeAtIndex ? – Stephen Apr 14 '16 at 07:01
  • var is not deprecated. What is the warning? – Darko Apr 14 '16 at 07:02
  • i have used inside the function, warning is: var parameters are deprecated and will be removed in Swift 3. clicking on that warning, showing me the line where i used var – Stephen Apr 14 '16 at 07:04
  • You have to remove var from the function signature. Show your function. – Darko Apr 14 '16 at 07:05
  • similar func exist in another path, deleted that file. Now no warning for var ipAddress = ipAddress inside the func. Thank you – Stephen Apr 14 '16 at 07:13