Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios NSRegularExpressions在swift中的数组_Ios_Objective C_Swift_Nsarray_Nsregularexpression - Fatal编程技术网

Ios NSRegularExpressions在swift中的数组

Ios NSRegularExpressions在swift中的数组,ios,objective-c,swift,nsarray,nsregularexpression,Ios,Objective C,Swift,Nsarray,Nsregularexpression,fork有一个自定义链接函数,但实际代码中的实现在objective C中。是代码行,它将再次打印: - (NSArray<NSRegularExpression*>*)getRegularExpressions { return [NSArray arrayWithObject:[NSRegularExpression regularExpressionWithPattern:@"#([a-zA-Z0-9])+" options:0 error:NULL]]; } -(NS

fork有一个自定义链接函数,但实际代码中的实现在objective C中。是代码行,它将再次打印:

- (NSArray<NSRegularExpression*>*)getRegularExpressions
{
   return [NSArray arrayWithObject:[NSRegularExpression regularExpressionWithPattern:@"#([a-zA-Z0-9])+" options:0 error:NULL]];
}
-(NSArray*)getRegularExpressions
{
返回[NSArray arrayWithObject:[NSRegularExpression regularExpressionWithPattern:@“#”([a-zA-Z0-9])+”选项:0错误:NULL];
}
我想知道如何在swift中重现这一点,我已经放置了所有的框架代码,我只需要知道如何做到这一点。

试试这个

func getRegularExpressions() -> [NSRegularExpression] {
    var arrayOfExpressions = [NSRegularExpression]()
    do
    {
        let expresion = try NSRegularExpression(pattern: "#([a-zA-Z0-9])+", options:.CaseInsensitive)
        arrayOfExpressions.append(expresion)
    }catch _
    {
        arrayOfExpressions.removeAll()
        return arrayOfExpressions
    }
    return arrayOfExpressions;
}

我希望这对你有帮助

到目前为止你都做了些什么?@Jacolack如果我能解决你的问题,你能在我的叉子里放一颗星星吗?谢谢