Skip to content

Instantly share code, notes, and snippets.

View WildStudio's full-sized avatar
Get shit done!

Christian Aranda WildStudio

Get shit done!
  • WildStudio
  • Barcelona
View GitHub Profile
@WildStudio
WildStudio / MainViewController
Created May 29, 2019 17:47
Set the card frame on tapping an item
@IBAction func onTapButton(_ sender: Any) {
presentAnimationController.selectedCardFrame = imageView.frame
self.performSegue(withIdentifier: "showDetail", sender: nil)
}
@WildStudio
WildStudio / MainViewController
Created May 29, 2019 17:47
Set the card frame on tapping an item
@IBAction func onTapButton(_ sender: Any) {
presentAnimationController.selectedCardFrame = imageView.frame
self.performSegue(withIdentifier: "showDetail", sender: nil)
}
@WildStudio
WildStudio / MainViewController
Created May 29, 2019 17:47
Set the card frame on tapping an item
@IBAction func onTapButton(_ sender: Any) {
presentAnimationController.selectedCardFrame = imageView.frame
self.performSegue(withIdentifier: "showDetail", sender: nil)
}
@WildStudio
WildStudio / TransitioningDelegate
Created May 29, 2019 17:28
Extend MainViewController so it conforms UIViewControllerTransitioningDelegate:
extension MainViewController: UIViewControllerTransitioningDelegate {
func animationController(forPresented presented: UIViewController,
presenting: UIViewController,
source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
return presentAnimationController
}
}
@WildStudio
WildStudio / TransitioningDelegate
Created May 29, 2019 17:24
Setting transition delegate on `prepare(for segue:)`
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationViewController = segue.destination
destinationViewController.transitioningDelegate = self
}
@WildStudio
WildStudio / Set up Pager Container View Controller
Created February 27, 2019 11:43
Create PagerContainerViewController and configure
let controller = Pager.PageContainerViewController.instantiate()
present(controller, animated: true)
let controllers = dataSource.map { _ in PageDetailViewController.instantiate() ?? PageDetailViewController() }
controller.configure(with: dataSource, controllers: controllers)
@WildStudio
WildStudio / Handle VNRequest Results
Created December 17, 2018 10:46
Handle Image Classification Results
func handleClassification(request: VNRequest, error: Error?) {
guard let observations = request.results as? [VNClassificationObservation]
else { fatalError("unexpected result type from VNCoreMLRequest") }
guard let best = observations.first
else { fatalError("can't get best result") }
DispatchQueue.main.async {
self.classificationLabel.text = "Classification: \"\(best.identifier)\" Confidence: \(best.confidence)"
}
}
@WildStudio
WildStudio / Vision image process
Created December 17, 2018 10:41
Processes one or more image analysis requests using Vision
let handler = VNImageRequestHandler(ciImage: ciImage, orientation:orientation)
DispatchQueue.global(qos: .userInteractive).async {
do {
try handler.perform([self.classificationRequest])
} catch {
print(error)
}
}
@WildStudio
WildStudio / Core ML prediction
Created December 17, 2018 08:59
Load the ML model through its generated class and create a Vision request for it.
lazy var classificationRequest: VNCoreMLRequest = {
do {
let model = try VNCoreMLModel(for: ImageClassifier().model)
return VNCoreMLRequest(model: model, completionHandler: self.handleClassification)
} catch {
fatalError("can't load Vision ML model: \(error)")
}
}()
@WildStudio
WildStudio / Create ML Playground.
Created December 17, 2018 08:39
Create an image classifier model using Playgrounds and Create ML
import CreateMLUI
 
let builder = MLImageClassifierBuilder()
builder.showInLiveView()