Skip to content

Instantly share code, notes, and snippets.

struct DataModel: Identifiable{
var id = UUID()
var name: String
var icon: String
var children : [DataModel]?
}
@main
struct WhatsNewiOS14SwiftUIApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
MyModel.apply{
switch result {
case .success(let model):
currentModel = model
case .failure(let error):
handleFailure(for: error)
}
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in
switch status {
case .limited:
print("limited access granted")
default:
print("not implemented")
}
}
let requestHandler = VNImageRequestHandler(cgImage: originalImage, options: [:])
let saliencyRequest = VNGenerateAttentionBasedSaliencyImageRequest(completionHandler: nil)
try requestHandler.perform([self.saliencyRequest])
guard let results = self.saliencyRequest.results?.first else{return}
let observations = results as? VNSaliencyImageObservation
let salientObjects = observation.salientObjects
@iosdevie
iosdevie / roundedrectangle-swifui
Created May 26, 2021 10:26
Fill Custom Views With Gradients
RoundedRectangle(cornerRadius: cornerRadius)
.fill(LinearGradient(gradient: Gradient(colors: [.purple, .red, .blue]), startPoint: .top, endPoint: .bottom))
.frame(width: 30, height: value)
@iosdevie
iosdevie / ios-setup-audioengine.swift
Created May 26, 2021 10:15
The AVAudioEngine is responsible for receiving the audio signals from the microphone. It provides our input for speech recognition.
let audioEngine = AVAudioEngine()
let audioSession = AVAudioSession.sharedInstance()
try audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)
try audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let inputNode = audioEngine.inputNode
inputNode.removeTap(onBus: 0)
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
@iosdevie
iosdevie / centralManager-scan-connect.swift
Created May 26, 2021 08:13
Connecting To Scanned Devices Bluetooth iOS
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any],
rssi RSSI: NSNumber) {
self.peripheral = peripheral
self.peripheral?.delegate = self
centralManager?.connect(peripheral, options: nil)
centralManager?.stopScan()
}
@objc func preview() {
let bounds = canvasView.drawing.bounds
if let image = clippedImageForRect(clipRect: bounds, inView: mapView!){
showPreviewImage(image: image)
}
}
@iosdevie
iosdevie / pkcanvasview.swift
Created May 26, 2021 07:11
Setting the PKCanvasView
let canvasView = PKCanvasView(frame: .zero)
canvasView.translatesAutoresizingMaskIntoConstraints = false
canvasView.isOpaque = false
view.addSubview(canvasView)
canvasView.backgroundColor = .clear
NSLayoutConstraint.activate([
canvasView.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor, constant: 40),
canvasView.bottomAnchor.constraint(equalTo: view.bottomAnchor),