This file contains 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 createVisionRequest(image: UIImage){ | |
currentImage = image | |
guard let cgImage = image.cgImage else { | |
return | |
} | |
let requestHandler = VNImageRequestHandler(cgImage: cgImage, orientation: image.cgImageOrientation, options: [:]) | |
let vnRequests = [vnTextDetectionRequest] | |
DispatchQueue.global(qos: .background).async { |
This file contains 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: UIImagePickerControllerDelegate, UINavigationControllerDelegate { | |
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]) { | |
picker.dismiss(animated: true) | |
guard let uiImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage else { | |
fatalError("Error!") | |
} | |
imageView.image = uiImage | |
createVisionRequest(image: uiImage) |
This file contains 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
guard UIImagePickerController.isSourceTypeAvailable(.camera) else { | |
presentPhotoPicker(sourceType: .photoLibrary) | |
return | |
} | |
let photoSourcePicker = UIAlertController() | |
let takePhoto = UIAlertAction(title: "Camera", style: .default) { [unowned self] _ in | |
self.presentPhotoPicker(sourceType: .camera) | |
} | |
let choosePhoto = UIAlertAction(title: "Photos Library", style: .default) { [unowned self] _ in | |
self.presentPhotoPicker(sourceType: .photoLibrary) |
This file contains 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 imageClassifier(image: UIImage, wordNumber: Int, characterNumber: Int, currentObservation : VNTextObservation){ | |
let request = VNCoreMLRequest(model: model) { [weak self] request, error in | |
guard let results = request.results as? [VNClassificationObservation], | |
let topResult = results.first else { | |
fatalError("Unexpected result type from VNCoreMLRequest") | |
} | |
let result = topResult.identifier | |
let classificationInfo: [String: Any] = ["wordNumber" : wordNumber, | |
"characterNumber" : characterNumber, | |
"class" : result] |
This file contains 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 SwiftUI | |
import AVKit | |
import CoreImage | |
import CoreImage.CIFilterBuiltins | |
struct ContentView: View { | |
@State private var currentFilter = 0 | |
var filters : [CIFilter?] = [nil, CIFilter.sepiaTone(), CIFilter.pixellate(), CIFilter.comicEffect()] |
This file contains 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
struct ContentView: View { | |
var body: some View { | |
VStack{ | |
Label("Hello Label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) | |
Label("Title only label", systemImage: "sun.min") | |
.font(.system(.title, design: .rounded)) |
This file contains 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
struct ProgressBar: View { | |
@Binding var progress: Double | |
var body: some View { | |
GeometryReader { geometry in | |
ZStack(alignment: .leading) { | |
Rectangle() | |
.foregroundColor(Color.gray) | |
.opacity(0.3) |
This file contains 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 address(o: UnsafeRawPointer) -> NSString { | |
let addr = Int(bitPattern: o) | |
return NSString(format: "%p", addr) | |
} | |
struct Point { | |
var p: Int | |
} | |
var pointA = [Point(p: 25), Point(p: 20)] |
This file contains 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
struct Anything<Wrapper : UIView>: UIViewRepresentable { | |
typealias Updater = (Wrapper, Context) -> Void | |
var makeView: () -> Wrapper | |
var update: (Wrapper, Context) -> Void | |
init(_ makeView: @escaping @autoclosure () -> Wrapper, | |
updater update: @escaping (Wrapper) -> Void) { | |
self.makeView = makeView | |
self.update = { view, _ in update(view) } |
This file contains 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 SwiftUI | |
import Introspect | |
struct ContentView : View { | |
@State var text = "" | |
var body: some View { | |
VStack { | |
TextField("Enter some text", text: $text) |