Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Swift 5.0 #53

Merged
merged 2 commits into from
Apr 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# * http://www.objc.io/issue-6/travis-ci.html
# * https://github.com/supermarin/xcpretty#usage

osx_image: xcode10.1
osx_image: xcode10.2
language: swift
env:
global:
Expand Down
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

##### Enhancements

* None.
* Migrate to Swift 5.0.
[Earl Gaspard](https://github.com/earlgaspard)
[#53](https://github.com/BottleRocketStudios/iOS-UtiliKit/pull/53)

##### Bug Fixes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public extension ContainerViewController {

//MARK: Finding a ManagedChild
func index(ofChild controller: UIViewController) -> Int? {
return managedChildren.index(where: { $0.viewController === controller })
return managedChildren.firstIndex(where: { $0.viewController === controller })
}

func indexOfChild(following viewController: UIViewController) -> Int? {
Expand All @@ -31,7 +31,7 @@ public extension ContainerViewController {

// MARK: Removing a ManagedChild
func removeChild(_ child: ManagedChild) {
let removed = managedChildren.index { $0.identifier == child.identifier }.flatMap { managedChildren.remove(at: $0) }
let removed = managedChildren.firstIndex { $0.identifier == child.identifier }.flatMap { managedChildren.remove(at: $0) }
#if swift(>=4.2)
removed?.viewController.removeFromParent()
#else
Expand Down
8 changes: 4 additions & 4 deletions Sources/UtiliKit/General/FileManager+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
public extension FileManager {

/// The URL for the documents directory.
public var documentsDirectory: URL {
var documentsDirectory: URL {
guard let documentDirectory = urls(for: .documentDirectory, in: .userDomainMask).first else {
fatalError("Could not locate Documents Directory.")
}
Expand All @@ -18,7 +18,7 @@ public extension FileManager {
}

/// The URL for the chaches directory.
public var cachesDirectory: URL {
var cachesDirectory: URL {
guard let cachesDirectory = urls(for: .cachesDirectory, in: .userDomainMask).first else {
fatalError("Could not locate Caches Directory.")
}
Expand All @@ -27,7 +27,7 @@ public extension FileManager {
}

/// The URL for the application support directory.
public var applicationSupportDirectory: URL {
var applicationSupportDirectory: URL {
guard let applicationSupportDirectory = urls(for: .applicationSupportDirectory, in: .userDomainMask).first else {
fatalError("Could not locate Application Support Directory.")
}
Expand All @@ -41,7 +41,7 @@ public extension FileManager {
- Parameter groupIdentifier: The group identifier for the app group.
- Returns: The URL for the shared container.
*/
public func sharedContainerURL(forSecurityApplicationGroupIdentifier groupIdentifier: String) -> URL {
func sharedContainerURL(forSecurityApplicationGroupIdentifier groupIdentifier: String) -> URL {
guard let sharedContainerURL = containerURL(forSecurityApplicationGroupIdentifier: groupIdentifier) else {
fatalError("Could not locate Shared Container URL.")
}
Expand Down
8 changes: 4 additions & 4 deletions Sources/UtiliKit/General/UIView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public extension UIView {
- Parameter isUsingSafeArea: A Bool value used to determine the use of safeAreaLayoutGuides or superview anchors
*/
@available(iOS 11, *)
public func addSubview(_ subview: UIView, constrainedToSuperview: Bool, usingSafeArea isUsingSafeArea: Bool) {
func addSubview(_ subview: UIView, constrainedToSuperview: Bool, usingSafeArea isUsingSafeArea: Bool) {
guard constrainedToSuperview else {
addSubview(subview)
return
Expand All @@ -35,7 +35,7 @@ public extension UIView {
- Parameter subview: The subview to add.
- Parameter constrainedToSuperview: Whether or not you want the edges to be automatically constrained to the superview. If 'true', then 'translatesAutoresizingMaskIntoConstraints' will automatically be set to false for the given subview.
*/
public func addSubview(_ subview: UIView, constrainedToSuperview: Bool) {
func addSubview(_ subview: UIView, constrainedToSuperview: Bool) {
guard constrainedToSuperview else {
addSubview(subview)
return
Expand All @@ -54,7 +54,7 @@ public extension UIView {
- Parameter isUsingSafeArea: A Bool value used to determine the use of safeAreaLayoutGuides or superview anchors
*/
@available(iOS 11, *)
public func constrainEdgesToSuperview(with insets: UIEdgeInsets = .zero, usingSafeArea isUsingSafeArea: Bool) {
func constrainEdgesToSuperview(with insets: UIEdgeInsets = .zero, usingSafeArea isUsingSafeArea: Bool) {
guard let superview = superview else { return }

if isUsingSafeArea {
Expand All @@ -72,7 +72,7 @@ public extension UIView {

- Parameter insets: Defaults to UIEdgeInsets.zero, this parameter is used for the constant value of the constraints
*/
public func constrainEdgesToSuperview(with insets: UIEdgeInsets = .zero) {
func constrainEdgesToSuperview(with insets: UIEdgeInsets = .zero) {
guard let superview = superview else { return }

superview.addConstraints([leadingAnchor.constraint(equalTo: superview.leadingAnchor, constant: insets.left),
Expand Down
6 changes: 3 additions & 3 deletions Sources/UtiliKit/Instantiation/MKMapView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public extension MKMapView {
- Parameter type: The type of the view being registered
*/
@available(iOS 11.0, *)
public func register<T: MKAnnotationView>(_ type: T.Type) {
func register<T: MKAnnotationView>(_ type: T.Type) {
register(type, forAnnotationViewWithReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -28,7 +28,7 @@ public extension MKMapView {
- Returns: An annotation view of type T.
*/
@available(iOS 11.0, *)
public func dequeueReusableAnnotationView<T: MKAnnotationView>(for annotation: MKAnnotation) -> T {
func dequeueReusableAnnotationView<T: MKAnnotationView>(for annotation: MKAnnotation) -> T {
guard let annotationView = dequeueReusableAnnotationView(withIdentifier: T.reuseIdentifier, for: annotation) as? T else {
fatalError("Could not dequeue a reusable annotation of type \(T.self) with identifier \(T.reuseIdentifier) for use in \(self)")
}
Expand All @@ -42,7 +42,7 @@ public extension MKMapView {
- Parameter type: The type of the cell being registered. This should match the reuse identifier on the nib.
- Returns: Either a reusable annotation view of type T or a new instance of it.
*/
public func dequeueReusableAnnotationView<T: MKAnnotationView>() -> T {
func dequeueReusableAnnotationView<T: MKAnnotationView>() -> T {
let annotationView: MKAnnotationView? = dequeueReusableAnnotationView(withIdentifier: T.reuseIdentifier)

if let annotationView = annotationView {
Expand Down
18 changes: 9 additions & 9 deletions Sources/UtiliKit/Instantiation/UICollectionView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
public extension UICollectionView {

/// Enum defining UICollectionElementKind
public enum SupplementaryElementKind {
enum SupplementaryElementKind {
case sectionHeader
case sectionFooter

Expand Down Expand Up @@ -62,7 +62,7 @@ public extension UICollectionView {

- Parameter type: The type of the cell being registered.
*/
public func register<T: UICollectionViewCell>(_ type: T.Type) {
func register<T: UICollectionViewCell>(_ type: T.Type) {
register(type, forCellWithReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -71,7 +71,7 @@ public extension UICollectionView {

- Parameter type: The class of the nib being registered. This should match its reuse identifier.
*/
public func registerNib<T: UICollectionViewCell>(for type: T.Type) {
func registerNib<T: UICollectionViewCell>(for type: T.Type) {
register(UINib(nibName: T.nibName, bundle: Bundle(for: type)), forCellWithReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -80,7 +80,7 @@ public extension UICollectionView {

- Parameter type: The type of the view being registered.
*/
public func registerHeaderFooter<T: UICollectionReusableView>(_ type: T.Type) {
func registerHeaderFooter<T: UICollectionReusableView>(_ type: T.Type) {
register(type, forSupplementaryViewOfKind: .sectionHeader)
register(type, forSupplementaryViewOfKind: .sectionFooter)
}
Expand All @@ -91,7 +91,7 @@ public extension UICollectionView {
- Parameter type: The type of the view being registered.
- Parameter kind: The kind of supplementary view to make.
*/
public func register<T: UICollectionReusableView>(_ type: T.Type, forSupplementaryViewOfKind kind: SupplementaryElementKind) {
func register<T: UICollectionReusableView>(_ type: T.Type, forSupplementaryViewOfKind kind: SupplementaryElementKind) {
register(type, forSupplementaryViewOfKind: kind.type, withReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -100,7 +100,7 @@ public extension UICollectionView {

- Parameter type: The type of the view being registered.
*/
public func registerNib<T: UICollectionReusableView>(forHeaderFooterView type: T.Type) {
func registerNib<T: UICollectionReusableView>(forHeaderFooterView type: T.Type) {
registerNib(forHeaderFooterView: type, forSupplementaryViewOfKind: .sectionHeader)
registerNib(forHeaderFooterView: type, forSupplementaryViewOfKind: .sectionFooter)
}
Expand All @@ -111,7 +111,7 @@ public extension UICollectionView {
- Parameter type: The type of the view being registered.
- Parameter kind: The kind of supplementary view to make.
*/
public func registerNib<T: UICollectionReusableView>(forHeaderFooterView type: T.Type, forSupplementaryViewOfKind kind: SupplementaryElementKind) {
func registerNib<T: UICollectionReusableView>(forHeaderFooterView type: T.Type, forSupplementaryViewOfKind kind: SupplementaryElementKind) {
register(UINib(nibName: T.nibName, bundle: Bundle(for: type)), forSupplementaryViewOfKind: kind.type, withReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -122,7 +122,7 @@ public extension UICollectionView {
- Parameter indexPath: The index path of the cell.
- Returns: A collection view cell of type T.
*/
public func dequeueReusableCell<T: UICollectionViewCell>(for indexPath: IndexPath) -> T {
func dequeueReusableCell<T: UICollectionViewCell>(for indexPath: IndexPath) -> T {
guard let reusableCell = dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
fatalError("Could not dequeue a reusable cell of type \(T.self) with identifier \(T.reuseIdentifier) for use in \(self)")
}
Expand All @@ -137,7 +137,7 @@ public extension UICollectionView {
- Parameter indexPath: The index path of the cell.
- Returns: A collection view cell of type T.
*/
public func dequeueReusableSupplementaryView<T: UICollectionReusableView>(of kind: SupplementaryElementKind, for indexPath: IndexPath) -> T {
func dequeueReusableSupplementaryView<T: UICollectionReusableView>(of kind: SupplementaryElementKind, for indexPath: IndexPath) -> T {
guard let reusableView = dequeueReusableSupplementaryView(ofKind: kind.type, withReuseIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
fatalError("Could not dequeue a reusable supplementary view of type \(T.self) with identifier \(T.reuseIdentifier) for use in \(self)")
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/UtiliKit/Instantiation/UIStoryboard+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import UIKit
public extension UIStoryboard {

/// A small struct used to represent the name and bundle of a storyboad object.
public struct Identifier {
struct Identifier {
public let name: String
public let bundle: Bundle

Expand Down Expand Up @@ -40,7 +40,7 @@ public extension UIStoryboard {

- Returns: A view controller of type T.
*/
public func instantiateInitialViewController<T: UIViewController>() -> T {
func instantiateInitialViewController<T: UIViewController>() -> T {
guard let vc = instantiateInitialViewController() as? T else {
fatalError("Unable to instantiate the initial view controller as \(T.self) from storyboard \(self)")
}
Expand All @@ -54,7 +54,7 @@ public extension UIStoryboard {
- Parameter element: An element of the appropriate type, used to configure the view controller.
- Returns: A view controller of type T.
*/
public func instantiateInitialViewController<T: UIViewController & Configurable>(configuredWith element: T.ConfiguringType) -> T {
func instantiateInitialViewController<T: UIViewController & Configurable>(configuredWith element: T.ConfiguringType) -> T {
let vc: T = instantiateInitialViewController()
vc.configure(with: element)

Expand All @@ -66,7 +66,7 @@ public extension UIStoryboard {

- Returns: A view controller of type T.
*/
public func instantiateViewController<T: UIViewController>() -> T {
func instantiateViewController<T: UIViewController>() -> T {
guard let vc = instantiateViewController(withIdentifier: T.storyboardIdentifier) as? T else {
fatalError("Unable to instantiate a view controller with identifier \(T.storyboardIdentifier) from storyboard \(self)")
}
Expand All @@ -80,7 +80,7 @@ public extension UIStoryboard {
- Parameter element: An element of the appropriate type, used to configure the view controller.
- Returns: A view controller of type T.
*/
public func instantiateViewController<T: UIViewController & Configurable>(configuredWith element: T.ConfiguringType) -> T {
func instantiateViewController<T: UIViewController & Configurable>(configuredWith element: T.ConfiguringType) -> T {
let vc: T = instantiateViewController()
vc.configure(with: element)

Expand Down
12 changes: 6 additions & 6 deletions Sources/UtiliKit/Instantiation/UITableView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public extension UITableView {

- Parameter type: The type of the cell being registered.
*/
public func register<T: UITableViewCell>(type: T.Type) {
func register<T: UITableViewCell>(type: T.Type) {
register(type, forCellReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -24,7 +24,7 @@ public extension UITableView {

- Parameter type: The class of the nib being registered. This should match its reuse identifier.
*/
public func registerNib<T: UITableViewCell>(for type: T.Type) {
func registerNib<T: UITableViewCell>(for type: T.Type) {
register(UINib(nibName: T.nibName, bundle: Bundle(for: type)), forCellReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -33,7 +33,7 @@ public extension UITableView {

- Parameter type: The type of the class being registered.
*/
public func registerHeaderFooter<T: UITableViewHeaderFooterView>(type: T.Type) {
func registerHeaderFooter<T: UITableViewHeaderFooterView>(type: T.Type) {
register(type, forHeaderFooterViewReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -42,7 +42,7 @@ public extension UITableView {

- Parameter type: The class of the nib being registered. This should match its reuse identifier.
*/
public func registerNib<T: UITableViewHeaderFooterView>(forHeaderFooterView type: T.Type) {
func registerNib<T: UITableViewHeaderFooterView>(forHeaderFooterView type: T.Type) {
register(UINib(nibName: T.nibName, bundle: Bundle(for: type)), forHeaderFooterViewReuseIdentifier: T.reuseIdentifier)
}

Expand All @@ -53,7 +53,7 @@ public extension UITableView {
- Parameter indexPath: The index path of the cell.
- Returns: A table view cell of type T.
*/
public func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T {
func dequeueReusableCell<T: UITableViewCell>(for indexPath: IndexPath) -> T {
guard let reusableCell = dequeueReusableCell(withIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
fatalError("Could not dequeue a reusable cell of type \(T.self) with identifier \(T.reuseIdentifier) for use in \(self)")
}
Expand All @@ -66,7 +66,7 @@ public extension UITableView {

- Returns: A headerFooter view of type T.
*/
public func dequeueReusableHeaderFooterView<T: UITableViewHeaderFooterView>() -> T {
func dequeueReusableHeaderFooterView<T: UITableViewHeaderFooterView>() -> T {
guard let reusableView = dequeueReusableHeaderFooterView(withIdentifier: T.reuseIdentifier) as? T else {
fatalError("Could not dequeue a reusable view of type \(T.self) with identifier \(T.reuseIdentifier) for use in \(self)")
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/UtiliKit/TimelessDate/Date+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import Foundation
public extension Date {

/// Current date and time.
public static var now: Date { return Date() }
static var now: Date { return Date() }

/// Date and time of Midnight January 1, 2001.
public static var reference2001: Date { return Date(timeIntervalSinceReferenceDate: 0) }
static var reference2001: Date { return Date(timeIntervalSinceReferenceDate: 0) }

/// Date and time of Midnight January 1, 1970.
public static var reference1970: Date { return Date(timeIntervalSince1970: 0) }
static var reference1970: Date { return Date(timeIntervalSince1970: 0) }

/**
Creates a Date initialized relative to another given date by a given number of days, hours, minutes, and seconds.
Expand All @@ -29,7 +29,7 @@ public extension Date {
- Parameter seconds: The number of seconds to be added.
- Parameter date: The reference Date
*/
public init?(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0, since date: Date) {
init?(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0, since date: Date) {
var components = DateComponents()
components.day = days
components.hour = hours
Expand All @@ -49,7 +49,7 @@ public extension Date {
- Parameter seconds: The number of seconds to be added.
- Returns: An optional Date with the given values added to it.
*/
public func adding(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? {
func adding(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? {
return Date(days: days, hours: hours, minutes: minutes, seconds: seconds, since: self)
}

Expand All @@ -62,7 +62,7 @@ public extension Date {
- Parameter seconds: The number of seconds to be subtracted.
- Returns: An optional Date with the given values subtracted to it.
*/
public func subtracting(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? {
func subtracting(days: Int = 0, hours: Int = 0, minutes: Int = 0, seconds: Int = 0) -> Date? {
return Date(days: -days, hours: -hours, minutes: -minutes, seconds: -seconds, since: self)
}
}
4 changes: 2 additions & 2 deletions Sources/UtiliKit/TimelessDate/TimelessDate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ public struct TimelessDate: Comparable, Equatable, Hashable {

// MARK: Hashable

public var hashValue: Int {
return date.hashValue
public func hash(into hasher: inout Hasher) {
hasher.combine(date.hashValue)
}

// MARK: Math
Expand Down
Loading