👓 NSPredicate
A definition of logical conditions used to constrain a search either for a fetch or for in-memory filtering.
📔 Check validity of URL Source Code by Swift
func checkValidWebURL(url: String) -> Bool {
let urlRegEx = "^(https?://)?(www\\.)?([-a-z0-9]{1,63}\\.)*?[a-z0-9][-a-z0-9]{0,61}[a-z0-9]\\.[a-z]{2,6}(/[-\\w@\\+\\.~#\\?&/=%]*)?$"
let urlTest = NSPredicate(format:"SELF MATCHES %@", urlRegEx)
if urlTest.evaluate(with: url) {
return true
}
let range = NSRange(location: 0, length: url.utf16.count)
guard let detector = try? NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue),
let match: NSTextCheckingResult = detector.firstMatch(in: url, options: [], range: range) else {
return false
}
return match.range.length == url.utf16.count
}
🚀 REFERENCE
How to check validity of URL in Swift?
Trying to make an app launch the default browser to a URL, but only if the URL entered is valid, otherwise it displays a message saying the URL is invalid. How would I go about checking the validity
stackoverflow.com
ChangYeop-Yang/Study-macOS
macOS는 기업 애플이 제작한 운영 체제이다. 2002년 4월부터 모든 매킨토시 컴퓨터에 적용되고 있다. - ChangYeop-Yang/Study-macOS
github.com
Predicate Format String Syntax
SELF Represents the object being evaluated. Comma-separated literal array For example, { 'comma', 'separated', 'literal', 'array' }. Standard integer and fixed-point notations For example, 1, 27, 2.71828, 19.75. 0x Prefix used to denote a hexadecimal digit
developer.apple.com
[iOS/OSX] predicate를 사용한 배열의 필터 · Wireframe
배열을 필터하기 특정한 값을 만족하는 원소만을 추출하여 부분 집합을 구하는 작업을 종종 해야 할 때가 있다. 배열에 대한 정렬 보다 간단하다면 간단하고 어렵다면 어려운데, predicate를 사용하면 쉽게 추출이 가능한데, 이 predicate를 사용하는 문법이 별도로 존재하기 때문에 조금 성가실 수 있다. (하지만 영문법과 크게 다르지 않다) NSMutaleArray *array = [NSMutableArray arrayWithObjects:@"Bill
soooprmx.com
댓글