Cannot convert value of type "String" to type "NSString" in coercion when I use self swift2 with ubuntu 16.04

I have a problem with code that produces the following message:

error: cannot convert value of type 'String' to type 'NSString' in coercion return (self as NSString).substringWithRange(range) 

I could solve this earlier, but not with self-clearance, so here is the code:

 let range = expression.rangeOfFirstMatchInString(self, options: [], range: NSMakeRange(0, self.utf16.count)) if range.location != NSNotFound { return (self as NSString).substringWithRange(range) } return nil 
+8
ubuntu swift
source share
1 answer

The fast compiler in Ubuntu will not automatically recognize that NSString has a constructor that takes a String as an argument. (during compilation, the compiler interprets it)

Instead, do the work yourself by writing

 NSString(string: self) 
+9
source share

All Articles