Skip to content

Instantly share code, notes, and snippets.

View onmyway133's full-sized avatar
๐Ÿ˜‡
What you don't know is what you haven't learned

Khoa onmyway133

๐Ÿ˜‡
What you don't know is what you haven't learned
View GitHub Profile
import XCTest
class LoginTests: XCTestCase {
var app: XCUIApplication!
func testLogin() {
continueAfterFailure = false
app = XCUIApplication()
app.launch()
passLogin()
}
}
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
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
let standaloneItem = UINavigationItem()
standaloneItem.leftBarButtonItem = UIBarButtonItem(customView: closeButton)
standaloneItem.titleView = UILabel()
public func validate(expression: String) -> String {
let set = Set("0123456789()+-*/")
return expression
.replacingOccurrences(of: "/n", with: "")
.filter({ set.contains($0) })
}
extension CGRect {
func scaleUp(scaleUp: CGFloat) -> CGRect {
let biggerRect = self.insetBy(
dx: -self.size.width * scaleUp,
dy: -self.size.height * scaleUp
)
return biggerRect
}
}
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
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
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
)
}
private func makeRequest(image: UIImage) {
guard let cgImage = image.cgImage else {
assertionFailure()
return
}
let handler = VNImageRequestHandler(
cgImage: cgImage,
orientation: CGImagePropertyOrientation.up,
options: [VNImageOption: Any]()