Commit 6c813dcf by Daniel Dahan

development: Updated to Xcode Beta 6

parent d2aa614b
......@@ -56,13 +56,13 @@ public func AnimationFillModeToValue(mode: AnimationFillMode) -> AnimationFillMo
}
}
public typealias AnimationDelayCancelBlock = (cancel : Bool) -> Void
public typealias AnimationDelayCancelBlock = (Bool) -> Void
public struct Animation {
/// 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)
}
......@@ -78,7 +78,7 @@ public struct Animation {
cancelable = delayed
dispatch_later {
cancelable?(cancel: false)
cancelable?(false)
}
return cancelable;
......@@ -88,7 +88,7 @@ public struct Animation {
:name: delayCancel
*/
public static func delayCancel(completion: AnimationDelayCancelBlock?) {
completion?(cancel: true)
completion?(true)
}
......
......@@ -32,8 +32,8 @@ import UIKit
public class BottomNavigationFadeAnimatedTransitioning : NSObject, UIViewControllerAnimatedTransitioning {
public func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
let fromView : UIView = transitionContext.view(forKey: UITransitionContextFromViewKey)!
let toView : UIView = transitionContext.view(forKey: UITransitionContextToViewKey)!
let fromView : UIView = transitionContext.view(forKey: UITransitionContextViewKey.from)!
let toView : UIView = transitionContext.view(forKey: UITransitionContextViewKey.to)!
toView.alpha = 0
transitionContext.containerView.addSubview(fromView)
......
......@@ -150,10 +150,10 @@ public protocol CaptureSessionDelegate {
- Parameter captureSession: A reference to the calling CaptureSession.
- Parameter captureOut: An AVCaptureFileOutput.
- Parameter fileURL: A file URL.
- Parameter fromConnections: An array of AnyObjects.
- Parameter fromConnections: An array of Anys.
*/
@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
......@@ -161,11 +161,11 @@ public protocol CaptureSessionDelegate {
- Parameter captureSession: A reference to the calling CaptureSession.
- Parameter captureOut: An AVCaptureFileOutput.
- 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.
*/
@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)
......@@ -186,7 +186,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
private var movieOutput: AVCaptureMovieFileOutput!
/// A reference to the movie output URL.
private var movieOutputURL: NSURL?
private var movieOutputURL: URL?
/// A reference to the AVCaptureSession.
internal var session: AVCaptureSession!
......@@ -272,7 +272,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focusMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focusMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0001, userInfo: userInfo)
......@@ -301,11 +301,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported flashMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported flashMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0002, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
if let e = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
......@@ -330,11 +330,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported torchMode.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported torchMode.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0003, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
if let e: NSError = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
......@@ -476,11 +476,11 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported focus.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported focus.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0004, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
if let e = error {
delegate?.captureSessionFailedWithError?(captureSession: self, error: e)
......@@ -507,22 +507,22 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
error = e
}
} else {
var userInfo: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var userInfo: Dictionary<String, Any> = Dictionary<String, Any>()
userInfo[NSLocalizedDescriptionKey] = "[Material Error: Unsupported expose.]"
userInfo[NSLocalizedFailureReasonErrorKey] = "[Material Error: Unsupported expose.]"
error = NSError(domain: "io.cosmicmind.Material.Capture", code: 0005, userInfo: userInfo)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
if let e = error {
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 {
let device: AVCaptureDevice = object as! AVCaptureDevice
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() {
do {
try device.lockForConfiguration()
......@@ -571,26 +571,26 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
if let v: AVCaptureConnection = s.imageOutput.connection(withMediaType: AVMediaTypeVideo) {
v.videoOrientation = s.videoOrientation
s.imageOutput.captureStillImageAsynchronously(from: v) { [weak self] (sampleBuffer: CMSampleBuffer?, error: Error?) -> Void in
if let s: CaptureSession = self {
var captureError: Error? = error
if let s = self {
var captureError = error
if nil == captureError {
let data: NSData = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)
if let image1: UIImage = UIImage(data: data as Data) {
if let image2: UIImage = image1.adjustOrientation() {
let data = AVCaptureStillImageOutput.jpegStillImageNSDataRepresentation(sampleBuffer)!
if let image1 = UIImage(data: data) {
if let image2 = image1.adjustOrientation() {
s.delegate?.captureSessionStillImageAsynchronously?(captureSession: s, image: image2)
} else {
var userInfo = [String: AnyObject]()
var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[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)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
} else {
var userInfo = [String: AnyObject]()
var userInfo = [String: Any]()
userInfo[NSLocalizedDescriptionKey] = "[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)
userInfo[NSUnderlyingErrorKey] = error as? AnyObject
userInfo[NSUnderlyingErrorKey] = error
}
}
......@@ -625,7 +625,7 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
}
s.movieOutputURL = s.uniqueURL()
if let v: NSURL = s.movieOutputURL {
if let v = s.movieOutputURL {
s.movieOutput.startRecording(toOutputFileURL: v as URL!, recordingDelegate: s)
}
}
......@@ -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
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
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.
......@@ -721,9 +721,9 @@ public class CaptureSession: NSObject, AVCaptureFileOutputRecordingDelegate {
Creates a unique URL if possible.
- Returns: A NSURL if it is possible to create one.
*/
private func uniqueURL() -> NSURL? {
private func uniqueURL() -> URL? {
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()
dateFormatter.dateStyle = .full
dateFormatter.timeStyle = .full
......
......@@ -165,7 +165,7 @@ public class Card: PulseView {
/**
:name: leftButtons
*/
public var leftButtons: Array<UIButton>? {
public var leftButtons = [UIButton]() {
didSet {
reloadView()
}
......@@ -192,7 +192,7 @@ public class Card: PulseView {
/**
:name: rightButtons
*/
public var rightButtons: Array<UIButton>? {
public var rightButtons = [UIButton]() {
didSet {
reloadView()
}
......@@ -222,7 +222,7 @@ public class Card: PulseView {
/**
: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)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
}
......@@ -235,10 +235,10 @@ public class Card: PulseView {
if self.layer == layer {
if divider {
var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height
} else if 0 < rightButtons?.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height
if 0 < leftButtons.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons[0].frame.height
} else if 0 < rightButtons.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons[0].frame.height
}
if 0 < y {
prepareDivider(y: bounds.height - y - 0.5, width: bounds.width)
......@@ -261,8 +261,8 @@ public class Card: PulseView {
}
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var views: Dictionary<String, Any> = Dictionary<String, Any>()
var metrics: Dictionary<String, Any> = Dictionary<String, Any>()
if nil != titleLabel {
verticalFormat += "-(insetTop)"
......@@ -296,70 +296,66 @@ public class Card: PulseView {
}
// leftButtons
if let v: Array<UIButton> = leftButtons {
if 0 < v.count {
var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0
for b in v {
let k: String = "b\(i)"
d[k] = b
if 0 == i {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
}
if 0 < leftButtons.count {
var h = "H:|"
var d = Dictionary<String, Any>()
var i = 0
for b in leftButtons {
let k: String = "b\(i)"
d[k] = b
if 0 == i {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
// rightButtons
if let v: Array<UIButton> = rightButtons {
if 0 < v.count {
var h: String = "H:"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = v.count - 1
for b in v {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
}
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
}
}
if 0 < rightButtons.count {
var h = "H:"
var d = Dictionary<String, Any>()
var i = rightButtons.count - 1
for b in rightButtons {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
}
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]"
views["button"] = leftButtons![0]
views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
} else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
......@@ -412,11 +408,11 @@ public class Card: PulseView {
/**
: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.titleLabel = titleLabel
self.contentView = contentView
self.leftButtons = leftButtons
self.rightButtons = rightButtons
self.leftButtons = leftButtons ?? []
self.rightButtons = rightButtons ?? []
}
}
......@@ -137,7 +137,7 @@ public class CollectionViewLayout: UICollectionViewLayout {
for i in 0..<dataSourceItems.count {
let item: DataSourceItem = dataSourceItems[i]
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 += nil == item.width ? itemSize.width : item.width!
......
......@@ -164,58 +164,57 @@ public class ControlView: View {
if willRenderView {
layoutIfNeeded()
if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1
grid.views = []
grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views.append(c)
}
}
addSubview(contentView)
grid.views.append(contentView)
// rightControls
if let v = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views.append(c)
}
}
grid.contentEdgeInsets = contentInset
grid.interimSpace = interimSpace
grid.reload()
contentView.grid.reload()
}
}
}
let g = Int(width / gridFactor)
let columns = g + 1
grid.views = []
grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v = leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views.append(c)
}
}
addSubview(contentView)
grid.views.append(contentView)
// rightControls
if let v = rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(c as? UIButton)?.contentEdgeInsets = UIEdgeInsets.zero
c.frame.size.height = frame.size.height - contentInset.top - contentInset.bottom
let q: Int = Int(w / gridFactor)
c.grid.columns = q + 1
contentView.grid.columns -= c.grid.columns
addSubview(c)
grid.views.append(c)
}
}
grid.contentEdgeInsets = contentInset
grid.interimSpace = interimSpace
grid.reload()
contentView.grid.reload()
}
}
/**
Prepares the view instance when intialized. When subclassing,
......
......@@ -32,7 +32,7 @@ import UIKit
public struct DataSourceItem {
/// Stores an the data for the item.
public var data: AnyObject?
public var data: Any?
/// Width for horizontal scroll direction.
public var width: CGFloat?
......@@ -42,12 +42,12 @@ public struct DataSourceItem {
/**
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.
- Parameter width: The width for the horizontal 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.width = width
self.height = height
......
......@@ -96,8 +96,8 @@ private class FontLoader {
var error: Unmanaged<CFError>?
if !CTFontManagerRegisterGraphicsFont(font, &error) {
let errorDescription = CFErrorCopyDescription(error!.takeUnretainedValue())
let nsError = error!.takeUnretainedValue() as AnyObject as! Error
NSException(name: .internalInconsistencyException, reason: errorDescription as? String, userInfo: [NSUnderlyingErrorKey: nsError as AnyObject]).raise()
let nsError = error!.takeUnretainedValue() as Any as! Error
NSException(name: .internalInconsistencyException, reason: errorDescription as? String, userInfo: [NSUnderlyingErrorKey: nsError as Any]).raise()
}
}
}
......
......@@ -258,7 +258,7 @@ public class ImageCard: PulseView {
/**
:name: leftButtons
*/
public var leftButtons: Array<UIButton>? {
public var leftButtons = [UIButton]() {
didSet {
reloadView()
}
......@@ -285,7 +285,7 @@ public class ImageCard: PulseView {
/**
:name: rightButtons
*/
public var rightButtons: Array<UIButton>? {
public var rightButtons = [UIButton]() {
didSet {
reloadView()
}
......@@ -315,7 +315,7 @@ public class ImageCard: PulseView {
/**
: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)
prepareProperties(image: image, titleLabel: titleLabel, contentView: contentView, leftButtons: leftButtons, rightButtons: rightButtons)
}
......@@ -332,10 +332,10 @@ public class ImageCard: PulseView {
// divider
if divider {
var y: CGFloat = contentInset.bottom + dividerInset.bottom
if 0 < leftButtons?.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons![0].frame.height
} else if 0 < rightButtons?.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons![0].frame.height
if 0 < leftButtons.count {
y += leftButtonsInset.top + leftButtonsInset.bottom + leftButtons[0].frame.height
} else if 0 < rightButtons.count {
y += rightButtonsInset.top + rightButtonsInset.bottom + rightButtons[0].frame.height
}
if 0 < y {
prepareDivider(y: bounds.height - y - 0.5, width: bounds.width)
......@@ -358,8 +358,8 @@ public class ImageCard: PulseView {
}
var verticalFormat: String = "V:|"
var views: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var metrics: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var views: Dictionary<String, Any> = Dictionary<String, Any>()
var metrics: Dictionary<String, Any> = Dictionary<String, Any>()
if nil != imageLayer?.contents {
verticalFormat += "-(insetTop)"
......@@ -399,71 +399,67 @@ public class ImageCard: PulseView {
}
// leftButtons
if let v: Array<UIButton> = leftButtons {
if 0 < v.count {
var h: String = "H:|"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = 0
for b in v {
let k: String = "b\(i)"
d[k] = b
if 0 == i {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
}
if 0 < leftButtons.count {
var h: String = "H:|"
var d: Dictionary<String, Any> = Dictionary<String, Any>()
var i: Int = 0
for b in leftButtons {
let k: String = "b\(i)"
d[k] = b
if 0 == i {
h += "-(left)-"
} else {
h += "-(left_right)-"
}
h += "[\(k)]"
_ = layout(b).bottom(contentInset.bottom + leftButtonsInset.bottom)
i += 1
}
addConstraints(Layout.constraint(format: h, options: [], metrics: ["left" : contentInset.left + leftButtonsInset.left, "left_right" : leftButtonsInset.left + leftButtonsInset.right], views: d))
}
// rightButtons
if let v: Array<UIButton> = rightButtons {
if 0 < v.count {
var h: String = "H:"
var d: Dictionary<String, AnyObject> = Dictionary<String, AnyObject>()
var i: Int = v.count - 1
for b in v {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
}
addConstraints(Layout.constraint(format: h + "|", options: [], metrics: ["right" : contentInset.right + rightButtonsInset.right, "right_left" : rightButtonsInset.right + rightButtonsInset.left], views: d))
}
}
if 0 < rightButtons.count {
var h: String = "H:"
var d: Dictionary<String, Any> = Dictionary<String, Any>()
var i: Int = rightButtons.count - 1
for b in rightButtons {
let k: String = "b\(i)"
d[k] = b
h += "[\(k)]"
if 0 == i {
h += "-(right)-"
} else {
h += "-(right_left)-"
}
_ = layout(b).bottom(contentInset.bottom + rightButtonsInset.bottom)
i -= 1
}
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 0 < leftButtons?.count {
if 0 < leftButtons.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
} else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
......@@ -484,14 +480,14 @@ public class ImageCard: PulseView {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentInset.top + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else if nil != contentView {
if 0 < leftButtons?.count {
if 0 < leftButtons.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = leftButtons![0]
views["button"] = leftButtons[0]
metrics["insetC"] = leftButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
} else if 0 < rightButtons.count {
verticalFormat += "-(insetC)-[button]"
views["button"] = rightButtons![0]
views["button"] = rightButtons[0]
metrics["insetC"] = rightButtonsInset.top
metrics["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
}
......@@ -502,14 +498,14 @@ public class ImageCard: PulseView {
metrics["insetC"] = (metrics["insetC"] as! CGFloat) + contentViewInset.bottom + (divider ? dividerInset.top + dividerInset.bottom : 0)
}
} else {
if 0 < leftButtons?.count {
if 0 < leftButtons.count {
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["insetBottom"] = contentInset.bottom + leftButtonsInset.bottom
} else if 0 < rightButtons?.count {
} else if 0 < rightButtons.count {
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["insetBottom"] = contentInset.bottom + rightButtonsInset.bottom
} else {
......@@ -565,11 +561,11 @@ public class ImageCard: PulseView {
/**
: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.titleLabel = titleLabel
self.contentView = contentView
self.leftButtons = leftButtons
self.rightButtons = rightButtons
self.leftButtons = leftButtons ?? []
self.rightButtons = rightButtons ?? []
}
}
......@@ -41,20 +41,20 @@ public class JSON: Equatable, CustomStringConvertible {
/**
:name: object
*/
public private(set) var object: AnyObject
public private(set) var object: Any
/**
:name: asArray
*/
public var asArray: [AnyObject]? {
return object as? [AnyObject]
public var asArray: [Any]? {
return object as? [Any]
}
/**
:name: asDictionary
*/
public var asDictionary: [String: AnyObject]? {
return object as? [String: AnyObject]
public var asDictionary: [String: Any]? {
return object as? [String: Any]
}
/**
......@@ -95,7 +95,7 @@ public class JSON: Equatable, CustomStringConvertible {
/**
:name: asNSData
*/
public var asNSData: NSData? {
public var asNSData: Data? {
return JSON.serialize(object: object)
}
......@@ -122,14 +122,14 @@ public class JSON: Equatable, CustomStringConvertible {
/**
:name: serialize
*/
public class func serialize(object: AnyObject) -> Data? {
public class func serialize(object: Any) -> Data? {
return try? JSONSerialization.data(withJSONObject: object, options: [])
}
/**
:name: stringify
*/
public class func stringify(_ object: AnyObject) -> String? {
public class func stringify(_ object: Any) -> String? {
if let o = object as? JSON {
return stringify(o.object)
} else if let data = JSON.serialize(object: object) {
......@@ -143,7 +143,7 @@ public class JSON: Equatable, CustomStringConvertible {
/**
:name: init
*/
public required init(_ object: AnyObject) {
public required init(_ object: Any) {
if let o = object as? JSON {
self.object = o.object
} else {
......
......@@ -196,9 +196,7 @@ public class Layer: CAShapeLayer {
*/
public var cornerRadiusPreset: CornerRadiusPreset = .none {
didSet {
if let v: CornerRadiusPreset = cornerRadiusPreset {
cornerRadius = CornerRadiusPresetToValue(preset: v)
}
cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset)
}
}
......@@ -254,9 +252,9 @@ public class Layer: CAShapeLayer {
/**
An initializer the same as init(). The layer parameter is ignored
to avoid crashes on certain architectures.
- Parameter layer: AnyObject.
- Parameter layer: Any.
*/
public override init(layer: AnyObject) {
public override init(layer: Any) {
contentsGravityPreset = .ResizeAspectFill
super.init()
prepareVisualLayer()
......
......@@ -850,11 +850,11 @@ extension Layout {
Creats an Array with a NSLayoutConstraint value.
- Parameter format: The VFL format string.
- Parameter options: Additional NSLayoutFormatOptions.
- Parameter metrics: An optional Dictionary<String, AnyObject> of metric key / value pairs.
- Parameter views: A Dictionary<String, AnyObject> of view key / value pairs.
- Parameter metrics: An optional Dictionary<String, Any> of metric key / value pairs.
- Parameter views: A Dictionary<String, Any> of view key / value pairs.
- 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 {
if let v = a as? UIView {
v.translatesAutoresizingMaskIntoConstraints = false
......
......@@ -35,7 +35,7 @@
- Parameter initializer: Object initializer.
- 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 {
return v
}
......@@ -52,6 +52,6 @@ internal func AssociatedObject<T: AnyObject>(base: AnyObject, key: UnsafePointer
- Parameter value: The object instance to set for the associated 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)
}
......@@ -63,7 +63,7 @@ extension String {
:name: replacePunctuationCharacters
*/
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 {
- Parameter completion: A completion block that is executed once the image
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
DispatchQueue.main.async {
if let v = error {
completion(image: nil, error: v)
completion(nil, v)
} else if let v = data {
completion(image: UIImage(data: v), error: nil)
completion(UIImage(data: v), nil)
}
}
}.resume()
......@@ -246,9 +246,9 @@ extension UIImage {
switch imageOrientation {
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:
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 {
......
......@@ -48,10 +48,7 @@ public class Material {
guard let v = view else {
return
}
if let preset: CornerRadiusPreset = cornerRadiusPreset {
v.cornerRadius = CornerRadiusPresetToValue(preset: preset)
}
v.cornerRadius = CornerRadiusPresetToValue(preset: cornerRadiusPreset)
}
}
......@@ -61,10 +58,7 @@ public class Material {
guard let v = view else {
return
}
if let preset: BorderWidthPreset = borderWidthPreset {
v.borderWidth = BorderWidthPresetToValue(preset: preset)
}
v.borderWidth = BorderWidthPresetToValue(preset: borderWidthPreset)
}
}
......
......@@ -48,7 +48,7 @@ public class MaterialTextLayer : CATextLayer {
*/
@IBInspectable public var text: String? {
didSet {
string = text as? AnyObject
string = text as Any
}
}
......@@ -171,7 +171,7 @@ public class MaterialTextLayer : CATextLayer {
/**
:name: init
*/
public override init(layer: AnyObject) {
public override init(layer: Any) {
super.init()
prepareLayer()
}
......@@ -196,12 +196,10 @@ public class MaterialTextLayer : CATextLayer {
:name: stringSize
*/
public func stringSize(constrainedToWidth width: Double) -> CGSize {
if let v = fontType {
if 0 < text?.utf16.count {
return v.stringSize(string: text!, constrainedToWidth: width)
}
}
return CGSize.zero
guard let v = fontType, let t = text, 0 < t.utf16.count else {
return CGSize.zero
}
return v.stringSize(string: text!, constrainedToWidth: width)
}
/**
......
......@@ -196,93 +196,92 @@ public class NavigationBar: UINavigationBar {
let titleView = prepareTitleView(item: item)
let contentView = prepareContentView(item: item)
if let g: Int = Int(width / gridFactor) {
let columns: Int = g + 1
let g = Int(width / gridFactor)
let columns = g + 1
titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize
titleView.grid.views = []
titleView.grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v: Array<UIControl> = item.leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(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
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
titleView.frame.origin = CGPoint.zero
titleView.frame.size = intrinsicContentSize
titleView.grid.views = []
titleView.grid.axis.columns = columns
contentView.grid.columns = columns
// leftControls
if let v: Array<UIControl> = item.leftControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(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
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
titleView.addSubview(contentView)
titleView.grid.views.append(contentView)
// rightControls
if let v: Array<UIControl> = item.rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(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
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
}
titleView.addSubview(contentView)
titleView.grid.views.append(contentView)
// rightControls
if let v: Array<UIControl> = item.rightControls {
for c in v {
let w: CGFloat = c.intrinsicContentSize.width
(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
contentView.grid.columns -= c.grid.columns
titleView.addSubview(c)
titleView.grid.views.append(c)
}
titleView.grid.contentEdgeInsets = contentInset
titleView.grid.interimSpace = interimSpace
titleView.grid.reload()
// contentView alignment.
if nil != item.title && "" != item.title {
if nil == item.titleLabel.superview {
contentView.addSubview(item.titleLabel)
}
item.titleLabel.frame = contentView.bounds
} else {
item.titleLabel.removeFromSuperview()
}
titleView.grid.contentEdgeInsets = contentInset
titleView.grid.interimSpace = interimSpace
titleView.grid.reload()
// contentView alignment.
if nil != item.title && "" != item.title {
if nil == item.titleLabel.superview {
contentView.addSubview(item.titleLabel)
}
item.titleLabel.frame = contentView.bounds
} 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.detailLabel.superview {
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
}
if nil == item.titleLabel.superview {
item.detailLabel.frame = contentView.bounds
} 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
}
contentView.grid.reload()
} else {
item.detailLabel.removeFromSuperview()
}
contentView.grid.reload()
}
}
......
......@@ -185,7 +185,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
A CGFloat property that sets the animation duration of the
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
......@@ -619,7 +619,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
showView(container: v)
isUserInteractionEnabled = false
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: {
v.position.x = v.width / 2
self.rootViewController.view.alpha = 0.5
......@@ -645,7 +645,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
showView(container: v)
isUserInteractionEnabled = false
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
if let s = self {
v.position.x = s.view.bounds.width - v.width / 2
......@@ -671,7 +671,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
if let v: View = leftView {
isUserInteractionEnabled = true
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
if let s = self {
v.position.x = -v.width / 2
......@@ -699,7 +699,7 @@ public class NavigationDrawerController: RootController, UIGestureRecognizerDele
if let v: View = rightView {
isUserInteractionEnabled = true
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
if let s = self {
v.position.x = s.view.bounds.width + v.width / 2
......
......@@ -170,10 +170,10 @@ public protocol PhotoLibraryDelegate {
@objc(PhotoLibrary)
public class PhotoLibrary: NSObject {
/// 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.
public private(set) lazy var fetchResultsDataSource = [String: PhotoLibraryFetchResultDataSource]()
public internal(set) lazy var fetchResultsDataSource = [String: PhotoLibraryFetchResultDataSource]()
/// A reference to a PhotoLibraryDelegate.
public weak var delegate: PhotoLibraryDelegate?
......@@ -252,8 +252,8 @@ extension PhotoLibrary {
- Parameter fetchResult: A PHFetchResult<T>.
- Parameter completion: A completion block.
*/
private func fetch<T: PHFetchResult<U>, U: PHObject>(caller: String, result: T, completion: ([U], T) -> Void) {
var objects = [U]()
internal func fetch<T: PHObject, U: PHFetchResult<T>>(caller: String, result: U, completion: (@escaping ([T], U) -> Void)? = nil) -> [T] {
var objects = [T]()
result.enumerateObjects({ (collection, _, _) in
objects.append(collection)
......@@ -263,12 +263,14 @@ extension PhotoLibrary {
fetchResultsDataSource[caller] = PhotoLibraryFetchResultDataSource(fetchResult: result as! PHFetchResult<PHObject>, objects: objects)
if Thread.isMainThread {
completion(objects, result)
completion?(objects, result)
} else {
DispatchQueue.main.async { [objects = objects, result = result, completion = completion] in
completion(objects, result)
completion?(objects, result)
}
}
return objects
}
}
......@@ -283,8 +285,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchCollectionListsContaining(_ collection: PHCollection, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchCollectionListsContaining(collection, options: options), completion: completion)
public func fetchCollectionListsContaining(_ collection: PHCollection, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchCollectionListsContaining(collection, options: options), completion: completion)
}
/**
......@@ -294,8 +296,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchCollectionList(with type: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: type, subtype: subtype, options: options), completion: completion)
public func fetchCollectionList(with type: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: type, subtype: subtype, options: options), completion: completion)
}
/**
......@@ -307,8 +309,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchCollectionLists(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(withLocalIdentifiers: identifiers, options: options), completion: completion)
public func fetchCollectionLists(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(withLocalIdentifiers: identifiers, options: options), completion: completion)
}
/**
......@@ -320,8 +322,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchCollectionLists(with collectionListType: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: collectionListType, subtype: subtype, options: options), completion: completion)
public func fetchCollectionLists(with collectionListType: PHCollectionListType, subtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchCollectionLists(with: collectionListType, subtype: subtype, options: options), completion: completion)
}
/**
......@@ -331,8 +333,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, containingMoment moment: PHAssetCollection, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, containingMoment: moment, options: options), completion: completion)
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, containingMoment moment: PHAssetCollection, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, containingMoment: moment, options: options), completion: completion)
}
/**
......@@ -341,8 +343,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void) {
fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, options: options), completion: completion)
public func fetchMomentLists(with momentListSubtype: PHCollectionListSubtype, options: PHFetchOptions?, completion: (@escaping ([PHCollectionList], PHFetchResult<PHCollectionList>) -> Void)? = nil) -> [PHCollectionList] {
return fetch(caller: #function, result: PHCollectionList.fetchMomentLists(with: momentListSubtype, options: options), completion: completion)
}
}
......@@ -354,8 +356,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchCollections(in collectionList: PHCollectionList, options: PHFetchOptions?, completion: ([PHCollection], PHFetchResult<PHCollection>) -> Void) {
fetch(caller: #function, result: PHCollection.fetchCollections(in: collectionList, options: options), completion: completion)
public func fetchCollections(in collectionList: PHCollectionList, options: PHFetchOptions?, completion: (@escaping ([PHCollection], PHFetchResult<PHCollection>) -> Void)? = nil) -> [PHCollection] {
return fetch(caller: #function, result: PHCollection.fetchCollections(in: collectionList, options: options), completion: completion)
}
/**
......@@ -365,8 +367,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion callback.
*/
public func fetchTopLevelUserCollections(with options: PHFetchOptions?, completion: ([PHCollection], PHFetchResult<PHCollection>) -> Void) {
fetch(caller: #function, result: PHCollection.fetchTopLevelUserCollections(with: nil), completion: completion)
public func fetchTopLevelUserCollections(with options: PHFetchOptions?, completion: (@escaping ([PHCollection], PHFetchResult<PHCollection>) -> Void)? = nil) -> [PHCollection] {
return fetch(caller: #function, result: PHCollection.fetchTopLevelUserCollections(with: nil), completion: completion)
}
}
......@@ -379,8 +381,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssetCollections(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: identifiers, options: options), completion: completion)
public func fetchAssetCollections(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withLocalIdentifiers: identifiers, options: options), completion: completion)
}
/**
......@@ -391,8 +393,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssetCollections(with type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(with: type, subtype: subtype, options: options), completion: completion)
public func fetchAssetCollections(with type: PHAssetCollectionType, subtype: PHAssetCollectionSubtype, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(with: type, subtype: subtype, options: options), completion: completion)
}
/**
......@@ -402,8 +404,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssetCollectionsContaining(_ asset: PHAsset, with type: PHAssetCollectionType, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollectionsContaining(asset, with: type, options: options), completion: completion)
public func fetchAssetCollectionsContaining(_ asset: PHAsset, with type: PHAssetCollectionType, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollectionsContaining(asset, with: type, options: options), completion: completion)
}
/**
......@@ -414,8 +416,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssetCollections(withALAssetGroupURLs assetGroupURLs: [URL], options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withALAssetGroupURLs: assetGroupURLs, options: options), completion: completion)
public func fetchAssetCollections(withALAssetGroupURLs assetGroupURLs: [URL], options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchAssetCollections(withALAssetGroupURLs: assetGroupURLs, options: options), completion: completion)
}
/**
......@@ -424,8 +426,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchMoments(inMomentList momentList: PHCollectionList, options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchMoments(inMomentList: momentList, options: options), completion: completion)
public func fetchMoments(inMomentList momentList: PHCollectionList, options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchMoments(inMomentList: momentList, options: options), completion: completion)
}
/**
......@@ -433,8 +435,8 @@ extension PhotoLibrary {
- Parameter with options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchMoments(with options: PHFetchOptions?, completion: ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void) {
fetch(caller: #function, result: PHAssetCollection.fetchMoments(with: options), completion: completion)
public func fetchMoments(with options: PHFetchOptions?, completion: (@escaping ([PHAssetCollection], PHFetchResult<PHAssetCollection>) -> Void)? = nil) -> [PHAssetCollection] {
return fetch(caller: #function, result: PHAssetCollection.fetchMoments(with: options), completion: completion)
}
}
......@@ -446,8 +448,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(in: assetCollection, options: options), completion: completion)
public func fetchAssets(in assetCollection: PHAssetCollection, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(in: assetCollection, options: options), completion: completion)
}
/**
......@@ -457,8 +459,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: options), completion: completion)
public func fetchAssets(withLocalIdentifiers identifiers: [String], options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(withLocalIdentifiers: identifiers, options: options), completion: completion)
}
/**
......@@ -468,11 +470,11 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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 {
return nil
}
fetch(caller: #function, result: fetchResult, completion: completion)
let _: [PHAsset] = fetch(caller: #function, result: fetchResult, completion: completion)
return fetchResult
}
......@@ -483,8 +485,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(withBurstIdentifier burstIdentifier: String, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(withBurstIdentifier: burstIdentifier, options: options), completion: completion)
public func fetchAssets(withBurstIdentifier burstIdentifier: String, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(withBurstIdentifier: burstIdentifier, options: options), completion: completion)
}
/**
......@@ -493,8 +495,8 @@ extension PhotoLibrary {
- Parameter with options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(with options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(with: options), completion: completion)
public func fetchAssets(with options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(with: options), completion: completion)
}
/**
......@@ -503,8 +505,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(with mediaType: PHAssetMediaType, options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(with: mediaType, options: options), completion: completion)
public func fetchAssets(with mediaType: PHAssetMediaType, options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(with: mediaType, options: options), completion: completion)
}
/**
......@@ -514,8 +516,8 @@ extension PhotoLibrary {
- Parameter options: An optional PHFetchOptions object.
- Parameter completion: A completion block.
*/
public func fetchAssets(withALAssetURLs assetURLs: [URL], options: PHFetchOptions?, completion: ([PHAsset], PHFetchResult<PHAsset>) -> Void) {
fetch(caller: #function, result: PHAsset.fetchAssets(withALAssetURLs: assetURLs, options: options), completion: completion)
public func fetchAssets(withALAssetURLs assetURLs: [URL], options: PHFetchOptions?, completion: (@escaping ([PHAsset], PHFetchResult<PHAsset>) -> Void)? = nil) -> [PHAsset] {
return fetch(caller: #function, result: PHAsset.fetchAssets(withALAssetURLs: assetURLs, options: options), completion: completion)
}
}
......@@ -531,7 +533,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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)
}
......@@ -542,7 +544,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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)
}
......@@ -570,7 +572,7 @@ extension PhotoLibrary {
- Returns: A PHImageRequestID.
*/
@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)
}
......@@ -581,7 +583,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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)
}
......@@ -592,7 +594,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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)
}
......@@ -603,7 +605,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block.
- 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)
}
}
......@@ -640,7 +642,7 @@ extension PhotoLibrary: PHPhotoLibraryChangeObserver {
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)
dataSource.fetchResult = details.fetchResultAfterChanges
......@@ -689,7 +691,7 @@ extension PhotoLibrary {
- Parameter completion: A completion block that is executed once the
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)
}
}
......@@ -315,7 +315,7 @@ public class Switch: UIControl {
Toggle the Switch state, if On will be Off, and if Off will be On.
- 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)
}
......@@ -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 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)
}
......@@ -334,14 +334,14 @@ public class Switch: UIControl {
- Parameter animated: A Boolean indicating to set the animation or not.
- 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 {
internalSwitchState = state
if animated {
animateToState(state: state) { [weak self] _ in
if let s: Switch = self {
s.sendActions(for: .valueChanged)
completion?(control: s)
completion?(s)
s.delegate?.switchStateChanged(control: s)
}
}
......@@ -349,7 +349,7 @@ public class Switch: UIControl {
button.x = .on == state ? self.onPosition : self.offPosition
styleForState(state: state)
sendActions(for: .valueChanged)
completion?(control: self)
completion?(self)
delegate?.switchStateChanged(control: self)
}
}
......@@ -508,7 +508,7 @@ public class Switch: UIControl {
- Parameter state: The SwitchState to set.
- 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
UIView.animate(withDuration: 0.15,
delay: 0.05,
......@@ -527,7 +527,7 @@ public class Switch: UIControl {
}) { [weak self] _ in
if let s: Switch = self {
s.isUserInteractionEnabled = true
completion?(control: s)
completion?(s)
}
}
}
......
......@@ -53,15 +53,15 @@ public class TabBar: View {
}
/// Buttons.
public var buttons: Array<UIButton>? {
public var buttons: [UIButton]? {
didSet {
if let v: Array<UIButton> = oldValue {
if let v: [UIButton] = oldValue {
for b in v {
b.removeFromSuperview()
}
}
if let v: Array<UIButton> = buttons {
if let v: [UIButton] = buttons {
for b in v {
addSubview(b)
}
......@@ -73,7 +73,7 @@ public class TabBar: View {
public override func layoutSubviews() {
super.layoutSubviews()
if willRenderView {
if let v: Array<UIButton> = buttons {
if let v: [UIButton] = buttons {
if 0 < v.count {
let columns: Int = grid.axis.columns / v.count
for b in v {
......
......@@ -85,7 +85,7 @@ public class TextStorage: NSTextStorage {
If you don't need this value, pass NULL.
- 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)
}
......@@ -106,7 +106,7 @@ public class TextStorage: NSTextStorage {
- Parameter range: A range of characters that will have their
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)
edited(NSTextStorageEditActions.editedAttributes, range: range, changeInLength: 0)
}
......
......@@ -181,21 +181,32 @@ public class TextView: UITextView {
p.isHidden = !(true == text?.isEmpty)
}
if 0 < text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
guard let t = text else {
hideTitleLabel()
return
}
if 0 < t.utf16.count {
showTitleLabel()
} else {
hideTitleLabel()
}
}
/// Notification handler for when text editing ended.
internal func handleTextViewTextDidEnd() {
if 0 < text?.utf16.count {
showTitleLabel()
} else if 0 == text?.utf16.count {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelColor
guard let t = text else {
hideTitleLabel()
return
}
if 0 < t.utf16.count {
showTitleLabel()
} else {
hideTitleLabel()
}
titleLabel?.textColor = titleLabelColor
}
/**
......@@ -233,11 +244,13 @@ public class TextView: UITextView {
if let v: UILabel = titleLabel {
v.isHidden = true
addSubview(v)
if 0 < text?.utf16.count {
showTitleLabel()
} else {
v.alpha = 0
}
guard let t = text, 0 == t.utf16.count else {
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