ios - NSCaseInsensitiveSearch RangeOfString search Swift -


i'm attempting write following code in swift, having trouble doing so:

objective - c:

nsarray * seacharray = [sessionsearchresults filteredarrayusingpredicate:[nspredicate predicatewithblock:^bool(productmodel* evaluatedobject, nsdictionary *bindings) {     return [evaluatedobject.productname rangeofstring:searchstring options:nscaseinsensitivesearch].location != nsnotfound; }]]; 

swift (what have far)

func searchdisplaycontroller(controller: uisearchdisplaycontroller, shouldreloadtableforsearchstring searchstring: string!) -> bool {      let filteredarray = searcharray.filter { (session: productmodel) -> bool in         //contains string?         return session.productname == searchstring      }      var s : string     s in filteredarray {             println(s)     }      return true } 

just curious. there away achieve without importing foundation?

short answer: no.

swift has straightforward bridging between it's classes , foundation classes, e.g. string nsstring.

nsstring has incredibly rich set of methods. don't afraid of foundation, embrace it.

however, means importing foundation.

your alternative write own native swift functions replace foundation apis. can function here or there if want to, seems absurd. there millions of lines of industrial grade, efficient, tested code behind foundation classes. part of runtime environment. learn use them.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -