我正在使用下面的類,它有方法來提取字符串中的所有電子郵件,我是新的swift和它給我一個錯誤。有人可以請解釋爲什麼這個錯誤即將到來..? 感謝「通用參數'元素'無法被推斷出來」錯誤在迅速...?
import UIKit
import Foundation
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
if let results = extractEmailFromString("[email protected] heyyyyy cool [email protected]") {
print(results)
}
}
func extractEmailFromString(string:NSString) -> [String]? {
let pattern = "(\\+[a-zA-Z0-9._-][email protected][a-zA-Z0-9._-]+\\.[a-zA-Z0-9._-]+)"
let regexp = try! NSRegularExpression(pattern: pattern,
options: [.CaseInsensitive])
var results = [String]()
regexp.enumerateMatchesInString(string as String, options: NSMatchingOptions(rawValue: 0), range: NSRange(location: 0, length:string.length), usingBlock: { (result: NSTextCheckingResult!, _, _) in
results.append(string.substringWithRange(result.range))
})
return results
}
}
問題是什麼? – matt
@matt抱歉,提交時丟失了問題,我編輯了該問題。 –