๐
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 XCTest | |
class LoginTests: XCTestCase { | |
var app: XCUIApplication! | |
func testLogin() { | |
continueAfterFailure = false | |
app = XCUIApplication() | |
app.launch() | |
passLogin() | |
} | |
} |
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 navigationBar = UINavigationBar() | |
navigationBar.isTranslucent = false | |
navigationBar.delegate = self | |
navigationBar.backgroundColor = .white | |
navigationBar.items = [standaloneItem] | |
navigationBar.translatesAutoresizingMaskIntoConstraints = false | |
navigationBar.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true | |
navigationBar.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true | |
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
override func viewWillAppear(_ animated: Bool) { | |
super.viewWillAppear(animated) | |
if navigationController != nil { | |
let label = HeaderElement.makeLabel() | |
label.sizeToFit() | |
navigationItem.titleView = label | |
navigationBar.isHidden = true | |
} else { | |
navigationBar.isHidden = 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
let standaloneItem = UINavigationItem() | |
standaloneItem.leftBarButtonItem = UIBarButtonItem(customView: closeButton) | |
standaloneItem.titleView = UILabel() |
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
public func validate(expression: String) -> String { | |
let set = Set("0123456789()+-*/") | |
return expression | |
.replacingOccurrences(of: "/n", with: "") | |
.filter({ set.contains($0) }) | |
} |
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 CGRect { | |
func scaleUp(scaleUp: CGFloat) -> CGRect { | |
let biggerRect = self.insetBy( | |
dx: -self.size.width * scaleUp, | |
dy: -self.size.height * scaleUp | |
) | |
return biggerRect | |
} | |
} |
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
private func cropImage(image: UIImage, normalisedRect: CGRect) -> UIImage? { | |
let x = normalisedRect.origin.x * image.size.width | |
let y = normalisedRect.origin.y * image.size.height | |
let width = normalisedRect.width * image.size.width | |
let height = normalisedRect.height * image.size.height | |
let rect = CGRect(x: x, y: y, width: width, height: height).scaleUp(scaleUp: 0.1) | |
guard let cropped = image.cgImage?.cropping(to: rect) else { | |
return nil |
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
private func drawBox(overlayLayer: CALayer, normalisedRect: CGRect) { | |
let x = normalisedRect.origin.x * overlayLayer.frame.size.width | |
let y = normalisedRect.origin.y * overlayLayer.frame.size.height | |
let width = normalisedRect.width * overlayLayer.frame.size.width | |
let height = normalisedRect.height * overlayLayer.frame.size.height | |
let outline = CALayer() | |
outline.frame = CGRect(x: x, y: y, width: width, height: height).scaleUp(scaleUp: 0.1) | |
outline.borderWidth = 2.0 | |
outline.borderColor = UIColor.red.cgColor |
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
private func normalise(box: VNTextObservation) -> CGRect { | |
return CGRect( | |
x: box.boundingBox.origin.x, | |
y: 1 - box.boundingBox.origin.y - box.boundingBox.height, | |
width: box.boundingBox.size.width, | |
height: box.boundingBox.size.height | |
) | |
} |
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
private func makeRequest(image: UIImage) { | |
guard let cgImage = image.cgImage else { | |
assertionFailure() | |
return | |
} | |
let handler = VNImageRequestHandler( | |
cgImage: cgImage, | |
orientation: CGImagePropertyOrientation.up, | |
options: [VNImageOption: Any]() |