This regex splits an http or https url into its parts.
^(?:(?:(?:(http[s]?):\/\/)(?:([a-zA-Z0-9]+)?\.)?([^:\/\s\?]+\.+[^:\/\s\?]+))?(?:((?:\/[^\/\s]+)*\/)?(?:([\w\-\.]+[^#?\s]+))?)?(#[^#?\s]+)?(?:\?+([^\.\s$]+)?)?)$
- Whole match
| // get a complementary color to this color: | |
| func getComplementaryForColor(color: UIColor) -> UIColor { | |
| let ciColor = CIColor(color: color) | |
| // get the current values and make the difference from white: | |
| let compRed: CGFloat = 1.0 - ciColor.red | |
| let compGreen: CGFloat = 1.0 - ciColor.green | |
| let compBlue: CGFloat = 1.0 - ciColor.blue | |
| func getRandomColor(minVal: Int = 0, maxVal: Int = 255) -> UIColor { | |
| // get random values between the min value (0) and max value (255): | |
| let randomRed: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
| let randomGreen: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
| let randomBlue: Int = Int(arc4random_uniform(UInt32(maxVal-minVal+1)))+minVal | |
| return UIColor(red: CGFloat(Float(randomRed) / Float(255)), green: CGFloat(Float(randomGreen) / Float(255)), blue: CGFloat(Float(randomBlue) / Float(255)), alpha: 1.0) | |
| } |
| extension String { | |
| subscript (i: Int) -> Character { | |
| get { | |
| assert(i < self.characters.count && i >= 0, "Index out of range.") | |
| return self[self.index(self.startIndex, offsetBy: String.IndexDistance(i))] | |
| } | |
| set { | |
| assert(i < self.characters.count && i >= 0, "Index out of range.") | |
| let index = self.index(self.startIndex, offsetBy: String.IndexDistance(i)) | |
| let endIndex = self.index(self.startIndex, offsetBy: String.IndexDistance(i+1)) |
| extension String { | |
| func substring(from: UInt, length: UInt) -> String { | |
| if Int(from) >= self.characters.count { | |
| preconditionFailure("from is out of bounds.") | |
| } | |
| if Int(from+length) > self.characters.count { | |
| preconditionFailure("from and lenght are out of bounds") | |
| } | |
| let startIndex = self.index(self.startIndex, offsetBy: String.IndexDistance(from)) |
| extension String { | |
| func localize() -> String { | |
| return NSLocalizedString(self, comment: "") | |
| } | |
| func localize(_ args: CVarArg...) -> String { | |
| return String(format: NSLocalizedString(self, comment: ""), args) | |
| } | |
| } |
| import Cocoa | |
| import RxSwift | |
| import RxCocoa | |
| infix operator <-> | |
| func <-> <T>(property: ControlProperty<T>, variable: BehaviorRelay<T>) -> Disposable { | |
| let bindToUIDisposable = variable.asObservable() | |
| .bind(to: property) |
| struct RgxResult { | |
| private let textCheckingResult: NSTextCheckingResult | |
| private let baseString: String | |
| init(_ result: NSTextCheckingResult, _ baseString: String) { | |
| self.textCheckingResult = result | |
| self.baseString = baseString | |
| } | |
| } |
| import Foundation | |
| import SwiftUI | |
| struct AlertButton: Identifiable { | |
| var id: String { | |
| title | |
| } | |
| let title: String | |
| let style: ButtonRole? |