Commit ef06acfd by Daniel Dahan

issue-44: updated for swift 2.0

parent 4f2d6628
......@@ -458,7 +458,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
......@@ -500,7 +500,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
......
......@@ -18,7 +18,7 @@
import UIKit
public class BasicCardView : MaterialCardView, Comparable, Equatable {
public class BasicCardView : MaterialCardView, Comparable {
//
// :name: layoutConstraints
//
......@@ -319,15 +319,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
*/
public var leftButtons: Array<MaterialButton>? {
didSet {
if let b = leftButtons {
if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
} else {
if nil == rightButtons && nil == leftButtons {
buttonsContainer?.removeFromSuperview()
} else if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
}
......@@ -338,15 +336,13 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
*/
public var rightButtons: Array<MaterialButton>? {
didSet {
if let b = rightButtons {
if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
} else {
if nil == rightButtons && nil == leftButtons {
buttonsContainer?.removeFromSuperview()
} else if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
}
......@@ -497,10 +493,16 @@ public class BasicCardView : MaterialCardView, Comparable, Equatable {
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
}
public func ==(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
return lhs.tag == rhs.tag
/**
:name: isEqual
*/
public override func isEqual(object: AnyObject?) -> Bool {
if let rhs = object as? BasicCardView {
return tag == rhs.tag
}
return false
}
}
public func <=(lhs: BasicCardView, rhs: BasicCardView) -> Bool {
......
......@@ -97,11 +97,9 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
public func prepareSession(preset: String = AVCaptureSessionPresetHigh) -> Bool {
session.sessionPreset = preset
var error: NSError?
// setup default camera device
let videoDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeVideo)
let videoInput: AVCaptureDeviceInput? = AVCaptureDeviceInput.deviceInputWithDevice(videoDevice) as? AVCaptureDeviceInput
let videoInput: AVCaptureDeviceInput? = try? AVCaptureDeviceInput(device: videoDevice)
if nil == videoInput {
return false
......@@ -113,7 +111,7 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
}
let audioDevice: AVCaptureDevice = AVCaptureDevice.defaultDeviceWithMediaType(AVMediaTypeAudio)
let audioInput: AVCaptureDeviceInput? = AVCaptureDeviceInput.deviceInputWithDevice(audioDevice) as? AVCaptureDeviceInput
let audioInput: AVCaptureDeviceInput? = try? AVCaptureDeviceInput(device: audioDevice)
if nil == audioInput {
return false
......@@ -218,9 +216,8 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
return false
}
let error: NSError?
let videoDevice: AVCaptureDevice? = inactiveCamera
let videoInput: AVCaptureDeviceInput? = AVCaptureDeviceInput.deviceInputWithDevice(videoDevice) as? AVCaptureDeviceInput
let videoInput: AVCaptureDeviceInput? = try? AVCaptureDeviceInput(device: videoDevice)
if nil == videoInput {
session.beginConfiguration()
......@@ -234,7 +231,7 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
session.commitConfiguration()
} else {
delegate?.captureDeviceConfigurationFailed?(self, error: error)
delegate?.captureDeviceConfigurationFailed?(self, error: nil)
return false
}
......@@ -391,14 +388,14 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
let device: AVCaptureDevice = object as! AVCaptureDevice
if device.adjustingExposure && device.isExposureModeSupported(.Locked) {
object.removeObserver(self, forKeyPath: "adjustingExposure", context: &CaptureAdjustingExposureContext)
object!.removeObserver(self, forKeyPath: "adjustingExposure", context: &CaptureAdjustingExposureContext)
dispatch_async(queue) {
var error: NSError?
do {
try device.lockForConfiguration()
device.unlockForConfiguration()
} catch var error1 as NSError {
error = error1
} catch let e as NSError {
error = e
self.delegate?.captureDeviceConfigurationFailed?(self, error: error)
} catch {
fatalError()
......@@ -560,15 +557,12 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
* @return An optional NSURL value.
*/
private var uniqueURL: NSURL? {
var error: NSError?
let fileManager: NSFileManager = NSFileManager.defaultManager()
let tempDirectoryTemplate: String = (NSTemporaryDirectory() as NSString).stringByAppendingPathComponent("FocusLibrary")
do {
try fileManager.createDirectoryAtPath(tempDirectoryTemplate, withIntermediateDirectories: true, attributes: nil)
return NSURL.fileURLWithPath(tempDirectoryTemplate + "/test.mov")
} catch let error1 as NSError {
error = error1
}
} catch {}
return nil
}
......@@ -630,17 +624,19 @@ public class Capture: NSObject, AVCaptureFileOutputRecordingDelegate {
*/
private func generateThumbnailForVideoAtURL(videoURL: NSURL!) {
dispatch_async(queue) {
let asset: AVAsset = AVAsset.assetWithURL(videoURL)
let imageGenerator: AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.maximumSize = CGSizeMake(100, 0)
imageGenerator.appliesPreferredTrackTransform = true
let imageRef: CGImageRef = try? imageGenerator.copyCGImageAtTime(kCMTimeZero, actualTime: nil)
let image: UIImage = UIImage(CGImage: imageRef)
dispatch_async(dispatch_get_main_queue()) {
self.postAssetLibraryNotification(image)
}
do {
let asset: AVAsset = AVAsset(URL: videoURL)
let imageGenerator: AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.maximumSize = CGSizeMake(100, 0)
imageGenerator.appliesPreferredTrackTransform = true
let imageRef: CGImageRef = try imageGenerator.copyCGImageAtTime(kCMTimeZero, actualTime: nil)
let image: UIImage = UIImage(CGImage: imageRef)
dispatch_async(dispatch_get_main_queue()) {
self.postAssetLibraryNotification(image)
}
} catch {}
}
}
......
......@@ -41,7 +41,7 @@ public class FabButton : MaterialButton {
//
// :name: pulseBegan
//
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent?) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(3, 3)
......
......@@ -42,7 +42,7 @@ public class FlatButton : MaterialButton {
//
// :name: pulseBegan
//
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent?) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(4, 4)
......
......@@ -429,15 +429,13 @@ public class ImageCardView : MaterialCardView, Comparable {
*/
public var leftButtons: Array<MaterialButton>? {
didSet {
if let b = leftButtons {
if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
} else {
if nil == rightButtons && nil == leftButtons {
buttonsContainer?.removeFromSuperview()
} else if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
}
......@@ -448,15 +446,13 @@ public class ImageCardView : MaterialCardView, Comparable {
*/
public var rightButtons: Array<MaterialButton>? {
didSet {
if let b = rightButtons {
if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
} else {
if nil == rightButtons && nil == leftButtons {
buttonsContainer?.removeFromSuperview()
} else if nil == buttonsContainer {
buttonsContainer = UIView()
buttonsContainer!.translatesAutoresizingMaskIntoConstraints = false
buttonsContainer!.backgroundColor = MaterialTheme.clear.color
addSubview(buttonsContainer!)
}
prepareCard()
}
......@@ -630,10 +626,16 @@ public class ImageCardView : MaterialCardView, Comparable {
NSLayoutConstraint.activateConstraints(layoutConstraints)
}
}
}
public func ==(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
return lhs.tag == rhs.tag
/**
:name: isEqual
*/
public override func isEqual(object: AnyObject?) -> Bool {
if let rhs = object as? ImageCardView {
return tag == rhs.tag
}
return false
}
}
public func <=(lhs: ImageCardView, rhs: ImageCardView) -> Bool {
......
......@@ -142,9 +142,6 @@ public struct Layout {
:name: constraint
*/
public static func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> {
for (_, v) in views {
v.setTranslatesAutoresizingMaskIntoConstraints(false)
}
return NSLayoutConstraint.constraintsWithVisualFormat(
format,
options: options,
......
......@@ -129,7 +129,7 @@ public class MaterialButton : UIButton {
//
// :name: pulseBegan
//
internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
internal func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent?) {
pulseView = UIView(frame: CGRectMake(0, 0, bounds.height, bounds.height))
pulseView!.layer.cornerRadius = bounds.height / 2
pulseView!.center = (touches.first as! UITouch).locationInView(self)
......@@ -140,7 +140,7 @@ public class MaterialButton : UIButton {
//
// :name: pulseEnded
//
internal func pulseEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
internal func pulseEnded(touches: Set<NSObject>?, withEvent event: UIEvent?) {
UIView.animateWithDuration(0.3,
animations: { _ in
self.pulseView?.alpha = 0
......
......@@ -21,7 +21,7 @@ import UIKit
@objc(MaterialTextDelegate)
public protocol TextDelegate {
optional func textStorageWillProcessEdit(text: MaterialText, textStorage: MaterialTextStorage, string: String, range: NSRange)
optional func textStorageDidProcessEdit(text: MaterialText, textStorage: MaterialTextStorage, string: String, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
optional func textStorageDidProcessEdit(text: MaterialText, textStorage: MaterialTextStorage, string: String, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>)
}
@objc(MaterialText)
......@@ -60,7 +60,7 @@ public class MaterialText: NSObject {
textStorage.textStorageWillProcessEdit = { (textStorage: MaterialTextStorage, string: String, range: NSRange) -> Void in
self.delegate?.textStorageWillProcessEdit?(self, textStorage: textStorage, string: string, range: range)
}
textStorage.textStorageDidProcessEdit = { (textStorage: MaterialTextStorage, result: NSTextCheckingResult, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
textStorage.textStorageDidProcessEdit = { (textStorage: MaterialTextStorage, result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.delegate?.textStorageDidProcessEdit?(self, textStorage: textStorage, string: textStorage.string, result: result, flags: flags, stop: stop)
}
}
......
......@@ -19,7 +19,7 @@
import UIKit
internal typealias MaterialTextStorageWillProcessEdit = (MaterialTextStorage, String, NSRange) -> Void
internal typealias MaterialTextStorageDidProcessEdit = (MaterialTextStorage, NSTextCheckingResult, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
internal typealias MaterialTextStorageDidProcessEdit = (MaterialTextStorage, NSTextCheckingResult?, NSMatchingFlags, UnsafeMutablePointer<ObjCBool>) -> Void
public class MaterialTextStorage: NSTextStorage {
/**
......@@ -48,11 +48,17 @@ public class MaterialTextStorage: NSTextStorage {
*/
internal var textStorageDidProcessEdit: MaterialTextStorageDidProcessEdit?
required public init?(coder aDecoder: NSCoder) {
/**
:name: init
*/
public required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override public init() {
/**
:name: init
*/
public override init() {
super.init()
}
......@@ -66,25 +72,37 @@ public class MaterialTextStorage: NSTextStorage {
}
}
override public func processEditing() {
/**
:name: processEditing
*/
public override func processEditing() {
let range: NSRange = (string as NSString).paragraphRangeForRange(editedRange)
textStorageWillProcessEdit?(self, string, range)
searchExpression!.enumerateMatchesInString(string, options: [], range: range) { (result: NSTextCheckingResult!, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) in
self.textStorageDidProcessEdit?(self, result, flags, stop)
searchExpression!.enumerateMatchesInString(string, options: [], range: range) { (result: NSTextCheckingResult?, flags: NSMatchingFlags, stop: UnsafeMutablePointer<ObjCBool>) -> Void in
self.textStorageDidProcessEdit?(self, result, flags, stop)
}
super.processEditing()
}
override public func attributesAtIndex(location: Int, effectiveRange range: NSRangePointer) -> [String : AnyObject] {
/**
:name: attributesAtIndex
*/
public override func attributesAtIndex(location: Int, effectiveRange range: NSRangePointer) -> [String : AnyObject] {
return store.attributesAtIndex(location, effectiveRange: range)
}
override public func replaceCharactersInRange(range: NSRange, withString str: String) {
/**
:name: replaceCharactersInRange
*/
public override func replaceCharactersInRange(range: NSRange, withString str: String) {
store.replaceCharactersInRange(range, withString: str)
edited(NSTextStorageEditActions.EditedCharacters, range: range, changeInLength: str.utf16.count - range.length)
}
override public func setAttributes(attrs: [String : AnyObject]?, range: NSRange) {
/**
:name: setAttributes
*/
public override func setAttributes(attrs: [String : AnyObject]?, range: NSRange) {
store.setAttributes(attrs, range: range)
edited(NSTextStorageEditActions.EditedAttributes, range: range, changeInLength: 0)
}
......
......@@ -42,7 +42,7 @@ public class RaisedButton : MaterialButton {
//
// :name: pulseBegan
//
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
internal override func pulseBegan(touches: Set<NSObject>, withEvent event: UIEvent?) {
super.pulseBegan(touches, withEvent: event)
UIView.animateWithDuration(0.3, animations: {
self.pulseView!.transform = CGAffineTransformMakeScale(4, 4)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment