Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't pass 0 to NSRegularExpression options?

Tags:

swift

I'm getting the error:

Could not find an overload for 'init' that accepts the supplied arguments

when I type:

var expr = NSRegularExpression(pattern: "test", options: 0, error: nil)

The error goes away if I pass a NSRegularExpressionOptions member...

How can I pass no options to NSRegularExpression's init?

like image 570
aleclarson Avatar asked Jun 07 '14 07:06

aleclarson


2 Answers

In Swift 2 nil is not accepted, and the error is no longer an output parameter (it is thrown), so it becomes:

var expr = try NSRegularExpression(pattern: "test", options: [])
like image 158
sjs Avatar answered Nov 06 '22 12:11

sjs


Use nil instead of 0. NSRegularExpressionOptions is a struct so you cannot pass an integer in for that parameter. In Objective-C the regular expression options were done with enums which evaluated to ints.

var expr = NSRegularExpression(pattern: "test", options: nil, error: nil)
like image 12
Dash Avatar answered Nov 06 '22 14:11

Dash