Swizzbeat Posted August 27, 2014 Posted August 27, 2014 (edited) Little class I made since I needed basic Camera control in an iOS app I'm making. It may be useful to others as Swift is relatively new. Remember to create a delegate and set it to deal with responses when the user interacts with the camera view. // Copyright (c) 2014 Anthony Puppo. All rights reserved. import Foundation import UIKit var cameraInstance:Camera! func getCameraInstance() -> Camera { if (cameraInstance == nil) { cameraInstance = Camera() } return cameraInstance } class Camera { let cameraUI:UIImagePickerController! private init() { //Singleton Design Pattern if (isAvailable()) { self.cameraUI = UIImagePickerController() } self.cameraUI = nil } func isAvailable() -> Bool { return UIImagePickerController.isSourceTypeAvailable(.Camera) } func open(currentViewController:UIViewController) -> Bool { if (isAvailable() && cameraUI != nil) { currentViewController.presentViewController(cameraUI, animated: true, completion: nil) return true } return false } func setDelegate(delegate:protocol<UINavigationControllerDelegate, UIImagePickerControllerDelegate>) { if (cameraUI != nil) { cameraUI.delegate = delegate } } func setSourceType(sourceType:UIImagePickerControllerSourceType) { if (cameraUI != nil) { cameraUI.sourceType = sourceType } } func setMediaTypes(mediaTypes:AnyObject...) { if (cameraUI != nil) { cameraUI.mediaTypes = mediaTypes } } func setAllowsEditing(allowsEditing:Bool) { if (cameraUI != nil) { cameraUI.allowsEditing = allowsEditing } } } Edited August 28, 2014 by Swizzbeat
Jack Posted August 28, 2014 Posted August 28, 2014 Swift is so ugly. I wish i could write iphone apps in java or c. 1
Swizzbeat Posted August 28, 2014 Author Posted August 28, 2014 Swift is so ugly. I wish i could write iphone apps in java or c. Both of those are even uglier lol
Dog_ Posted August 28, 2014 Posted August 28, 2014 Both of those are even uglier lol neh, c is but not jerba
Jack Posted August 28, 2014 Posted August 28, 2014 Both of those are even uglier lol c doesnt have classes so i guess c++ or c#
FrostBug Posted August 28, 2014 Posted August 28, 2014 c doesnt have classes so i guess c++ or c# Good luck getting Apple to allow programming iOS apps in .NET Framework 4
Jack Posted August 28, 2014 Posted August 28, 2014 Good luck getting Apple to allow programming iOS apps in .NET Framework "I wish"