Have a look here to see how to get the text in a textView ; you could also just put in in a temporary or just make the outlet hidden :
http : / / stackoverflow.com/questions/29679229/how-to-upload-rtf-file-in-ui-text-view-in-swift-code
import UIKit
import Foundation
class ViewController: UIViewController {
var fullText = "" as NSString
@IBOutlet var textView: UITextView!
override func viewDidLoad() {
super.viewDidLoad()
if let rtf = NSBundle.mainBundle().URLForResource("rtfdoc", withExtension: "rtf", subdirectory: nil, localization: nil) {
do {
let attrString = try NSMutableAttributedString(URL: rtfPath, options: [NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType], documentAttributes: nil)
textView.attributedText = attrString
// or
fullText = attrString.string as NSString // that will ease search
} catch{}
}
}
}
Once you have the text, you can search for the substring in it:
let startingSequence = theZipCode
let startRange = fullText.rangeOfString(startingSequence)
if startRange.length > 0 {
// create a "OK" alert
} else {
show an alternative alert
}
Thanks to tell if that works.