swift 中 NSRegularExpressions 的 NSArray [英] NSArray of NSRegularExpressions in swift
本文介绍了swift 中 NSRegularExpressions 的 NSArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
fork here 有一个自定义的链接函数,但实际代码中的实现是在目标 C.这是代码行和她它再次打印:
The fork here has a custom link function but the implementation in the actual code is in objective C.This is the code line and her it is printed again:
- (NSArray<NSRegularExpression*>*)getRegularExpressions
{
return [NSArray arrayWithObject:[NSRegularExpression regularExpressionWithPattern:@"#([a-zA-Z0-9])+" options:0 error:NULL]];
}
我想知道如何在 swift 中重现这个,我已经放置了所有框架代码,我只需要知道如何做到这一点.
I was wondering how i could reproduce this in swift, I have already placed all of the framework code, I just need to know how to do this.
推荐答案
试试这个
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;
}
希望对你有帮助
这篇关于swift 中 NSRegularExpressions 的 NSArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文