Skip to content

Commit

Permalink
Migrate to Swift 2
Browse files Browse the repository at this point in the history
  • Loading branch information
zenangst committed Sep 4, 2015
1 parent 468fa85 commit 5e63a92
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
29D699D11B70ABFC0021FA73 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0640;
ORGANIZATIONNAME = "Ramon Gilabert Llop";
TargetAttributes = {
Expand Down
4 changes: 2 additions & 2 deletions Source/BottomView/BottomContainerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class BottomContainerView: UIView {

for view in [borderPickerButton, pickerButton, doneButton, stackView, topSeparator] {
addSubview(view)
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.translatesAutoresizingMaskIntoConstraints = false
}

backgroundColor = configuration.backgroundColor
Expand All @@ -79,7 +79,7 @@ class BottomContainerView: UIView {
setupConstraints()
}

required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
4 changes: 2 additions & 2 deletions Source/BottomView/ButtonPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ButtonPicker: UIButton {

lazy var numberLabel: UILabel = { [unowned self] in
let label = UILabel()
label.setTranslatesAutoresizingMaskIntoConstraints(false)
label.translatesAutoresizingMaskIntoConstraints = false
label.font = self.configuration.numberLabelFont

return label
Expand Down Expand Up @@ -61,7 +61,7 @@ class ButtonPicker: UIButton {
object: nil)
}

required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion Source/BottomView/ImageStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ public class ImageStack {
}

public func containsImage(image: UIImage) -> Bool {
return contains(images, image)
return images.contains(image)
}
}
10 changes: 5 additions & 5 deletions Source/BottomView/StackView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ImageStackView: UIView {
layoutSubviews()
}

required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down Expand Up @@ -74,10 +74,10 @@ class ImageStackView: UIView {
let offset = -step * CGFloat(views.count)
var origin = CGPoint(x: offset, y: offset)

for (i, view) in enumerate(views) {
for (i, view) in views.enumerate() {
origin.x += step
origin.y += step
var frame = CGRect(origin: origin, size: viewSize)
let frame = CGRect(origin: origin, size: viewSize)
view.frame = frame
}
}
Expand Down Expand Up @@ -116,9 +116,9 @@ extension ImageStackView {
return
}

let photos = suffix(images, 4)
let photos = images.suffix(4)

for (index, view) in enumerate(views) {
for (index, view) in views.enumerate() {
if index <= photos.count - 1 {
view.image = photos[index]
view.alpha = 1
Expand Down
36 changes: 24 additions & 12 deletions Source/CameraView/CameraView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,17 @@ class CameraView: UIViewController {

delegate?.handleFlashButton(captureDevice?.position == .Front)

var error: NSError? = nil

UIView.animateWithDuration(0.3, animations: { [unowned self] in
self.containerView.alpha = 1
}, completion: { finished in
self.captureSession.beginConfiguration()
self.captureSession.removeInput(currentDeviceInput)
self.captureSession.addInput(AVCaptureDeviceInput(device: self.captureDevice, error: &error))

let captureDeviceInput: AVCaptureDeviceInput?
do { try captureDeviceInput = AVCaptureDeviceInput(device: self.captureDevice)
} catch { }

self.captureSession.addInput(AVCaptureDeviceInput(device: captureDeviceInput))
self.captureSession.commitConfiguration()
UIView.animateWithDuration(1.3, animations: { [unowned self] in
self.containerView.alpha = 0
Expand All @@ -129,7 +132,10 @@ class CameraView: UIViewController {
func flashCamera(title: String) {

if (captureDevice?.hasFlash != nil) {
captureDevice?.lockForConfiguration(nil)
do {
try captureDevice?.lockForConfiguration()
} catch _ {
}
switch title {
case "ON":
captureDevice?.flashMode = .On
Expand Down Expand Up @@ -173,7 +179,7 @@ class CameraView: UIViewController {

func focusTo(point: CGPoint) {
if let device = captureDevice {
if device.lockForConfiguration(nil)
if device.lockForConfiguration()
&& device.isFocusModeSupported(AVCaptureFocusMode.Locked) {
device.focusPointOfInterest = CGPointMake(point.x / UIScreen.mainScreen().bounds.width, point.y / UIScreen.mainScreen().bounds.height)
device.unlockForConfiguration()
Expand All @@ -189,8 +195,8 @@ class CameraView: UIViewController {
}
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
let anyTouch = touches.first as! UITouch
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let anyTouch = touches.first!
let touchX = anyTouch.locationInView(view).x
let touchY = anyTouch.locationInView(view).y
focusImageView.transform = CGAffineTransformIdentity
Expand All @@ -200,26 +206,32 @@ class CameraView: UIViewController {

func configureDevice() {
if let device = captureDevice {
device.lockForConfiguration(nil)
do {
try device.lockForConfiguration()
} catch _ {
}
device.unlockForConfiguration()
}
}

func beginSession() {
configureDevice()
var error: NSError? = nil
let error: NSError? = nil
if captureSession.inputs.count == 0 {
captureSession.addInput(AVCaptureDeviceInput(device: captureDevice, error: &error))
let captureDeviceInput: AVCaptureDeviceInput?
do { try captureDeviceInput = AVCaptureDeviceInput(device: self.captureDevice)
} catch { }
captureSession.addInput(captureDeviceInput)

if error != nil {
println("error: \(error?.localizedDescription)")
print("error: \(error?.localizedDescription)")
}

previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
previewLayer?.autoreverses = true
previewLayer?.videoGravity = AVLayerVideoGravityResizeAspectFill
view.clipsToBounds = true
view.layer.addSublayer(previewLayer)
view.layer.addSublayer(previewLayer!)
previewLayer?.frame = view.layer.frame
captureSession.startRunning()
delegate?.handleFlashButton(captureDevice?.position == .Front)
Expand Down
8 changes: 4 additions & 4 deletions Source/ImageGallery/ImageGalleryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ImageGalleryView: UIView {
lazy public var collectionView: UICollectionView = { [unowned self] in
let collectionView = UICollectionView(frame: CGRectMake(0, 0, 0, 0),
collectionViewLayout: self.collectionViewLayout)
collectionView.setTranslatesAutoresizingMaskIntoConstraints(false)
collectionView.translatesAutoresizingMaskIntoConstraints = false
collectionView.backgroundColor = self.configuration.mainColor
collectionView.showsHorizontalScrollIndicator = false
collectionView.layer.anchorPoint = CGPointMake(0.5, 0.5)
Expand All @@ -45,7 +45,7 @@ public class ImageGalleryView: UIView {

lazy var topSeparator: UIView = { [unowned self] in
let view = UIView()
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.translatesAutoresizingMaskIntoConstraints = false
view.addGestureRecognizer(self.panGestureRecognizer)
view.backgroundColor = UIColor.blackColor().colorWithAlphaComponent(0.6)

Expand All @@ -56,7 +56,7 @@ public class ImageGalleryView: UIView {
let view = UIView()
view.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.6)
view.layer.cornerRadius = Dimensions.indicatorHeight / 2
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.translatesAutoresizingMaskIntoConstraints = false

return view
}()
Expand Down Expand Up @@ -112,7 +112,7 @@ public class ImageGalleryView: UIView {
fetchPhotos(0)
}

required public init(coder aDecoder: NSCoder) {
required public init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down
2 changes: 1 addition & 1 deletion Source/ImageGallery/ImageGalleryViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ImageGalleryViewCell: UICollectionViewCell {
if imageView.superview != contentView {
for view in [imageView, selectedImageView] {
view.contentMode = .ScaleAspectFill
view.setTranslatesAutoresizingMaskIntoConstraints(false)
view.translatesAutoresizingMaskIntoConstraints = false
view.clipsToBounds = true
contentView.addSubview(view)
}
Expand Down
4 changes: 2 additions & 2 deletions Source/ImagePickerController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class ImagePickerController: UIViewController {

for subview in [cameraController.view, galleryView, bottomContainer, topView] {
view.addSubview(subview)
subview.setTranslatesAutoresizingMaskIntoConstraints(false)
subview.translatesAutoresizingMaskIntoConstraints = false
}

view.backgroundColor = .whiteColor()
Expand Down Expand Up @@ -293,7 +293,7 @@ extension ImagePickerController: ImageGalleryPanGestureDelegate {
galleryView.collectionSize = CGSize(width: galleryView.collectionView.frame.height, height: galleryView.collectionView.frame.height)

if galleryHeight < GestureConstants.maximumHeight {
var realTranslation = translation.y < -GestureConstants.minimumHeight + ImageGalleryView.Dimensions.galleryBarHeight
let realTranslation = translation.y < -GestureConstants.minimumHeight + ImageGalleryView.Dimensions.galleryBarHeight
? translation.y + GestureConstants.minimumHeight - ImageGalleryView.Dimensions.galleryBarHeight
: translation.y
galleryView.collectionView.contentOffset = CGPoint(x: initialContentOffset.x - (realTranslation * CGFloat(numberOfCells)), y: 0)
Expand Down
4 changes: 2 additions & 2 deletions Source/TopView/TopView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class TopView: UIView {
button.layer.shadowOpacity = 0.5
button.layer.shadowOffset = CGSize(width: 0, height: 1)
button.layer.shadowRadius = 1
button.setTranslatesAutoresizingMaskIntoConstraints(false)
button.translatesAutoresizingMaskIntoConstraints = false
addSubview(button)
}

setupConstraints()
}

required init(coder aDecoder: NSCoder) {
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

Expand Down

0 comments on commit 5e63a92

Please sign in to comment.