Skip to content

Commit

Permalink
Swift 4.2 support (#58)
Browse files Browse the repository at this point in the history
* Add support for Swift 4.2 (keep compatible with older versions)

* Changelog entry

* Ensure the example code compiles in Swift 4.2

* Address SwiftLint warnings

* Migrate tvOS Target to 4.2 too

* Fix compilation issue with NSLayoutConstraint.Attribute

* addConstraint is deprecated ==> NSLayoutConstraint.activate

* Update to Xcode 10 recommended settings

* Fix SwiftLint violations.
  • Loading branch information
djbe authored and AliSoftware committed Jul 12, 2018
1 parent a738240 commit 223c205
Show file tree
Hide file tree
Showing 18 changed files with 109 additions and 64 deletions.
3 changes: 0 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
disabled_rules:
- missing_docs

line_length:
warning: 120
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# CHANGELOG

## Master

* Update project to support Swift 4.2.
[djbe](https://github.com/djbe)
[#58](https://github.com/AliSoftware/Reusable/pull/58)

## 4.0.2

* Update project to support Swift 4.
[@AYastrebov](https://github.com/AYastrebov)
[#42](https://github.com/AliSoftware/Reusable/pull/54)
[#54](https://github.com/AliSoftware/Reusable/pull/54)

* Fix typo in StoryboardBased examples.
[@danshevluk](https://github.com/danshevluk)
Expand Down
5 changes: 2 additions & 3 deletions Example/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
opt_in_rules:
- empty_count
- missing_docs

included:
- ../Sources
- ReusableDemo

line_length:
warning: 160
error: 200
warning: 120
error: 160

32 changes: 20 additions & 12 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion Example/ReusableDemo iOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}

/// Swift < 4.2 support
#if !(swift(>=4.2))
extension UIApplication {
typealias LaunchOptionsKey = UIApplicationLaunchOptionsKey
}
#endif
9 changes: 8 additions & 1 deletion Example/ReusableDemo iOS/CollectionViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class CollectionViewController: UICollectionViewController {
// self.collectionView.registerReusableCell(MyStoryBoardIndexPathCell)

collectionView.register(supplementaryViewType: CollectionHeaderView.self,
ofKind: UICollectionElementKindSectionHeader)
ofKind: UICollectionView.elementKindSectionHeader)

if let flowLayout = self.collectionView?.collectionViewLayout as? UICollectionViewFlowLayout {
flowLayout.headerReferenceSize = CGSize(width: collectionView.bounds.size.width, height: 60)
Expand Down Expand Up @@ -67,3 +67,10 @@ final class CollectionViewController: UICollectionViewController {
}
}
}

/// Swift < 4.2 support
#if !(swift(>=4.2))
private extension UICollectionView {
static let elementKindSectionHeader = UICollectionElementKindSectionHeader
}
#endif
7 changes: 6 additions & 1 deletion Example/ReusableDemo iOS/TableViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ final class TableViewController: UITableViewController {
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let frame = CGRect(x: 0, y: 0, width: tableView.bounds.size.width, height: self.tableView(tableView, heightForHeaderInSection: section))
let frame = CGRect(
x: 0,
y: 0,
width: tableView.bounds.size.width,
height: self.tableView(tableView, heightForHeaderInSection: section)
)
// See the overridden `MyHeaderTableView.init(frame:)` initializer, which
// automatically loads the view content from its nib using loadNibContent()
let view = MyHeaderTableView(frame: frame)
Expand Down
9 changes: 8 additions & 1 deletion Example/ReusableDemo tvOS/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
return true
}
}

/// Swift < 4.2 support
#if !(swift(>=4.2))
extension UIApplication {
typealias LaunchOptionsKey = UIApplicationLaunchOptionsKey
}
#endif
Loading

0 comments on commit 223c205

Please sign in to comment.