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 isValidEmail() -> Bool { | |
| guard !self.lowercaseString.hasPrefix("mailto:") else { return false } | |
| guard let emailDetector = try? NSDataDetector(types: NSTextCheckingType.Link.rawValue) else { return false } | |
| let matches = emailDetector.matchesInString(self, options: NSMatchingOptions.Anchored, range: NSRange(location: 0, length: self.characters.count)) | |
| guard matches.count == 1 else { return false } | |
| return matches[0].URL?.scheme == "mailto" | |
| } | |
| } |
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
| import PlaygroundSupport | |
| import Foundation | |
| class Worker { | |
| private let queue = DispatchQueue.global(qos: .background) | |
| private let serialQueue = DispatchQueue(label: "com.acme.serial") | |
| public private(set) var count = 0 | |
| func incrementCount() { |
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
| // | |
| // Combine+WithLatestFrom.swift | |
| // | |
| // Created by Shai Mishali on 29/08/2019. | |
| // Copyright © 2019 Shai Mishali. All rights reserved. | |
| // | |
| import Combine | |
| // MARK: - Operator methods |
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
| import UIKit | |
| import WebKit | |
| open class ProgressObservableWebViewController: UIViewController, WKWebViewProgressObservable { | |
| @IBOutlet weak public var webView: WKWebView! | |
| public var webViewProgressObservation: Any? | |
| private let progressView: UIProgressView = { | |
| let view = UIProgressView(progressViewStyle: .default) |
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
| import Foundation | |
| public extension UIApplication { | |
| class func tryURL(_ urls: [String]) { | |
| let application = UIApplication.shared | |
| urls.forEach { urlString in | |
| guard let url = URL(string: urlString) else { | |
| Logger.error?.message("Cannot make url from: \(urlString)") | |
| return | |
| } |
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
| import UIKit | |
| public protocol UITableViewHeaderFooterViewIdentifiable: UITableViewHeaderFooterView { | |
| static var identifier: String { get } | |
| } | |
| public extension UITableViewHeaderFooterViewIdentifiable where Self: UITableViewHeaderFooterView { | |
| static var identifier: String { | |
| return String(describing: self) | |
| } |
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
| import Foundation | |
| import CommonCrypto | |
| internal enum CryptoError: Error { | |
| case emptyData | |
| case invalidData | |
| case invalidKey | |
| case fail(status: CCStatus) | |
| } |
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
| e print(String(data: JSONSerialization.data(withJSONObject: JSONSerialization.jsonObject(with: data, options: []), options: .prettyPrinted), encoding: .utf8)!) |
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 NSLayoutManager { | |
| var numberOfLines: Int { | |
| var linesCount: Int = 0 | |
| var idx: Int = 0 | |
| let lineRange: NSRangePointer = .allocate(capacity: 1) | |
| while idx < numberOfGlyphs { | |
| lineFragmentRect(forGlyphAt: idx, effectiveRange: lineRange) | |
| idx = NSMaxRange(lineRange.pointee) | |
| linesCount += 1 | |
| } |
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
| import UIKit | |
| public final class TextView: UITextView { | |
| public override init(frame: CGRect, textContainer: NSTextContainer?) { | |
| super.init(frame: frame, textContainer: textContainer) | |
| layoutManager.delegate = self | |
| isScrollEnabled = false | |
| } | |
OlderNewer