私は以下のクラスを使用しています。文字列内のすべての電子メールを抽出する方法を持っています。私は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申し訳ありませんが提出中に質問が失われました。私は質問を編集しました。 –