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
| @inlinable | |
| public __consuming func split(separator: Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true | |
| ) -> [ArraySlice<Element>] { | |
| return split(maxSplits: maxSplits, omittingEmptySubsequences: omittingEmptySubsequences, whereSeparator: { $0 == separator }) | |
| } | |
| } | |
| @inlinable | |
| public __consuming func split(maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true, whereSeparator isSeparator: (Element) throws -> Bool ) rethrows -> [ArraySlice<Element>] { | |
| _precondition(maxSplits >= 0, "Must take zero or more splits") |
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 search<T: Comparable>(target:T, slice:ArraySlice<T>) -> Int? { | |
| let lowIndex = slice.startIndex | |
| let highIndex = slice.endIndex - 1 | |
| while lowIndex <= highIndex { | |
| let midIndex = slice.startIndex + (highIndex - lowIndex)/2 | |
| let value = slice[midIndex] | |
| if target == value { |
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
| @inlinable | |
| public func map<T>( | |
| _ transform: (Element) throws -> T | |
| ) rethrows -> [T] { | |
| let initialCapacity = underestimatedCount | |
| var result = ContiguousArray<T>() | |
| result.reserveCapacity(initialCapacity) | |
| var iterator = self.makeIterator() |
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
| let word1 = "bat" | |
| let word2 = "cat" | |
| let lex_words = word1.lexicographicallyPrecedes(word2) | |
| print(lex_words) //result TRUE | |
| let zebra = "zebra" | |
| let giraffe = "giraffe" | |
| let lex_zoo = zebra.lexicographicallyPrecedes(giraffe) | |
| print(lex_zoo) //result FALSE |
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
| /* sample text */ | |
| let text = "this is some text where we can replace the last part... [+6025 characters]" | |
| /* | |
| * define a regular expression to search for text | |
| * see https://www.regular-expressions.info/ | |
| */ | |
| let pattern = "\\[.*\\]" | |
| /* create the regular expression with options */ |
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
| /* sample text */ | |
| let text = "this is some text where we can replace the last part... [+6025 characters]" | |
| /* | |
| * define a regular expression to search for text | |
| * see https://www.regular-expressions.info/ | |
| */ | |
| let pattern = "\\[.*\\]" | |
| /* search the text for the regular expression, returns the Range */ |
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
| let monitor = NWPathMonitor() | |
| /* closure called when path changes */ | |
| let pathUpdateHandler = {(path:NWPath) in | |
| let availableInterfaces = path.availableInterfaces | |
| if !availableInterfaces.isEmpty { | |
| //e.g. [ipsec4, en0, pdp_ip0] | |
| let list = availableInterfaces.map { $0.debugDescription }.joined(separator: "\n") | |
| } |
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
| + (BOOL)checkForVPNConnectivity:(NSString *)hostName { | |
| BOOL success = false; | |
| if (hostName.length == 0) { | |
| return success; | |
| } | |
| SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(NULL, [hostName UTF8String]); | |
| SCNetworkReachabilityFlags flags; | |
| success = SCNetworkReachabilityGetFlags(reachability, &flags); |
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 | |
| class ProfileViewController: UIViewController { | |
| private var profileImage:CircularImageView = { | |
| let imageView = CircularImageView(frame: .zero) | |
| imageView.translatesAutoresizingMaskIntoConstraints = false | |
| return imageView | |
| }() |
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 | |
| final class VerticalScrollingViewController: UIViewController { | |
| private lazy var scrollView:UIScrollView = { | |
| let scrollView = UIScrollView(frame:UIScreen.main.bounds) | |
| scrollView.translatesAutoresizingMaskIntoConstraints = false | |
| scrollView.preservesSuperviewLayoutMargins = true | |
| scrollView.backgroundColor = Theme.backgroundColor | |
| return scrollView |