Commit 6c813dcf by Daniel Dahan

development: Updated to Xcode Beta 6

parent d2aa614b
...@@ -56,13 +56,13 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> AnimationFillMo ...@@ -56,13 +56,13 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> AnimationFillMo
} }
} }
public typealias AnimationDelayCancelBlock = (cancel : Bool) -> Void public typealias AnimationDelayCancelBlock = (Bool) -> Void
public struct Animation { public struct Animation {
/// Delay helper method. /// Delay helper method.
public static func delay(time: TimeInterval, completion: ()-> Void) -> AnimationDelayCancelBlock? { public static func delay(time: TimeInterval, completion: @escaping ()-> Void) -> AnimationDelayCancelBlock? {
func dispatch_later(completion: ()-> Void) { func dispatch_later(completion: @escaping ()-> Void) {
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion) DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + time, execute: completion)
} }
...@@ -78,7 +78,7 @@ public struct Animation { ...@@ -78,7 +78,7 @@ public struct Animation {
cancelable = delayed cancelable = delayed
dispatch_later { dispatch_later {
cancelable?(cancel: false) cancelable?(false)
} }
return cancelable; return cancelable;
...@@ -88,7 +88,7 @@ public struct Animation { ...@@ -88,7 +88,7 @@ public struct Animation {
:name: delayCancel :name: delayCancel
*/ */
public static func delayCancel(completion: AnimationDelayCancelBlock?) { public static func delayCancel(completion: AnimationDelayCancelBlock?) {
completion?(cancel: true) completion?(true)
} }
......
...@@ -32,8 +32,8 @@ import UIKit ...@@ -32,8 +32,8 @@ import UIKit
public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning { public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning {
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) { public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let fromView : UIView = transitionContext.view(forKey: UITransitionContextFromViewKey)! let fromView : UIView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)! let toView : UIView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
toView.alpha = 0 toView.alpha = 0
transitionContext.containerView.addSubview(fromView) transitionContext.containerView.addSubview(fromView)
......
...@@ -150,10 +150,10 @@ public protocol CaptureSessionDelegate { ...@@ -150,10 +150,10 @@ public protocol CaptureSessionDelegate {
- Parameter captureSession: A reference to the calling CaptureSession. - Parameter captureSession: A reference to the calling CaptureSession.
- Parameter captureOut: An AVCaptureFileOutput. - Parameter captureOut: An AVCaptureFileOutput.
- Parameter fileURL: A file URL. - Parameter fileURL: A file URL.
- Parameter fromConnections: An array of AnyObjects. - Parameter fromConnections: An array of Anys.
*/ */
@objc @objc
optional func captureSessionDidStartRecordingToOutputFileAtURL(captureSession: CaptureSession, captureOutput: AVCaptureFileOutput, fileURL: NSURL, fromConnections connections: [AnyObject]) optional func captureSessionDidStartRecordingToOutputFileAtURL(captureSession: CaptureSession, captureOutput: AVCaptureFileOutput, fileURL: NSURL, fromConnections connections: [Any])
/** /**
A delegation method that is fired when a session finished recording and writing A delegation method that is fired when a session finished recording and writing
...@@ -161,11 +161,11 @@ public protocol CaptureSessionDelegate { ...@@ -161,11 +161,11 @@ public protocol CaptureSessionDelegate {
- Parameter captureSession: A reference to the calling CaptureSession. - Parameter captureSession: A reference to the calling CaptureSession.
- Parameter captureOut: An AVCaptureFileOutput. - Parameter captureOut: An AVCaptureFileOutput.
- Parameter fileURL: A file URL. - Parameter fileURL: A file URL.
- Parameter fromConnections: An array of AnyObjects. - Parameter fromConnections: An array of Anys.
- Parameter error: A Error corresponding to an error. - Parameter error: A Error corresponding to an error.
*/ */
@objc @objc
optional func captureSessionDidFinishRecordingToOutputFileAtURL(captureSession: CaptureSession, captureOutput: AVCaptureFileOutput, outputFileURL: NSURL, fromConnections connections: [AnyObject], error: Error!) optional func captureSessionDidFinishRecordingToOutputFileAtURL(captureSession: CaptureSession, captureOutput: AVCaptureFileOutput, outputFileURL: NSURL, fromConnections connections: [Any], error: Error!)
} }
@objc(CaptureSession) @objc(CaptureSession)
...@@ -186,7 +186,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -186,7 +186,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
private var movieOutput: AVCaptureMovieFileOutput! private var movieOutput: AVCaptureMovieFileOutput!
/// A reference to the movie output URL. /// A reference to the movie output URL.
private var movieOutputURL: NSURL? private var movieOutputURL: URL?
/// A reference to the AVCaptureSession. /// A reference to the AVCaptureSession.
internal var session: AVCaptureSession! internal var session: AVCaptureSession!
...@@ -272,7 +272,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -272,7 +272,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e error = e
} }
} else { } else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focusMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focusMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focusMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focusMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0001, userInfo: userInfo) error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0001, userInfo: userInfo)
...@@ -301,11 +301,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -301,11 +301,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e error = e
} }
} else { } else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported flashMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported flashMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported flashMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported flashMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0002, userInfo: userInfo) error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0002, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
if let e = error { if let e = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e) delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
...@@ -330,11 +330,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -330,11 +330,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e error = e
} }
} else { } else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported torchMode.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported torchMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported torchMode.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported torchMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0003, userInfo: userInfo) error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0003, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
if let e: NSError = error { if let e: NSError = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e) delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
...@@ -476,11 +476,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -476,11 +476,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e error = e
} }
} else { } else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0004, userInfo: userInfo) error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0004, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
if let e = error { if let e = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e) delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
...@@ -507,22 +507,22 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -507,22 +507,22 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e error = e
} }
} else { } else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0005, userInfo: userInfo) error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0005, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
if let e = error { if let e = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e) delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
} }
} }
public override func observeValue(forKeyPath keyPath: String?, of object: AnyObject?, change: [NSKeyValueChangeKey: AnyObject]?, context: UnsafeMutablePointer<Void>?) { public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey: Any]?, context: UnsafeMutableRawPointer?) {
if context == &CaptureSessionAdjustingExposureContext { if context == &CaptureSessionAdjustingExposureContext {
let device: AVCaptureDevice = object as! AVCaptureDevice let device: AVCaptureDevice = object as! AVCaptureDevice
if !device.isAdjustingExposure && device.isExposureModeSupported(.locked) { if !device.isAdjustingExposure && device.isExposureModeSupported(.locked) {
object!.removeObserver(self, forKeyPath: "adjustingExposure", context: &CaptureSessionAdjustingExposureContext) (object! as AnyObject).removeObserver(self, forKeyPath: "adjustingExposure", context: &CaptureSessionAdjustingExposureContext)
DispatchQueue.main.async() { DispatchQueue.main.async() {
do { do {
try device.lockForConfiguration() try device.lockForConfiguration()
...@@ -571,26 +571,26 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -571,26 +571,26 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
if let v: AVCaptureConnection = s.imageOutput.connection(withMediaType: AVMediaTypeVideo) { if let v: AVCaptureConnection = s.imageOutput.connection(withMediaType: AVMediaTypeVideo) {
v.videoOrientation = s.videoOrientation v.videoOrientation = s.videoOrientation
s.imageOutput.captureStillImageAsynchronously(from: v) { [weak self] (sampleBuffer: CMSampleBuffer?, error: Error?) -> Void in s.imageOutput.captureStillImageAsynchronously(from: v) { [weak self] (sampleBuffer: CMSampleBuffer?, error: Error?) -> Void in
if let s: CaptureSession = self { if let s = self {
var captureError: Error? = error var captureError = error
if nil == captureError { if nil == captureError {
let data: NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer) let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)!
if let image1: UIImage = UIImage(data: data as Data) { if let image1 = UIImage(data: data) {
if let image2: UIImage = image1.adjustOrientation() { if let image2 = image1.adjustOrientation() {
s.delegate?.captureSessionStillImageAsynchronously?(captureSession: s, image: image2) s.delegate?.captureSessionStillImageAsynchronously?(captureSession: s, image: image2)
} else { } else {
var userInfo = [String: AnyObject]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot fix image orientation.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot fix image orientation.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot fix image orientation.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot fix image orientation.]"
captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0006, userInfo: userInfo) captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0006, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
} else { } else {
var userInfo = [String: AnyObject]() var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot capture image from data.]" userInfo[NSLocalizedDescriptionKey] = "[Material Error: Cannot capture image from data.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot capture image from data.]" userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Cannot capture image from data.]"
captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0007, userInfo: userInfo) captureError = NSError(domain: "io.cosmicmind.Material.Capture", code: 0007, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject userInfo[NSUnderlyingErrorKey] = error
} }
} }
...@@ -625,7 +625,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -625,7 +625,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
} }
s.movieOutputURL = s.uniqueURL() s.movieOutputURL = s.uniqueURL()
if let v: NSURL = s.movieOutputURL { if let v = s.movieOutputURL {
s.movieOutput.startRecording(toOutputFileURL: v as URL!, recordingDelegate: s) s.movieOutput.startRecording(toOutputFileURL: v as URL!, recordingDelegate: s)
} }
} }
...@@ -641,14 +641,14 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -641,14 +641,14 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
} }
} }
public func capture(_ captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAt fileURL: URL!, fromConnections connections: [AnyObject]!) { public func capture(_ captureOutput: AVCaptureFileOutput!, didStartRecordingToOutputFileAt fileURL: URL!, fromConnections connections: [Any]!) {
isRecording = true isRecording = true
delegate?.captureSessionDidStartRecordingToOutputFileAtURL?(captureSession: self, captureOutput: captureOutput, fileURL: fileURL, fromConnections: connections) delegate?.captureSessionDidStartRecordingToOutputFileAtURL?(captureSession: self, captureOutput: captureOutput, fileURL: fileURL as NSURL, fromConnections: connections)
} }
public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [AnyObject]!, error: Error!) { public func capture(_ captureOutput: AVCaptureFileOutput!, didFinishRecordingToOutputFileAt outputFileURL: URL!, fromConnections connections: [Any]!, error: Error!) {
isRecording = false isRecording = false
delegate?.captureSessionDidFinishRecordingToOutputFileAtURL?(captureSession: self, captureOutput: captureOutput, outputFileURL: outputFileURL, fromConnections: connections, error: error) delegate?.captureSessionDidFinishRecordingToOutputFileAtURL?(captureSession: self, captureOutput: captureOutput, outputFileURL: outputFileURL as NSURL, fromConnections: connections, error: error)
} }
/// Prepares the sessionQueue. /// Prepares the sessionQueue.
...@@ -721,9 +721,9 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate { ...@@ -721,9 +721,9 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
Creates a unique URL if possible. Creates a unique URL if possible.
- Returns: A NSURL if it is possible to create one. - Returns: A NSURL if it is possible to create one.
*/ */
private func uniqueURL() -> NSURL? { private func uniqueURL() -> URL? {
do { do {
let directory: NSURL = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) let directory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let dateFormatter = DateFormatter() let dateFormatter = DateFormatter()
dateFormatter.dateStyle = .full dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .full dateFormatter.timeStyle = .full
......
...@@ -165,7 +165,7 @@ public class Card: PulseView { ...@@ -165,7 +165,7 @@ public class Card: PulseView {
/** /**
:name: leftButtons :name: leftButtons
*/ */
public var leftButtons: Array<UIButton>? { public var leftButtons = [UIButton]() {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -192,7 +192,7 @@ public class Card: PulseView { ...@@ -192,7 +192,7 @@ public class Card: PulseView {
/** /**
:name: rightButtons :name: rightButtons
*/ */
public var rightButtons: Array<UIButton>? { public var rightButtons = [UIButton]() {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -222,7 +222,7 @@ public class Card: PulseView { ...@@ -222,7 +222,7 @@ public class Card: PulseView {
/** /**
:name: init :name: init
*/ */
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) { public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: [UIButton]? = nil, rightButtons: [UIButton]? = nil) {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
} }
...@@ -235,10 +235,10 @@ public class Card: PulseView { ...@@ -235,10 +235,10 @@ public class Card: PulseView {
if self.layer == layer { if self.layer == layer {
if divider { if divider {
var y: CGFloat = contentInset.bottom + dividerInset.bottom var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count { if 0 < leftButtons.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons[0].frame.height
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons[0].frame.height
} }
if 0 < y { if 0 < y {
prepareDivider(y: bounds.height - y - 0.5, width: bounds.width) prepareDivider(y: bounds.height - y - 0.5, width: bounds.width)
...@@ -261,8 +261,8 @@ public class Card: PulseView { ...@@ -261,8 +261,8 @@ public class Card: PulseView {
} }
var verticalFormat: String = "V:|" var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var views: Dictionary<String, Any> = Dictionary<String, Any>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var metrics: Dictionary<String, Any> = Dictionary<String, Any>()
if nil != titleLabel { if nil != titleLabel {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
...@@ -296,70 +296,66 @@ public class Card: PulseView { ...@@ -296,70 +296,66 @@ public class Card: PulseView {
} }
// leftButtons // leftButtons
if let v: Array<UIButton> = leftButtons { if 0 < leftButtons.count {
if 0 < v.count { var h = "H:|"
var h: String = "H:|" var d = Dictionary<String, Any>()
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var i = 0
var i: Int = 0 for b in leftButtons {
for b in v { let k: String = "b\(i)"
let k: String = "b\(i)"
d[k] = b
d[k] = b
if 0 == i {
if 0 == i { h += "-(left)-"
h += "-(left)-" } else {
} else { h += "-(left_right)-"
h += "-(left_right)-" }
}
h += "[\(k)]"
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
i += 1 }
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d)) }
}
}
// rightButtons // rightButtons
if let v: Array<UIButton> = rightButtons { if 0 < rightButtons.count {
if 0 < v.count { var h = "H:"
var h: String = "H:" var d = Dictionary<String, Any>()
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var i = rightButtons.count - 1
var i: Int = v.count - 1
for b in rightButtons {
for b in v { let k: String = "b\(i)"
let k: String = "b\(i)"
d[k] = b
d[k] = b
h += "[\(k)]"
h += "[\(k)]"
if 0 == i {
if 0 == i { h += "-(right)-"
h += "-(right)-" } else {
} else { h += "-(right_left)-"
h += "-(right_left)-" }
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
i -= 1 }
}
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d)) }
}
}
if 0 < leftButtons?.count { if 0 < leftButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0] views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0] views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} }
...@@ -412,11 +408,11 @@ public class Card: PulseView { ...@@ -412,11 +408,11 @@ public class Card: PulseView {
/** /**
:name: prepareProperties :name: prepareProperties
*/ */
internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) { internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: [UIButton]?, rightButtons: [UIButton]?) {
self.image = image self.image = image
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.contentView = contentView self.contentView = contentView
self.leftButtons = leftButtons self.leftButtons = leftButtons ?? []
self.rightButtons = rightButtons self.rightButtons = rightButtons ?? []
} }
} }
...@@ -137,7 +137,7 @@ public class CollectionViewLayout: UICollectionViewLayout { ...@@ -137,7 +137,7 @@ public class CollectionViewLayout: UICollectionViewLayout {
for i in 0..<dataSourceItems.count { for i in 0..<dataSourceItems.count {
let item: DataSourceItem = dataSourceItems[i] let item: DataSourceItem = dataSourceItems[i]
let indexPath = IndexPath(item: i, section: 0) let indexPath = IndexPath(item: i, section: 0)
layoutItems.append((layoutAttributesForItem(at: indexPath)!, indexPath)) layoutItems.append((layoutAttributesForItem(at: indexPath)!, indexPath as NSIndexPath))
offset.x += interimSpace offset.x += interimSpace
offset.x += nil == item.width ? itemSize.width : item.width! offset.x += nil == item.width ? itemSize.width : item.width!
......
...@@ -164,58 +164,57 @@ public class ControlView: View { ...@@ -164,58 +164,57 @@ public class ControlView: View {
if willRenderView { if willRenderView {
layoutIfNeeded() layoutIfNeeded()
if let g: Int = Int(width / gridFactor) { let g = Int(width / gridFactor)
let columns: Int = g + 1 let columns = g + 1
grid.views = [] grid.views = []
grid.axis.columns = columns grid.axis.columns = columns
contentView.grid.columns = columns contentView.grid.columns = columns
// leftControls // leftControls
if let v = leftControls { if let v = leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize.width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor) let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c) addSubview(c)
grid.views.append(c) grid.views.append(c)
} }
} }
addSubview(contentView) addSubview(contentView)
grid.views.append(contentView) grid.views.append(contentView)
// rightControls // rightControls
if let v = rightControls { if let v = rightControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize.width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor) let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
addSubview(c) addSubview(c)
grid.views.append(c) grid.views.append(c)
} }
} }
grid.contentEdgeInsets = contentInset grid.contentEdgeInsets = contentInset
grid.interimSpace = interimSpace grid.interimSpace = interimSpace
grid.reload() grid.reload()
contentView.grid.reload() contentView.grid.reload()
} }
} }
}
/** /**
Prepares the view instance when intialized. When subclassing, Prepares the view instance when intialized. When subclassing,
......
...@@ -32,7 +32,7 @@ import UIKit ...@@ -32,7 +32,7 @@ import UIKit
public struct DataSourceItem { public struct DataSourceItem {
/// Stores an the data for the item. /// Stores an the data for the item.
public var data: AnyObject? public var data: Any?
/// Width for horizontal scroll direction. /// Width for horizontal scroll direction.
public var width: CGFloat? public var width: CGFloat?
...@@ -42,12 +42,12 @@ public struct DataSourceItem { ...@@ -42,12 +42,12 @@ public struct DataSourceItem {
/** /**
Initializer. Initializer.
- Parameter data: A reference to an AnyObject that is associated - Parameter data: A reference to an Any that is associated
with a width or height. with a width or height.
- Parameter width: The width for the horizontal scroll direction. - Parameter width: The width for the horizontal scroll direction.
- Parameter height: The height for the vertical scroll direction. - Parameter height: The height for the vertical scroll direction.
*/ */
public init(data: AnyObject? = nil, width: CGFloat? = nil, height: CGFloat? = nil) { public init(data: Any? = nil, width: CGFloat? = nil, height: CGFloat? = nil) {
self.data = data self.data = data
self.width = width self.width = width
self.height = height self.height = height
......
...@@ -96,8 +96,8 @@ private class FontLoader { ...@@ -96,8 +96,8 @@ private class FontLoader {
var error: Unmanaged<CFError>? var error: Unmanaged<CFError>?
if !CTFontManagerRegisterGraphicsFont(font, &error) { if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription = CFErrorCopyDescription(error!.takeUnretainedValue()) let errorDescription = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! Error let nsError = error!.takeUnretainedValue() as Any as! Error
NSException(name: .internalInconsistencyException, reason: errorDescription as? String, userInfo: [NSUnderlyingErrorKey: nsError as AnyObject]).raise() NSException(name: .internalInconsistencyException, reason: errorDescription as? String, userInfo: [NSUnderlyingErrorKey: nsError as Any]).raise()
} }
} }
} }
......
...@@ -258,7 +258,7 @@ public class ImageCard: PulseView { ...@@ -258,7 +258,7 @@ public class ImageCard: PulseView {
/** /**
:name: leftButtons :name: leftButtons
*/ */
public var leftButtons: Array<UIButton>? { public var leftButtons = [UIButton]() {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -285,7 +285,7 @@ public class ImageCard: PulseView { ...@@ -285,7 +285,7 @@ public class ImageCard: PulseView {
/** /**
:name: rightButtons :name: rightButtons
*/ */
public var rightButtons: Array<UIButton>? { public var rightButtons = [UIButton]() {
didSet { didSet {
reloadView() reloadView()
} }
...@@ -315,7 +315,7 @@ public class ImageCard: PulseView { ...@@ -315,7 +315,7 @@ public class ImageCard: PulseView {
/** /**
:name: init :name: init
*/ */
public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: Array<UIButton>? = nil, rightButtons: Array<UIButton>? = nil) { public convenience init?(image: UIImage? = nil, titleLabel: UILabel? = nil, contentView: UIView? = nil, leftButtons: [UIButton]? = nil, rightButtons: [UIButton]? = nil) {
self.init(frame: CGRect.zero) self.init(frame: CGRect.zero)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons) prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
} }
...@@ -332,10 +332,10 @@ public class ImageCard: PulseView { ...@@ -332,10 +332,10 @@ public class ImageCard: PulseView {
// divider // divider
if divider { if divider {
var y: CGFloat = contentInset.bottom + dividerInset.bottom var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count { if 0 < leftButtons.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons[0].frame.height
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons[0].frame.height
} }
if 0 < y { if 0 < y {
prepareDivider(y: bounds.height - y - 0.5, width: bounds.width) prepareDivider(y: bounds.height - y - 0.5, width: bounds.width)
...@@ -358,8 +358,8 @@ public class ImageCard: PulseView { ...@@ -358,8 +358,8 @@ public class ImageCard: PulseView {
} }
var verticalFormat: String = "V:|" var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var views: Dictionary<String, Any> = Dictionary<String, Any>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var metrics: Dictionary<String, Any> = Dictionary<String, Any>()
if nil != imageLayer?.contents { if nil != imageLayer?.contents {
verticalFormat += "-(insetTop)" verticalFormat += "-(insetTop)"
...@@ -399,71 +399,67 @@ public class ImageCard: PulseView { ...@@ -399,71 +399,67 @@ public class ImageCard: PulseView {
} }
// leftButtons // leftButtons
if let v: Array<UIButton> = leftButtons { if 0 < leftButtons.count {
if 0 < v.count { var h: String = "H:|"
var h: String = "H:|" var d: Dictionary<String, Any> = Dictionary<String, Any>()
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var i: Int = 0
var i: Int = 0 for b in leftButtons {
for b in v { let k: String = "b\(i)"
let k: String = "b\(i)"
d[k] = b
d[k] = b
if 0 == i {
if 0 == i { h += "-(left)-"
h += "-(left)-" } else {
} else { h += "-(left_right)-"
h += "-(left_right)-" }
}
h += "[\(k)]"
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
i += 1 }
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d)) }
}
}
// rightButtons // rightButtons
if let v: Array<UIButton> = rightButtons { if 0 < rightButtons.count {
if 0 < v.count { var h: String = "H:"
var h: String = "H:" var d: Dictionary<String, Any> = Dictionary<String, Any>()
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>() var i: Int = rightButtons.count - 1
var i: Int = v.count - 1
for b in rightButtons {
for b in v { let k: String = "b\(i)"
let k: String = "b\(i)"
d[k] = b
d[k] = b
h += "[\(k)]"
h += "[\(k)]"
if 0 == i {
if 0 == i { h += "-(right)-"
h += "-(right)-" } else {
} else { h += "-(right_left)-"
h += "-(right_left)-" }
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
i -= 1 }
}
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d)) }
}
}
if nil == imageLayer?.contents { if nil == imageLayer?.contents {
if 0 < leftButtons?.count { if 0 < leftButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0] views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0] views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} }
...@@ -484,14 +480,14 @@ public class ImageCard: PulseView { ...@@ -484,14 +480,14 @@ public class ImageCard: PulseView {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else if nil != contentView { } else if nil != contentView {
if 0 < leftButtons?.count { if 0 < leftButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0] views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]" verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0] views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} }
...@@ -502,14 +498,14 @@ public class ImageCard: PulseView { ...@@ -502,14 +498,14 @@ public class ImageCard: PulseView {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
} }
} else { } else {
if 0 < leftButtons?.count { if 0 < leftButtons.count {
verticalFormat += "-[button]" verticalFormat += "-[button]"
views["button"] = leftButtons![0] views["button"] = leftButtons[0]
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + leftButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + leftButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count { } else if 0 < rightButtons.count {
verticalFormat += "-[button]" verticalFormat += "-[button]"
views["button"] = rightButtons![0] views["button"] = rightButtons[0]
metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + rightButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0) metrics["insetTop"] = (metrics["insetTop"] as! CGFloat) + contentInset.top + rightButtonsInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} else { } else {
...@@ -565,11 +561,11 @@ public class ImageCard: PulseView { ...@@ -565,11 +561,11 @@ public class ImageCard: PulseView {
/** /**
:name: prepareProperties :name: prepareProperties
*/ */
internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: Array<UIButton>?, rightButtons: Array<UIButton>?) { internal func prepareProperties(image: UIImage?, titleLabel: UILabel?, contentView: UIView?, leftButtons: [UIButton]?, rightButtons: [UIButton]?) {
self.image = image self.image = image
self.titleLabel = titleLabel self.titleLabel = titleLabel
self.contentView = contentView self.contentView = contentView
self.leftButtons = leftButtons self.leftButtons = leftButtons ?? []
self.rightButtons = rightButtons self.rightButtons = rightButtons ?? []
} }
} }
...@@ -41,20 +41,20 @@ public class JSON: Equatable, CustomStringConvertible { ...@@ -41,20 +41,20 @@ public class JSON: Equatable, CustomStringConvertible {
/** /**
:name: object :name: object
*/ */
public private(set) var object: AnyObject public private(set) var object: Any
/** /**
:name: asArray :name: asArray
*/ */
public var asArray: [AnyObject]? { public var asArray: [Any]? {
return object as? [AnyObject] return object as? [Any]
} }
/** /**
:name: asDictionary :name: asDictionary
*/ */
public var asDictionary: [String: AnyObject]? { public var asDictionary: [String: Any]? {
return object as? [String: AnyObject] return object as? [String: Any]
} }
/** /**
...@@ -95,7 +95,7 @@ public class JSON: Equatable, CustomStringConvertible { ...@@ -95,7 +95,7 @@ public class JSON: Equatable, CustomStringConvertible {
/** /**
:name: asNSData :name: asNSData
*/ */
public var asNSData: NSData? { public var asNSData: Data? {
return JSON.serialize(object: object) return JSON.serialize(object: object)
} }
...@@ -122,14 +122,14 @@ public class JSON: Equatable, CustomStringConvertible { ...@@ -122,14 +122,14 @@ public class JSON: Equatable, CustomStringConvertible {
/** /**
:name: serialize :name: serialize
*/ */
public class func serialize(object: AnyObject) -> Data? { public class func serialize(object: Any) -> Data? {
return try? JSONSerialization.data(withJSONObject: object, options: []) return try? JSONSerialization.data(withJSONObject: object, options: [])
} }
/** /**
:name: stringify :name: stringify
*/ */
public class func stringify(_ object: AnyObject) -> String? { public class func stringify(_ object: Any) -> String? {
if let o = object as? JSON { if let o = object as? JSON {
return stringify(o.object) return stringify(o.object)
} else if let data = JSON.serialize(object: object) { } else if let data = JSON.serialize(object: object) {
...@@ -143,7 +143,7 @@ public class JSON: Equatable, CustomStringConvertible { ...@@ -143,7 +143,7 @@ public class JSON: Equatable, CustomStringConvertible {
/** /**
:name: init :name: init
*/ */
public required init(_ object: AnyObject) { public required init(_ object: Any) {
if let o = object as? JSON { if let o = object as? JSON {
self.object = o.object self.object = o.object
} else { } else {
......
...@@ -196,9 +196,7 @@ public class Layer: CAShapeLayer { ...@@ -196,9 +196,7 @@ public class Layer: CAShapeLayer {
*/ */
public var cornerRadiusPreset: CornerRadiusPreset = .none { public var cornerRadiusPreset: CornerRadiusPreset = .none {
didSet { didSet {
if let v: CornerRadiusPreset = cornerRadiusPreset { cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset)
cornerRadius = CornerRadiusPresetToValue(preset: v)
}
} }
} }
...@@ -254,9 +252,9 @@ public class Layer: CAShapeLayer { ...@@ -254,9 +252,9 @@ public class Layer: CAShapeLayer {
/** /**
An initializer the same as init(). The layer parameter is ignored An initializer the same as init(). The layer parameter is ignored
to avoid crashes on certain architectures. to avoid crashes on certain architectures.
- Parameter layer: AnyObject. - Parameter layer: Any.
*/ */
public override init(layer: AnyObject) { public override init(layer: Any) {
contentsGravityPreset = .ResizeAspectFill contentsGravityPreset = .ResizeAspectFill
super.init() super.init()
prepareVisualLayer() prepareVisualLayer()
......
...@@ -850,11 +850,11 @@ extension Layout { ...@@ -850,11 +850,11 @@ extension Layout {
Creats an Array with a NSLayoutConstraint value. Creats an Array with a NSLayoutConstraint value.
- Parameter format: The VFL format string. - Parameter format: The VFL format string.
- Parameter options: Additional NSLayoutFormatOptions. - Parameter options: Additional NSLayoutFormatOptions.
- Parameter metrics: An optional Dictionary<String, AnyObject> of metric key / value pairs. - Parameter metrics: An optional Dictionary<String, Any> of metric key / value pairs.
- Parameter views: A Dictionary<String, AnyObject> of view key / value pairs. - Parameter views: A Dictionary<String, Any> of view key / value pairs.
- Returns: The Array<NSLayoutConstraint> instance. - Returns: The Array<NSLayoutConstraint> instance.
*/ */
public class func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, AnyObject>?, views: Dictionary<String, AnyObject>) -> Array<NSLayoutConstraint> { public class func constraint(format: String, options: NSLayoutFormatOptions, metrics: Dictionary<String, Any>?, views: Dictionary<String, Any>) -> Array<NSLayoutConstraint> {
for (_, a) in views { for (_, a) in views {
if let v = a as? UIView { if let v = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false v.translatesAutoresizingMaskIntoConstraints = false
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
- Parameter initializer: Object initializer. - Parameter initializer: Object initializer.
- Returns: The associated reference for the initializer object. - Returns: The associated reference for the initializer object.
*/ */
internal func AssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, initializer: () -> T) -> T { internal func AssociatedObject<T: Any>(base: Any, key: UnsafePointer<UInt8>, initializer: () -> T) -> T {
if let v: T = objc_getAssociatedObject(base, key) as? T { if let v: T = objc_getAssociatedObject(base, key) as? T {
return v return v
} }
...@@ -52,6 +52,6 @@ internal func AssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer ...@@ -52,6 +52,6 @@ internal func AssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer
- Parameter value: The object instance to set for the associated object. - Parameter value: The object instance to set for the associated object.
- Returns: The associated reference for the initializer object. - Returns: The associated reference for the initializer object.
*/ */
internal func AssociateObject<T: AnyObject>(base: AnyObject, key: UnsafePointer<UInt8>, value: T) { internal func AssociateObject<T: Any>(base: Any, key: UnsafePointer<UInt8>, value: T) {
objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN) objc_setAssociatedObject(base, key, value, .OBJC_ASSOCIATION_RETAIN)
} }
...@@ -63,7 +63,7 @@ extension String { ...@@ -63,7 +63,7 @@ extension String {
:name: replacePunctuationCharacters :name: replacePunctuationCharacters
*/ */
public func replacePunctuationCharacters(separator: String = "") -> String { public func replacePunctuationCharacters(separator: String = "") -> String {
return components(separatedBy: CharacterSet.punctuation).joined(separator: separator).trim() return components(separatedBy: CharacterSet.punctuationCharacters).joined(separator: separator).trim()
} }
/** /**
......
...@@ -185,13 +185,13 @@ extension UIImage { ...@@ -185,13 +185,13 @@ extension UIImage {
- Parameter completion: A completion block that is executed once the image - Parameter completion: A completion block that is executed once the image
has been retrieved. has been retrieved.
*/ */
public class func contentsOfURL(url: URL, completion: ((image: UIImage?, error: Error?) -> Void)) { public class func contentsOfURL(url: URL, completion: ((UIImage?, Error?) -> Void)) {
URLSession.shared.dataTask(with: URLRequest(url: url)) { (data: Data?, response: URLResponse?, error: Error?) in URLSession.shared.dataTask(with: URLRequest(url: url)) { (data: Data?, response: URLResponse?, error: Error?) in
DispatchQueue.main.async { DispatchQueue.main.async {
if let v = error { if let v = error {
completion(image: nil, error: v) completion(nil, v)
} else if let v = data { } else if let v = data {
completion(image: UIImage(data: v), error: nil) completion(UIImage(data: v), nil)
} }
} }
}.resume() }.resume()
...@@ -246,9 +246,9 @@ extension UIImage { ...@@ -246,9 +246,9 @@ extension UIImage {
switch imageOrientation { switch imageOrientation {
case .left, .leftMirrored, .right, .rightMirrored: case .left, .leftMirrored, .right, .rightMirrored:
context.draw(in: CGRect(x: 0, y: 0, width: size.height, height: size.width), image: cgImage!) context.draw(cgImage!, in: CGRect(x: 0, y: 0, width: size.height, height: size.width))
default: default:
context.draw(in: CGRect(origin: .zero, size: size), image: cgImage!) context.draw(cgImage!, in: CGRect(origin: .zero, size: size))
} }
guard let cgImage = context.makeImage() else { guard let cgImage = context.makeImage() else {
......
...@@ -48,10 +48,7 @@ public class Material { ...@@ -48,10 +48,7 @@ public class Material {
guard let v = view else { guard let v = view else {
return return
} }
v.cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset)
if let preset: CornerRadiusPreset = cornerRadiusPreset {
v.cornerRadius = CornerRadiusPresetToValue(preset: preset)
}
} }
} }
...@@ -61,10 +58,7 @@ public class Material { ...@@ -61,10 +58,7 @@ public class Material {
guard let v = view else { guard let v = view else {
return return
} }
v.borderWidth = BorderWidthPresetToValue(preset: borderWidthPreset)
if let preset: BorderWidthPreset = borderWidthPreset {
v.borderWidth = BorderWidthPresetToValue(preset: preset)
}
} }
} }
......
...@@ -48,7 +48,7 @@ public class MaterialTextLayer : CATextLayer { ...@@ -48,7 +48,7 @@ public class MaterialTextLayer : CATextLayer {
*/ */
@IBInspectable public var text: String? { @IBInspectable public var text: String? {
didSet { didSet {
string = text as? AnyObject string = text as Any
} }
} }
...@@ -171,7 +171,7 @@ public class MaterialTextLayer : CATextLayer { ...@@ -171,7 +171,7 @@ public class MaterialTextLayer : CATextLayer {
/** /**
:name: init :name: init
*/ */
public override init(layer: AnyObject) { public override init(layer: Any) {
super.init() super.init()
prepareLayer() prepareLayer()
} }
...@@ -196,12 +196,10 @@ public class MaterialTextLayer : CATextLayer { ...@@ -196,12 +196,10 @@ public class MaterialTextLayer : CATextLayer {
:name: stringSize :name: stringSize
*/ */
public func stringSize(constrainedToWidth width: Double) -> CGSize { public func stringSize(constrainedToWidth width: Double) -> CGSize {
if let v = fontType { guard let v = fontType, let t = text, 0 < t.utf16.count else {
if 0 < text?.utf16.count { return CGSize.zero
return v.stringSize(string: text!, constrainedToWidth: width) }
} return v.stringSize(string: text!, constrainedToWidth: width)
}
return CGSize.zero
} }
/** /**
......
...@@ -196,93 +196,92 @@ public class NavigationBar: UINavigationBar { ...@@ -196,93 +196,92 @@ public class NavigationBar: UINavigationBar {
let titleView = prepareTitleView(item: item) let titleView = prepareTitleView(item: item)
let contentView = prepareContentView(item: item) let contentView = prepareContentView(item: item)
if let g: Int = Int(width / gridFactor) { let g = Int(width / gridFactor)
let columns: Int = g + 1 let columns = g + 1
titleView.frame.origin = CGPoint.zero titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize titleView.frame.size = intrinsicContentSize
titleView.grid.views = [] titleView.grid.views = []
titleView.grid.axis.columns = columns titleView.grid.axis.columns = columns
contentView.grid.columns = columns contentView.grid.columns = columns
// leftControls // leftControls
if let v: Array<UIControl> = item.leftControls { if let v: Array<UIControl> = item.leftControls {
for c in v { for c in v {
let w: CGFloat = c.intrinsicContentSize.width let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor) let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns contentView.grid.columns -= c.grid.columns
titleView.addSubview(c) titleView.addSubview(c)
titleView.grid.views.append(c) titleView.grid.views.append(c)
}
} }
}
titleView.addSubview(contentView)
titleView.grid.views.append(contentView) titleView.addSubview(contentView)
titleView.grid.views.append(contentView)
// rightControls
if let v: Array<UIControl> = item.rightControls { // rightControls
for c in v { if let v: Array<UIControl> = item.rightControls {
let w: CGFloat = c.intrinsicContentSize.width for c in v {
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero let w: CGFloat = c.intrinsicContentSize.width
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom (c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = titleView.frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1 let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c) titleView.addSubview(c)
} titleView.grid.views.append(c)
} }
}
titleView.grid.contentEdgeInsets = contentInset
titleView.grid.interimSpace = interimSpace titleView.grid.contentEdgeInsets = contentInset
titleView.grid.reload() titleView.grid.interimSpace = interimSpace
titleView.grid.reload()
// contentView alignment.
if nil != item.title && "" != item.title { // contentView alignment.
if nil == item.titleLabel.superview { if nil != item.title && "" != item.title {
contentView.addSubview(item.titleLabel) if nil == item.titleLabel.superview {
} contentView.addSubview(item.titleLabel)
item.titleLabel.frame = contentView.bounds }
} else { item.titleLabel.frame = contentView.bounds
item.titleLabel.removeFromSuperview() } else {
item.titleLabel.removeFromSuperview()
}
if nil != item.detail && "" != item.detail {
if nil == item.detailLabel.superview {
contentView.addSubview(item.detailLabel)
} }
if nil != item.detail && "" != item.detail { if nil == item.titleLabel.superview {
if nil == item.detailLabel.superview { item.detailLabel.frame = contentView.bounds
contentView.addSubview(item.detailLabel)
}
if nil == item.titleLabel.superview {
item.detailLabel.frame = contentView.bounds
} else {
item.titleLabel.sizeToFit()
item.detailLabel.sizeToFit()
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.size.height += diff
item.detailLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.origin.y = item.titleLabel.frame.height
}
} else { } else {
item.detailLabel.removeFromSuperview() item.titleLabel.sizeToFit()
item.detailLabel.sizeToFit()
let diff: CGFloat = (contentView.frame.height - item.titleLabel.frame.height - item.detailLabel.frame.height) / 2
item.titleLabel.frame.size.height += diff
item.titleLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.size.height += diff
item.detailLabel.frame.size.width = contentView.frame.width
item.detailLabel.frame.origin.y = item.titleLabel.frame.height
} }
} else {
contentView.grid.reload() item.detailLabel.removeFromSuperview()
} }
contentView.grid.reload()
} }
} }
......
...@@ -185,7 +185,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -185,7 +185,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
A CGFloat property that sets the animation duration of the A CGFloat property that sets the animation duration of the
leftView when closing and opening. Defaults to 0.25. leftView when closing and opening. Defaults to 0.25.
*/ */
@IBInspectable public var animationDuration: CGFloat = 0.25 @IBInspectable public var animationDuration: TimeInterval = 0.25
/** /**
A Boolean property that enables and disables the leftView from A Boolean property that enables and disables the leftView from
...@@ -619,7 +619,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -619,7 +619,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
showView(container: v) showView(container: v)
isUserInteractionEnabled = false isUserInteractionEnabled = false
delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .left) delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .left)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animate(withDuration: TimeInterval(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { animations: {
v.position.x = v.width / 2 v.position.x = v.width / 2
self.rootViewController.view.alpha = 0.5 self.rootViewController.view.alpha = 0.5
...@@ -645,7 +645,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -645,7 +645,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
showView(container: v) showView(container: v)
isUserInteractionEnabled = false isUserInteractionEnabled = false
delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .right) delegate?.navigationDrawerWillOpen?(navigationDrawerController: self, position: .right)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animate(withDuration: TimeInterval(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in animations: { [weak self] in
if let s = self { if let s = self {
v.position.x = s.view.bounds.width - v.width / 2 v.position.x = s.view.bounds.width - v.width / 2
...@@ -671,7 +671,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -671,7 +671,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
if let v: View = leftView { if let v: View = leftView {
isUserInteractionEnabled = true isUserInteractionEnabled = true
delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .left) delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .left)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animate(withDuration: TimeInterval(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in animations: { [weak self] in
if let s = self { if let s = self {
v.position.x = -v.width / 2 v.position.x = -v.width / 2
...@@ -699,7 +699,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele ...@@ -699,7 +699,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
if let v: View = rightView { if let v: View = rightView {
isUserInteractionEnabled = true isUserInteractionEnabled = true
delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .right) delegate?.navigationDrawerWillClose?(navigationDrawerController: self, position: .right)
UIView.animate(withDuration: Double(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))), UIView.animate(withDuration: TimeInterval(0 == velocity ? animationDuration : fmax(0.1, fmin(1, Double(v.x / velocity)))),
animations: { [weak self] in animations: { [weak self] in
if let s = self { if let s = self {
v.position.x = s.view.bounds.width + v.width / 2 v.position.x = s.view.bounds.width + v.width / 2
......
...@@ -170,10 +170,10 @@ public protocol PhotoLibraryDelegate { ...@@ -170,10 +170,10 @@ public protocol PhotoLibraryDelegate {
@objc(PhotoLibrary) @objc(PhotoLibrary)
public class PhotoLibrary: NSObject { public class PhotoLibrary: NSObject {
/// A reference to the PHCachingImageManager. /// A reference to the PHCachingImageManager.
public private(set) lazy var cachingImageManager = PHCachingImageManager() public internal(set) lazy var cachingImageManager = PHCachingImageManager()
/// A reference to all current PHFetchResults. /// A reference to all current PHFetchResults.
public private(set) lazy var fetchResultsDataSource = [String: PhotoLibraryFetchResultDataSource]() public internal(set) lazy var fetchResultsDataSource = [String: PhotoLibraryFetchResultDataSource]()
/// A reference to a PhotoLibraryDelegate. /// A reference to a PhotoLibraryDelegate.
public weak var delegate: PhotoLibraryDelegate? public weak var delegate: PhotoLibraryDelegate?
...@@ -252,8 +252,8 @@ extension PhotoLibrary { ...@@ -252,8 +252,8 @@ extension PhotoLibrary {
- Parameter fetchResult: A PHFetchResult<T>. - Parameter fetchResult: A PHFetchResult<T>.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
private func fetch<T: PHFetchResult<U>, U: PHObject>(caller: String, result: T, completion: ([U], T) -> Void) { internal func fetch<T: PHObject, U: PHFetchResult<T>>(caller: String, result: U, completion: (@escaping ([T], U) -> Void)? = nil) -> [T] {
var objects = [U]() var objects = [T]()
result.enumerateObjects({ (collection, _, _) in result.enumerateObjects({ (collection, _, _) in
objects.append(collection) objects.append(collection)
...@@ -263,12 +263,14 @@ extension PhotoLibrary { ...@@ -263,12 +263,14 @@ extension PhotoLibrary {
fetchResultsDataSource[caller] = PhotoLibraryFetchResultDataSource(fetchResult: result as! PHFetchResult<PHObject>, objects: objects) fetchResultsDataSource[caller] = PhotoLibraryFetchResultDataSource(fetchResult: result as! PHFetchResult<PHObject>, objects: objects)
if Thread.isMainThread { if Thread.isMainThread {
completion(objects, result) completion?(objects, result)
} else { } else {
DispatchQueue.main.async { [objects = objects, result = result, completion = completion] in DispatchQueue.main.async { [objects = objects, result = result, completion = completion] in
completion(objects, result) completion?(objects, result)
} }
} }
return objects
} }
} }
...@@ -283,8 +285,8 @@ extension PhotoLibrary { ...@@ -283,8 +285,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchCollectionListsContaining(_ collection: PHCollection, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchCollectionListsContaining(_ collection: PHCollection, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchCollectionListsContaining(collection, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchCollectionListsContaining(collection, options: options), completion: completion)
} }
/** /**
...@@ -294,8 +296,8 @@ extension PhotoLibrary { ...@@ -294,8 +296,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchCollectionList(with type: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchCollectionList(with type: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: type, subtype: subtype, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: type, subtype: subtype, options: options), completion: completion)
} }
/** /**
...@@ -307,8 +309,8 @@ extension PhotoLibrary { ...@@ -307,8 +309,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchCollectionLists(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchCollectionLists(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(withLocalIdentifiers: identifiers, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(withLocalIdentifiers: identifiers, options: options), completion: completion)
} }
/** /**
...@@ -320,8 +322,8 @@ extension PhotoLibrary { ...@@ -320,8 +322,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchCollectionLists(with collectionListType: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchCollectionLists(with collectionListType: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: collectionListType, subtype: subtype, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: collectionListType, subtype: subtype, options: options), completion: completion)
} }
/** /**
...@@ -331,8 +333,8 @@ extension PhotoLibrary { ...@@ -331,8 +333,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, containingMoment moment: PHAssetCollection, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, containingMoment moment: PHAssetCollection, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, containingMoment: moment, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, containingMoment: moment, options: options), completion: completion)
} }
/** /**
...@@ -341,8 +343,8 @@ extension PhotoLibrary { ...@@ -341,8 +343,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) { public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, options: options), completion: completion) return fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, options: options), completion: completion)
} }
} }
...@@ -354,8 +356,8 @@ extension PhotoLibrary { ...@@ -354,8 +356,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchCollections(in collectionList: PHCollectionList, options: PHFetchOptions?, completion: ([PHCollection], PHFetchResult<PHCollection>) -> Void) { public func fetchCollections(in collectionList: PHCollectionList, options: PHFetchOptions?, completion: (@escaping ([PHCollection], PHFetchResult<PHCollection>) -> Void)? = nil) -> [PHCollection] {
fetch(caller: #function, result: PHCollection.fetchCollections(in: collectionList, options: options), completion: completion) return fetch(caller: #function, result: PHCollection.fetchCollections(in: collectionList, options: options), completion: completion)
} }
/** /**
...@@ -365,8 +367,8 @@ extension PhotoLibrary { ...@@ -365,8 +367,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback. - Parameter completion: A completion callback.
*/ */
public func fetchTopLevelUserCollections(with options: PHFetchOptions?, completion: ([PHCollection], PHFetchResult<PHCollection>) -> Void) { public func fetchTopLevelUserCollections(with options: PHFetchOptions?, completion: (@escaping ([PHCollection], PHFetchResult<PHCollection>) -> Void)? = nil) -> [PHCollection] {
fetch(caller: #function, result: PHCollection.fetchTopLevelUserCollections(with: nil), completion: completion) return fetch(caller: #function, result: PHCollection.fetchTopLevelUserCollections(with: nil), completion: completion)
} }
} }
...@@ -379,8 +381,8 @@ extension PhotoLibrary { ...@@ -379,8 +381,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssetCollections(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchAssetCollections(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: identifiers, options: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: identifiers, options: options), completion: completion)
} }
/** /**
...@@ -391,8 +393,8 @@ extension PhotoLibrary { ...@@ -391,8 +393,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssetCollections(with type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchAssetCollections(with type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(with: type, subtype: subtype, options: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(with: type, subtype: subtype, options: options), completion: completion)
} }
/** /**
...@@ -402,8 +404,8 @@ extension PhotoLibrary { ...@@ -402,8 +404,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssetCollectionsContaining(_ asset: PHAsset, with type: PHAssetCollectionType, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchAssetCollectionsContaining(_ asset: PHAsset, with type: PHAssetCollectionType, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollectionsContaining(asset, with: type, options: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollectionsContaining(asset, with: type, options: options), completion: completion)
} }
/** /**
...@@ -414,8 +416,8 @@ extension PhotoLibrary { ...@@ -414,8 +416,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssetCollections(withALAssetGroupURLs assetGroupURLs: [URL], options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchAssetCollections(withALAssetGroupURLs assetGroupURLs: [URL], options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withALAssetGroupURLs: assetGroupURLs, options: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withALAssetGroupURLs: assetGroupURLs, options: options), completion: completion)
} }
/** /**
...@@ -424,8 +426,8 @@ extension PhotoLibrary { ...@@ -424,8 +426,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchMoments(inMomentList momentList: PHCollectionList, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchMoments(inMomentList momentList: PHCollectionList, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchMoments(inMomentList: momentList, options: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchMoments(inMomentList: momentList, options: options), completion: completion)
} }
/** /**
...@@ -433,8 +435,8 @@ extension PhotoLibrary { ...@@ -433,8 +435,8 @@ extension PhotoLibrary {
- Parameter with options: An optional PHFetchOptions object. - Parameter with options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchMoments(with options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) { public func fetchMoments(with options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
fetch(caller: #function, result: PHAssetCollection.fetchMoments(with: options), completion: completion) return fetch(caller: #function, result: PHAssetCollection.fetchMoments(with: options), completion: completion)
} }
} }
...@@ -446,8 +448,8 @@ extension PhotoLibrary { ...@@ -446,8 +448,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(in: assetCollection, options: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(in: assetCollection, options: options), completion: completion)
} }
/** /**
...@@ -457,8 +459,8 @@ extension PhotoLibrary { ...@@ -457,8 +459,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: options), completion: completion)
} }
/** /**
...@@ -468,11 +470,11 @@ extension PhotoLibrary { ...@@ -468,11 +470,11 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: An optional PHFetchResult<PHAsset> object. - Returns: An optional PHFetchResult<PHAsset> object.
*/ */
public func fetchKeyAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) -> PHFetchResult<PHAsset>? { public func fetchKeyAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> PHFetchResult<PHAsset>? {
guard let fetchResult = PHAsset.fetchKeyAssets(in: assetCollection, options: options) else { guard let fetchResult = PHAsset.fetchKeyAssets(in: assetCollection, options: options) else {
return nil return nil
} }
fetch(caller: #function, result: fetchResult, completion: completion) let _: [PHAsset] = fetch(caller: #function, result: fetchResult, completion: completion)
return fetchResult return fetchResult
} }
...@@ -483,8 +485,8 @@ extension PhotoLibrary { ...@@ -483,8 +485,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(withBurstIdentifier burstIdentifier: String, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(withBurstIdentifier burstIdentifier: String, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(withBurstIdentifier: burstIdentifier, options: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(withBurstIdentifier: burstIdentifier, options: options), completion: completion)
} }
/** /**
...@@ -493,8 +495,8 @@ extension PhotoLibrary { ...@@ -493,8 +495,8 @@ extension PhotoLibrary {
- Parameter with options: An optional PHFetchOptions object. - Parameter with options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(with options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(with options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(with: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(with: options), completion: completion)
} }
/** /**
...@@ -503,8 +505,8 @@ extension PhotoLibrary { ...@@ -503,8 +505,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(with mediaType: PHAssetMediaType, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(with mediaType: PHAssetMediaType, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(with: mediaType, options: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(with: mediaType, options: options), completion: completion)
} }
/** /**
...@@ -514,8 +516,8 @@ extension PhotoLibrary { ...@@ -514,8 +516,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object. - Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block. - Parameter completion: A completion block.
*/ */
public func fetchAssets(withALAssetURLs assetURLs: [URL], options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) { public func fetchAssets(withALAssetURLs assetURLs: [URL], options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
fetch(caller: #function, result: PHAsset.fetchAssets(withALAssetURLs: assetURLs, options: options), completion: completion) return fetch(caller: #function, result: PHAsset.fetchAssets(withALAssetURLs: assetURLs, options: options), completion: completion)
} }
} }
...@@ -531,7 +533,7 @@ extension PhotoLibrary { ...@@ -531,7 +533,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
public func requestImage(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHImageRequestOptions?, completion: (UIImage?, [NSObject: AnyObject]?) -> Void) -> PHImageRequestID { public func requestImage(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHImageRequestOptions?, completion: @escaping (UIImage?, [AnyHashable: Any]?) -> Void) -> PHImageRequestID {
return PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: contentMode, options: options, resultHandler: completion) return PHImageManager.default().requestImage(for: asset, targetSize: targetSize, contentMode: contentMode, options: options, resultHandler: completion)
} }
...@@ -542,7 +544,7 @@ extension PhotoLibrary { ...@@ -542,7 +544,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
public func requestImageData(for asset: PHAsset, options: PHImageRequestOptions?, completion: (Data?, String?, UIImageOrientation, [NSObject: AnyObject]?) -> Void) -> PHImageRequestID { public func requestImageData(for asset: PHAsset, options: PHImageRequestOptions?, completion: @escaping (Data?, String?, UIImageOrientation, [AnyHashable: Any]?) -> Void) -> PHImageRequestID {
return PHImageManager.default().requestImageData(for: asset, options: options, resultHandler: completion) return PHImageManager.default().requestImageData(for: asset, options: options, resultHandler: completion)
} }
...@@ -570,7 +572,7 @@ extension PhotoLibrary { ...@@ -570,7 +572,7 @@ extension PhotoLibrary {
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
@available(iOS 9.1, *) @available(iOS 9.1, *)
public func requestLivePhoto(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHLivePhotoRequestOptions?, completion: (PHLivePhoto?, [NSObject : AnyObject]?) -> Void) -> PHImageRequestID { public func requestLivePhoto(for asset: PHAsset, targetSize: CGSize, contentMode: PHImageContentMode, options: PHLivePhotoRequestOptions?, completion: @escaping (PHLivePhoto?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID {
return PHImageManager.default().requestLivePhoto(for: asset, targetSize: targetSize, contentMode: contentMode, options: options, resultHandler: completion) return PHImageManager.default().requestLivePhoto(for: asset, targetSize: targetSize, contentMode: contentMode, options: options, resultHandler: completion)
} }
...@@ -581,7 +583,7 @@ extension PhotoLibrary { ...@@ -581,7 +583,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
public func requestPlayerItem(forVideo asset: PHAsset, options: PHVideoRequestOptions?, completion: (AVPlayerItem?, [NSObject : AnyObject]?) -> Swift.Void) -> PHImageRequestID { public func requestPlayerItem(forVideo asset: PHAsset, options: PHVideoRequestOptions?, completion: @escaping (AVPlayerItem?, [AnyHashable : Any]?) -> Swift.Void) -> PHImageRequestID {
return PHImageManager.default().requestPlayerItem(forVideo: asset, options: options, resultHandler: completion) return PHImageManager.default().requestPlayerItem(forVideo: asset, options: options, resultHandler: completion)
} }
...@@ -592,7 +594,7 @@ extension PhotoLibrary { ...@@ -592,7 +594,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
public func requestExportSession(forVideo asset: PHAsset, options: PHVideoRequestOptions?, exportPreset: String, completion: (AVAssetExportSession?, [NSObject : AnyObject]?) -> Void) -> PHImageRequestID { public func requestExportSession(forVideo asset: PHAsset, options: PHVideoRequestOptions?, exportPreset: String, completion: @escaping (AVAssetExportSession?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID {
return PHImageManager.default().requestExportSession(forVideo: asset, options: options, exportPreset: exportPreset, resultHandler: completion) return PHImageManager.default().requestExportSession(forVideo: asset, options: options, exportPreset: exportPreset, resultHandler: completion)
} }
...@@ -603,7 +605,7 @@ extension PhotoLibrary { ...@@ -603,7 +605,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block. - Parameter completion: A completion block.
- Returns: A PHImageRequestID. - Returns: A PHImageRequestID.
*/ */
public func requestAVAsset(forVideo asset: PHAsset, options: PHVideoRequestOptions?, completion: (AVAsset?, AVAudioMix?, [NSObject : AnyObject]?) -> Void) -> PHImageRequestID { public func requestAVAsset(forVideo asset: PHAsset, options: PHVideoRequestOptions?, completion: @escaping (AVAsset?, AVAudioMix?, [AnyHashable : Any]?) -> Void) -> PHImageRequestID {
return PHImageManager.default().requestAVAsset(forVideo: asset, options: options, resultHandler: completion) return PHImageManager.default().requestAVAsset(forVideo: asset, options: options, resultHandler: completion)
} }
} }
...@@ -640,7 +642,7 @@ extension PhotoLibrary: PHPhotoLibraryChangeObserver { ...@@ -640,7 +642,7 @@ extension PhotoLibrary: PHPhotoLibraryChangeObserver {
s.delegate?.photoLibrary?(photoLibrary: s, beforeChanges: details.objectBeforeChanges, afterChanges: afterChanges, assetContentChanged: details.assetContentChanged, objectWasDeleted: details.objectWasDeleted) s.delegate?.photoLibrary?(photoLibrary: s, beforeChanges: details.objectBeforeChanges, afterChanges: afterChanges, assetContentChanged: details.assetContentChanged, objectWasDeleted: details.objectWasDeleted)
} }
if let details = changeInfo.changeDetails(for: dataSource.fetchResult as! PHFetchResult<AnyObject>) { if let details = changeInfo.changeDetails(for: dataSource.fetchResult) {
s.delegate?.photoLibrary?(photoLibrary: s, fetchBeforeChanges: details.fetchResultBeforeChanges, fetchAfterChanges: details.fetchResultAfterChanges) s.delegate?.photoLibrary?(photoLibrary: s, fetchBeforeChanges: details.fetchResultBeforeChanges, fetchAfterChanges: details.fetchResultAfterChanges)
dataSource.fetchResult = details.fetchResultAfterChanges dataSource.fetchResult = details.fetchResultAfterChanges
...@@ -689,7 +691,7 @@ extension PhotoLibrary { ...@@ -689,7 +691,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block that is executed once the - Parameter completion: A completion block that is executed once the
transaction has been completed. transaction has been completed.
*/ */
public func performChanges(_ block: () -> Void, completion: ((Bool, Error?) -> Void)? = nil) { public func performChanges(_ block: @escaping () -> Void, completion: ((Bool, Error?) -> Void)? = nil) {
PHPhotoLibrary.shared().performChanges(block, completionHandler: completion) PHPhotoLibrary.shared().performChanges(block, completionHandler: completion)
} }
} }
...@@ -315,7 +315,7 @@ public class Switch: UIControl { ...@@ -315,7 +315,7 @@ public class Switch: UIControl {
Toggle the Switch state, if On will be Off, and if Off will be On. Toggle the Switch state, if On will be Off, and if Off will be On.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
*/ */
public func toggle(completion: ((control: Switch) -> Void)? = nil) { public func toggle(completion: ((Switch) -> Void)? = nil) {
setSwitchState(state: .on == internalSwitchState ? .off : .on, animated: true, completion: completion) setSwitchState(state: .on == internalSwitchState ? .off : .on, animated: true, completion: completion)
} }
...@@ -324,7 +324,7 @@ public class Switch: UIControl { ...@@ -324,7 +324,7 @@ public class Switch: UIControl {
- Parameter on: A bool of whether the switch should be in the on state or not. - Parameter on: A bool of whether the switch should be in the on state or not.
- Parameter animated: A Boolean indicating to set the animation or not. - Parameter animated: A Boolean indicating to set the animation or not.
*/ */
public func setOn(on: Bool, animated: Bool, completion: ((control: Switch) -> Void)? = nil) { public func setOn(on: Bool, animated: Bool, completion: ((Switch) -> Void)? = nil) {
setSwitchState(state: on ? .on : .off, animated: animated, completion: completion) setSwitchState(state: on ? .on : .off, animated: animated, completion: completion)
} }
...@@ -334,14 +334,14 @@ public class Switch: UIControl { ...@@ -334,14 +334,14 @@ public class Switch: UIControl {
- Parameter animated: A Boolean indicating to set the animation or not. - Parameter animated: A Boolean indicating to set the animation or not.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
*/ */
public func setSwitchState(state: SwitchState, animated: Bool = true, completion: ((control: Switch) -> Void)? = nil) { public func setSwitchState(state: SwitchState, animated: Bool = true, completion: ((Switch) -> Void)? = nil) {
if isEnabled && internalSwitchState != state { if isEnabled && internalSwitchState != state {
internalSwitchState = state internalSwitchState = state
if animated { if animated {
animateToState(state: state) { [weak self] _ in animateToState(state: state) { [weak self] _ in
if let s: Switch = self { if let s: Switch = self {
s.sendActions(for: .valueChanged) s.sendActions(for: .valueChanged)
completion?(control: s) completion?(s)
s.delegate?.switchStateChanged(control: s) s.delegate?.switchStateChanged(control: s)
} }
} }
...@@ -349,7 +349,7 @@ public class Switch: UIControl { ...@@ -349,7 +349,7 @@ public class Switch: UIControl {
button.x = .on == state ? self.onPosition : self.offPosition button.x = .on == state ? self.onPosition : self.offPosition
styleForState(state: state) styleForState(state: state)
sendActions(for: .valueChanged) sendActions(for: .valueChanged)
completion?(control: self) completion?(self)
delegate?.switchStateChanged(control: self) delegate?.switchStateChanged(control: self)
} }
} }
...@@ -508,7 +508,7 @@ public class Switch: UIControl { ...@@ -508,7 +508,7 @@ public class Switch: UIControl {
- Parameter state: The SwitchState to set. - Parameter state: The SwitchState to set.
- Parameter completion: An Optional completion block. - Parameter completion: An Optional completion block.
*/ */
private func animateToState(state: SwitchState, completion: ((control: Switch) -> Void)? = nil) { private func animateToState(state: SwitchState, completion: ((Switch) -> Void)? = nil) {
isUserInteractionEnabled = false isUserInteractionEnabled = false
UIView.animate(withDuration: 0.15, UIView.animate(withDuration: 0.15,
delay: 0.05, delay: 0.05,
...@@ -527,7 +527,7 @@ public class Switch: UIControl { ...@@ -527,7 +527,7 @@ public class Switch: UIControl {
}) { [weak self] _ in }) { [weak self] _ in
if let s: Switch = self { if let s: Switch = self {
s.isUserInteractionEnabled = true s.isUserInteractionEnabled = true
completion?(control: s) completion?(s)
} }
} }
} }
......
...@@ -53,15 +53,15 @@ public class TabBar: View { ...@@ -53,15 +53,15 @@ public class TabBar: View {
} }
/// Buttons. /// Buttons.
public var buttons: Array<UIButton>? { public var buttons: [UIButton]? {
didSet { didSet {
if let v: Array<UIButton> = oldValue { if let v: [UIButton] = oldValue {
for b in v { for b in v {
b.removeFromSuperview() b.removeFromSuperview()
} }
} }
if let v: Array<UIButton> = buttons { if let v: [UIButton] = buttons {
for b in v { for b in v {
addSubview(b) addSubview(b)
} }
...@@ -73,7 +73,7 @@ public class TabBar: View { ...@@ -73,7 +73,7 @@ public class TabBar: View {
public override func layoutSubviews() { public override func layoutSubviews() {
super.layoutSubviews() super.layoutSubviews()
if willRenderView { if willRenderView {
if let v: Array<UIButton> = buttons { if let v: [UIButton] = buttons {
if 0 < v.count { if 0 < v.count {
let columns: Int = grid.axis.columns / v.count let columns: Int = grid.axis.columns / v.count
for b in v { for b in v {
......
...@@ -85,7 +85,7 @@ public class TextStorage: NSTextStorage { ...@@ -85,7 +85,7 @@ public class TextStorage: NSTextStorage {
If you don't need this value, pass NULL. If you don't need this value, pass NULL.
- Returns: The attributes for the character at index. - Returns: The attributes for the character at index.
*/ */
public override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [String : AnyObject] { public override func attributes(at location: Int, effectiveRange range: NSRangePointer?) -> [String : Any] {
return store.attributes(at: location, effectiveRange: range) return store.attributes(at: location, effectiveRange: range)
} }
...@@ -106,7 +106,7 @@ public class TextStorage: NSTextStorage { ...@@ -106,7 +106,7 @@ public class TextStorage: NSTextStorage {
- Parameter range: A range of characters that will have their - Parameter range: A range of characters that will have their
attributes updated. attributes updated.
*/ */
public override func setAttributes(_ attrs: [String : AnyObject]?, range: NSRange) { public override func setAttributes(_ attrs: [String : Any]?, range: NSRange) {
store.setAttributes(attrs, range: range) store.setAttributes(attrs, range: range)
edited(NSTextStorageEditActions.editedAttributes, range: range, changeInLength: 0) edited(NSTextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
} }
......
...@@ -181,21 +181,32 @@ public class TextView: UITextView { ...@@ -181,21 +181,32 @@ public class TextView: UITextView {
p.isHidden = !(true == text?.isEmpty) p.isHidden = !(true == text?.isEmpty)
} }
if 0 < text?.utf16.count { guard let t = text else {
showTitleLabel() hideTitleLabel()
} else if 0 == text?.utf16.count { return
hideTitleLabel() }
}
if 0 < t.utf16.count {
showTitleLabel()
} else {
hideTitleLabel()
}
} }
/// Notification handler for when text editing ended. /// Notification handler for when text editing ended.
internal func handleTextViewTextDidEnd() { internal func handleTextViewTextDidEnd() {
if 0 < text?.utf16.count { guard let t = text else {
showTitleLabel() hideTitleLabel()
} else if 0 == text?.utf16.count { return
hideTitleLabel() }
}
titleLabel?.textColor = titleLabelColor if 0 < t.utf16.count {
showTitleLabel()
} else {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelColor
} }
/** /**
...@@ -233,11 +244,13 @@ public class TextView: UITextView { ...@@ -233,11 +244,13 @@ public class TextView: UITextView {
if let v: UILabel = titleLabel { if let v: UILabel = titleLabel {
v.isHidden = true v.isHidden = true
addSubview(v) addSubview(v)
if 0 < text?.utf16.count {
showTitleLabel() guard let t = text, 0 == t.utf16.count else {
} else { v.alpha = 0
v.alpha = 0 return
} }
showTitleLabel()
} }
} }
......
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