This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension String { | |
| func link() -> URL? { | |
| let detector = try! NSDataDetector(types: NSTextCheckingResult.CheckingType.link.rawValue) | |
| let matches = detector.matches(in: self, options: [], range: NSRange(location: 0, length: self.count)) | |
| if matches.count > 0 { | |
| for result in matches { | |
| if let urlString = result.url?.absoluteString { | |
| let url = URL(string: urlString) | |
| return url |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func checkHashTags() { | |
| let matchedString = matches(for: "[##][A-Za-zA-Za-z0-90-9가-힣ㄱ-ㅎぁ-ヶヲ-゚ー]+", in: self.text) | |
| print(matchedString) | |
| } | |
| func matches(for regex: String, in text: String) -> [String] { | |
| do { | |
| let regex = try NSRegularExpression(pattern: regex) | |
| let nsString = text as NSString |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UITextInput { | |
| var selectedRange: NSRange? { | |
| guard let range = selectedTextRange else { return nil } | |
| let location = offset(from: beginningOfDocument, to: range.start) | |
| let length = offset(from: range.start, to: range.end) | |
| return NSRange(location: location, length: length) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension AVPlayerItem { | |
| enum TrackType { | |
| case subtitle | |
| case audio | |
| /** | |
| Return valid AVMediaSelectionGroup is item is available. | |
| */ | |
| fileprivate func characteristic(item:AVPlayerItem) -> AVMediaSelectionGroup? { | |
| let str: AVMediaCharacteristic = self == .subtitle ? .legible : .audible | |
| if item.asset.availableMediaCharacteristicsWithMediaSelectionOptions.contains(str) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extension UIImageView { | |
| func start(){ | |
| guard layer.sublayers?.first(where: {$0.name == "AnimatingGradient"}) == nil else { return } | |
| let light = UIColor(white: 1, alpha: 1).cgColor | |
| let alpha = UIColor.lightGray.cgColor | |
| let gradient = CAGradientLayer() | |
| gradient.name = "AnimatingGradient" |