regex - Error after updating to xcode 7 : Cannot invoke initializer for type 'NSRegularExpression' with an argument list of type -
get following error after updating xcode: "cannot invoke initializer type 'nsregularexpression' argument list of type '(pattern: string, options: nilliteralconvertible, error: nilliteralconvertible)'"
following code cause error:
func applystylestorange(searchrange: nsrange) { let normalattrs = [nsfontattributename : uifont.preferredfontfortextstyle(uifonttextstylebody)] // iterate on each replacement (pattern, attributes) in replacements { let regex = nsregularexpression(pattern: pattern, options: nil, error: nil)! regex.enumeratematchesinstring(backingstore.string, options: nil, range: searchrange) { match, flags, stop in // apply style let matchrange = match.rangeatindex(1) self.addattributes(attributes, range: matchrange) // reset style original let maxrange = matchrange.location + matchrange.length if maxrange + 1 < self.length { self.addattributes(normalattrs, range: nsmakerange(maxrange, 1)) } } }
error @ line:- let regex = nsregularexpression(pattern: pattern, options: nil, error: nil)! please suggest me how resolve it.
the initalizer throwable , needs option:
do { let regex = try nsregularexpression(pattern: "youpattern", options: nsregularexpressionoptions.caseinsensitive) } catch { print(error) }
Comments
Post a Comment