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 DataModel: Identifiable{ | |
var id = UUID() | |
var name: String | |
var icon: String | |
var children : [DataModel]? | |
} |
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
@main | |
struct WhatsNewiOS14SwiftUIApp: App { | |
var body: some Scene { | |
WindowGroup { | |
ContentView() | |
} | |
} | |
} |
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
MyModel.apply{ | |
switch result { | |
case .success(let model): | |
currentModel = model | |
case .failure(let error): | |
handleFailure(for: error) | |
} |
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
PHPhotoLibrary.requestAuthorization(for: .readWrite) { status in | |
switch status { | |
case .limited: | |
print("limited access granted") | |
default: | |
print("not implemented") | |
} | |
} |
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
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 |
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
RoundedRectangle(cornerRadius: cornerRadius) | |
.fill(LinearGradient(gradient: Gradient(colors: [.purple, .red, .blue]), startPoint: .top, endPoint: .bottom)) | |
.frame(width: 30, height: value) |
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
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 |
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 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() | |
} |
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
@objc func preview() { | |
let bounds = canvasView.drawing.bounds | |
if let image = clippedImageForRect(clipRect: bounds, inView: mapView!){ | |
showPreviewImage(image: image) | |
} | |
} |
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
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), |