1

There are two issues, the first comes as a yellow message (warning):

var parameters are deprecated and will be removed in Swift3"<BR> If I fix it, the next line "searchText = ...." 

The second comes with a red message (error)

cannot assign to value: searchText is a let constant

Here is the code:

func filterContentForSearchText(var searchText: String, scope: NSInteger) {       
        searchText = searchText.lowercaseString;
}
jjNford
  • 5,170
  • 7
  • 40
  • 64

2 Answers2

0

In swift 3.0 variable parameters to functions will be removed. This is due to the designers of the language believe it can be ambiguous with inout variables. You can use shadowing to easily fix this like so:

func filterContentForSearchText(searchText: String, scope: NSInteger) {
    var searchText = searchText       
    searchText = searchText.lowercaseString;

Here we assign a local variable searchText to be the value of the constant searchText parameter. Due to shadowing the local variable is what is referenced when searchText is used.

Blake Lockley
  • 2,931
  • 1
  • 17
  • 30
  • Thanks for your help, why did you add the third line? –  Apr 04 '16 at 22:48
  • @Jade, in this instance its not necessary as `lowercaseString` is a computed var that returns a string so you can simply assign the result as you wish. But in a more general case I assumed the reason you made `searchText` a variable in the first place is because you want to preform some form of manipulation on it later on. – Blake Lockley Apr 04 '16 at 22:51
-1

Try this:

func filterContentForSearchText(searchText: String, scope: NSInteger) {       
       var searchText = searchText.lowercaseString;
Manolo
  • 469
  • 6
  • 20