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 ViewController { | |
| private func setNotificationForKeyboardAppearance() { | |
| NotificationCenter.default.addObserver( | |
| self, | |
| selector: #selector(self.keyboardWillShow), | |
| name: UIResponder.keyboardWillShowNotification, | |
| object: nil) | |
| NotificationCenter.default.addObserver( |
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 syncOnMainThread<T>(execute block: () throws -> T) rethrows -> T { | |
| if Thread.isMainThread { | |
| return try block() | |
| } | |
| return DispatchQueue.main.sync(execute: block) | |
| } |
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
| enum ScreenSize { | |
| static let width = UIScreen.main.bounds.size.width | |
| static let height = UIScreen.main.bounds.size.height | |
| static let maxLength = max(ScreenSize.width, ScreenSize.height) | |
| static let minLength = min(ScreenSize.width, ScreenSize.height) | |
| } | |
| enum DeviceTypes { | |
| static let idiom = UIDevice.current.userInterfaceIdiom |
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 { | |
| var isValidEmail: Bool { | |
| let emailFormat = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}" | |
| let emailPredicate = NSPredicate(format: "SELF MATCHES %@", emailFormat) | |
| return emailPredicate.evaluate(with: self) | |
| } | |
| var isValidPassword: Bool { | |
| //Regex restricts to 8 character minimum, 1 capital letter, 1 lowercased letter, 1 number | |
| let passwordFormat = "(?=.*[A-Z])(?=.*[0-9])(?=.*[a-z]).{8,}" |
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 application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | |
| // Override point for customization after application launch. | |
| if let navController = window!.rootViewController as? UINavigationController { | |
| navController.delegate = self | |
| let appearance2 = UINavigationBarAppearance() | |
| appearance2.backgroundColor = .systemBlue | |
| appearance2.titleTextAttributes = [.foregroundColor: UIColor.white] | |
| appearance2.largeTitleTextAttributes = [.foregroundColor: UIColor.white] | |
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
| protocol Endpoint { | |
| var scheme: String { get } | |
| var host: String { get } | |
| var path: String { get } | |
| var method: RequestMethod { get } | |
| var header: [String: String]? { get } | |
| var body: [String: String]? { get } | |
| } | |
| extension Endpoint { |
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 quickSort(nums: [Int]) -> [Int] { | |
| if nums.count < 2 { | |
| return nums | |
| } else { | |
| let pivot = nums[0] | |
| var lessPart: [Int] = [] | |
| var greaterPart: [Int] = [] | |
| for i in 1..<nums.count { |
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 recursiveSum(_ nums: [Int]) -> Int { | |
| if nums.count == 0 { | |
| return 0 | |
| } else { | |
| return nums[0] + recursiveSum(Array(nums.dropFirst())) | |
| } | |
| } |
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 | |
| extension Bundle { | |
| func decode<T: Codable> (_ file: String) -> T { | |
| guard let url = self.url(forResource: file, withExtension: nil) else { | |
| fatalError("Failed to locate \(file) in bundle.") | |
| } | |
| guard let data = try? Data(contentsOf: url) else { | |
| fatalError("Failed to load \(file) from bundle.") |
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
| disabled_rules: | |
| - trailing_whitespace | |
| - colon | |
| - comma | |
| - control_statement | |
| - vertical_whitespace | |
| - switch_case_alignment | |
| - opening_brace | |
| - comment_spacing | |
| - trailing_newline |
NewerOlder