From 30e950edee45ca2350182242ab197d92efe1a3e6 Mon Sep 17 00:00:00 2001 From: "leo.wang" Date: Mon, 29 Apr 2019 16:41:58 +1000 Subject: [PATCH 1/2] Swift 5.0 --- Example.xcodeproj/project.pbxproj | 9 +++++++++ Example/AppDelegate.swift | 2 +- Example/CollectionViewController.swift | 2 +- Example/PlaceholderViews/BasicPlaceholderView.swift | 2 +- Example/PlaceholderViews/ErrorView.swift | 2 +- Example/PlaceholderViews/LoadingView.swift | 2 +- Example/TableViewController.swift | 2 +- Example/ViewController.swift | 2 +- 8 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 9fa81a5..737231a 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -357,6 +357,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -515,6 +516,7 @@ PRODUCT_NAME = StatefulViewController; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -539,6 +541,7 @@ PRODUCT_BUNDLE_IDENTIFIER = com.aschuch.StatefulViewController; PRODUCT_NAME = StatefulViewController; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = "1,2"; VERSIONING_SYSTEM = "apple-generic"; VERSION_INFO_PREFIX = ""; @@ -558,6 +561,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Debug; @@ -572,6 +576,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Release; @@ -671,6 +676,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Debug; }; @@ -682,6 +688,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; }; name = Release; }; @@ -703,6 +710,7 @@ PRODUCT_NAME = StatefulViewController; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; @@ -729,6 +737,7 @@ PRODUCT_NAME = StatefulViewController; SDKROOT = appletvos; SKIP_INSTALL = YES; + SWIFT_VERSION = 5.0; TARGETED_DEVICE_FAMILY = 3; TVOS_DEPLOYMENT_TARGET = 9.0; VERSIONING_SYSTEM = "apple-generic"; diff --git a/Example/AppDelegate.swift b/Example/AppDelegate.swift index f1eb6df..9320d87 100644 --- a/Example/AppDelegate.swift +++ b/Example/AppDelegate.swift @@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]? = nil) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool { // Override point for customization after application launch. return true } diff --git a/Example/CollectionViewController.swift b/Example/CollectionViewController.swift index fd85a51..c83a76d 100644 --- a/Example/CollectionViewController.swift +++ b/Example/CollectionViewController.swift @@ -36,7 +36,7 @@ class CollectionViewController: UICollectionViewController, StatefulViewControll refresh() } - func refresh() { + @objc func refresh() { if (lastState == .loading) { return } startLoading { diff --git a/Example/PlaceholderViews/BasicPlaceholderView.swift b/Example/PlaceholderViews/BasicPlaceholderView.swift index 1ec110d..e5c5440 100644 --- a/Example/PlaceholderViews/BasicPlaceholderView.swift +++ b/Example/PlaceholderViews/BasicPlaceholderView.swift @@ -33,7 +33,7 @@ class BasicPlaceholderView: UIView { let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "|-(>=20)-[centerView]-(>=20)-|", options: .alignAllCenterX, metrics: nil, views: ["centerView": centerView]) let hConstraint = NSLayoutConstraint(item: centerView, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0.0) let centerConstraint = NSLayoutConstraint(item: centerView, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0.0) - centerConstraint.priority = 750 + centerConstraint.priority = UILayoutPriority(rawValue: 750) addConstraints(vConstraints) addConstraint(hConstraint) diff --git a/Example/PlaceholderViews/ErrorView.swift b/Example/PlaceholderViews/ErrorView.swift index 3ac5a6e..7392cb3 100644 --- a/Example/PlaceholderViews/ErrorView.swift +++ b/Example/PlaceholderViews/ErrorView.swift @@ -30,7 +30,7 @@ class ErrorView: BasicPlaceholderView { detailTextLabel.text = "Tap to reload" detailTextLabel.numberOfLines = 0 detailTextLabel.textAlignment = .center - let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFontTextStyle.footnote) + let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: .footnote) detailTextLabel.font = UIFont(descriptor: fontDescriptor, size: 0) detailTextLabel.textAlignment = .center detailTextLabel.textColor = UIColor.gray diff --git a/Example/PlaceholderViews/LoadingView.swift b/Example/PlaceholderViews/LoadingView.swift index 705502c..94de137 100644 --- a/Example/PlaceholderViews/LoadingView.swift +++ b/Example/PlaceholderViews/LoadingView.swift @@ -20,7 +20,7 @@ class LoadingView: BasicPlaceholderView, StatefulPlaceholderView { label.translatesAutoresizingMaskIntoConstraints = false centerView.addSubview(label) - let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray) + let activityIndicator = UIActivityIndicatorView(style: .gray) activityIndicator.startAnimating() activityIndicator.translatesAutoresizingMaskIntoConstraints = false centerView.addSubview(activityIndicator) diff --git a/Example/TableViewController.swift b/Example/TableViewController.swift index 2f46c43..d47870a 100644 --- a/Example/TableViewController.swift +++ b/Example/TableViewController.swift @@ -34,7 +34,7 @@ class TableViewController: UITableViewController, StatefulViewController { refresh() } - func refresh() { + @objc func refresh() { if (lastState == .loading) { return } startLoading { diff --git a/Example/ViewController.swift b/Example/ViewController.swift index bfc7bf3..4bd7f74 100644 --- a/Example/ViewController.swift +++ b/Example/ViewController.swift @@ -36,7 +36,7 @@ class ViewController: UIViewController, StatefulViewController { refresh() } - func refresh() { + @objc func refresh() { if (lastState == .loading) { return } startLoading { From 1855f349367f44d06de528e975c12efb0c978bcc Mon Sep 17 00:00:00 2001 From: Eduardo Miranda Date: Wed, 11 Nov 2020 11:25:25 +0100 Subject: [PATCH 2/2] SPM Support --- Example.xcodeproj/project.pbxproj | 32 ++++++++++++++----- Package.swift | 31 ++++++++++++++++++ .../StatefulViewController}/Info.plist | 0 .../StatefulPlaceholderView.swift | 2 ++ .../StatefulViewController.h | 4 ++- .../StatefulViewController.swift | 2 ++ ...StatefulViewControllerImplementation.swift | 3 +- .../ViewStateMachine.swift | 3 +- .../StatefulViewControllerTests}/Info.plist | 0 .../StatefulViewControllerTests.swift | 2 ++ 10 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 Package.swift rename {StatefulViewController => Sources/StatefulViewController}/Info.plist (100%) rename {StatefulViewController => Sources/StatefulViewController}/StatefulPlaceholderView.swift (95%) rename {StatefulViewController => Sources/StatefulViewController}/StatefulViewController.h (91%) rename {StatefulViewController => Sources/StatefulViewController}/StatefulViewController.swift (99%) rename {StatefulViewController => Sources/StatefulViewController}/StatefulViewControllerImplementation.swift (99%) rename {StatefulViewController => Sources/StatefulViewController}/ViewStateMachine.swift (99%) rename {StatefulViewControllerTests => Tests/StatefulViewControllerTests}/Info.plist (100%) rename {StatefulViewControllerTests => Tests/StatefulViewControllerTests}/StatefulViewControllerTests.swift (98%) diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 737231a..bb14823 100644 --- a/Example.xcodeproj/project.pbxproj +++ b/Example.xcodeproj/project.pbxproj @@ -174,9 +174,9 @@ 4DE62AD319B658610021630A = { isa = PBXGroup; children = ( + C70A7279255BEE580046EDE9 /* Sources */, + C70A727A255BEE6E0046EDE9 /* Tests */, 4DE62ADE19B658610021630A /* Example */, - 4D6451471A64079200108EA3 /* StatefulViewController */, - 4D6451561A64079300108EA3 /* StatefulViewControllerTests */, 4DE62ADD19B658610021630A /* Products */, ); sourceTree = ""; @@ -227,6 +227,22 @@ path = PlaceholderViews; sourceTree = ""; }; + C70A7279255BEE580046EDE9 /* Sources */ = { + isa = PBXGroup; + children = ( + 4D6451471A64079200108EA3 /* StatefulViewController */, + ); + path = Sources; + sourceTree = ""; + }; + C70A727A255BEE6E0046EDE9 /* Tests */ = { + isa = PBXGroup; + children = ( + 4D6451561A64079300108EA3 /* StatefulViewControllerTests */, + ); + path = Tests; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXHeadersBuildPhase section */ @@ -508,7 +524,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = StatefulViewController/Info.plist; + INFOPLIST_FILE = Sources/StatefulViewController/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -534,7 +550,7 @@ DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; - INFOPLIST_FILE = StatefulViewController/Info.plist; + INFOPLIST_FILE = Sources/StatefulViewController/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -556,7 +572,7 @@ "DEBUG=1", "$(inherited)", ); - INFOPLIST_FILE = StatefulViewControllerTests/Info.plist; + INFOPLIST_FILE = Tests/StatefulViewControllerTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; @@ -571,7 +587,7 @@ buildSettings = { COPY_PHASE_STRIP = NO; FRAMEWORK_SEARCH_PATHS = "$(inherited)"; - INFOPLIST_FILE = StatefulViewControllerTests/Info.plist; + INFOPLIST_FILE = Tests/StatefulViewControllerTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)"; @@ -703,7 +719,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/StatefulViewController/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources//StatefulViewController/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.aschuch.StatefulViewController; @@ -730,7 +746,7 @@ DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; GCC_NO_COMMON_BLOCKS = YES; - INFOPLIST_FILE = "$(SRCROOT)/StatefulViewController/Info.plist"; + INFOPLIST_FILE = "$(SRCROOT)/Sources//StatefulViewController/Info.plist"; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = com.aschuch.StatefulViewController; diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..9a59955 --- /dev/null +++ b/Package.swift @@ -0,0 +1,31 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "StatefulViewController", + platforms: [.iOS(.v9), .tvOS(.v9)], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "StatefulViewController", + targets: ["StatefulViewController"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "StatefulViewController", + dependencies: [], + exclude: ["Info.plist"]), + .testTarget( + name: "StatefulViewControllerTests", + dependencies: ["StatefulViewController"], + exclude: ["Info.plist"]), + ] +) diff --git a/StatefulViewController/Info.plist b/Sources/StatefulViewController/Info.plist similarity index 100% rename from StatefulViewController/Info.plist rename to Sources/StatefulViewController/Info.plist diff --git a/StatefulViewController/StatefulPlaceholderView.swift b/Sources/StatefulViewController/StatefulPlaceholderView.swift similarity index 95% rename from StatefulViewController/StatefulPlaceholderView.swift rename to Sources/StatefulViewController/StatefulPlaceholderView.swift index a1bf5b2..2bf3547 100644 --- a/StatefulViewController/StatefulPlaceholderView.swift +++ b/Sources/StatefulViewController/StatefulPlaceholderView.swift @@ -6,6 +6,7 @@ // Copyright © 2016 Alexander Schuch. All rights reserved. // +#if canImport(UIKit) import UIKit public protocol StatefulPlaceholderView { @@ -22,3 +23,4 @@ extension StatefulPlaceholderView { } } +#endif diff --git a/StatefulViewController/StatefulViewController.h b/Sources/StatefulViewController/StatefulViewController.h similarity index 91% rename from StatefulViewController/StatefulViewController.h rename to Sources/StatefulViewController/StatefulViewController.h index 53d9d25..73e17e5 100644 --- a/StatefulViewController/StatefulViewController.h +++ b/Sources/StatefulViewController/StatefulViewController.h @@ -6,7 +6,9 @@ // Copyright (c) 2015 Alexander Schuch. All rights reserved. // -#import +#if canImport(UIKit) + #import +#endif //! Project version number for StatefulViewController. FOUNDATION_EXPORT double StatefulViewControllerVersionNumber; diff --git a/StatefulViewController/StatefulViewController.swift b/Sources/StatefulViewController/StatefulViewController.swift similarity index 99% rename from StatefulViewController/StatefulViewController.swift rename to Sources/StatefulViewController/StatefulViewController.swift index ea43248..e195540 100644 --- a/StatefulViewController/StatefulViewController.swift +++ b/Sources/StatefulViewController/StatefulViewController.swift @@ -1,3 +1,4 @@ +#if canImport(UIKit) import UIKit /// Represents all possible states of a stateful view controller @@ -87,3 +88,4 @@ public protocol StatefulViewController: class, BackingViewProvider { /// - parameter error: The error that occurred func handleErrorWhenContentAvailable(_ error: Error) } +#endif diff --git a/StatefulViewController/StatefulViewControllerImplementation.swift b/Sources/StatefulViewController/StatefulViewControllerImplementation.swift similarity index 99% rename from StatefulViewController/StatefulViewControllerImplementation.swift rename to Sources/StatefulViewController/StatefulViewControllerImplementation.swift index 26b9b27..afab3ad 100644 --- a/StatefulViewController/StatefulViewControllerImplementation.swift +++ b/Sources/StatefulViewController/StatefulViewControllerImplementation.swift @@ -1,6 +1,6 @@ +#if canImport(UIKit) import UIKit - // MARK: Default Implementation BackingViewProvider extension BackingViewProvider where Self: UIViewController { @@ -133,3 +133,4 @@ private func associatedObject(_ host: AnyObject, key: UnsafeRawPoi } return value! } +#endif diff --git a/StatefulViewController/ViewStateMachine.swift b/Sources/StatefulViewController/ViewStateMachine.swift similarity index 99% rename from StatefulViewController/ViewStateMachine.swift rename to Sources/StatefulViewController/ViewStateMachine.swift index cd1dca9..86b897b 100644 --- a/StatefulViewController/ViewStateMachine.swift +++ b/Sources/StatefulViewController/ViewStateMachine.swift @@ -6,9 +6,9 @@ // Copyright (c) 2014 Alexander Schuch. All rights reserved. // +#if canImport(UIKit) import UIKit - /// Represents the state of the view state machine public enum ViewStateMachineState : Equatable { case none // No view shown @@ -244,3 +244,4 @@ private class PassthroughView: UIView { return false } } +#endif diff --git a/StatefulViewControllerTests/Info.plist b/Tests/StatefulViewControllerTests/Info.plist similarity index 100% rename from StatefulViewControllerTests/Info.plist rename to Tests/StatefulViewControllerTests/Info.plist diff --git a/StatefulViewControllerTests/StatefulViewControllerTests.swift b/Tests/StatefulViewControllerTests/StatefulViewControllerTests.swift similarity index 98% rename from StatefulViewControllerTests/StatefulViewControllerTests.swift rename to Tests/StatefulViewControllerTests/StatefulViewControllerTests.swift index 931b675..3fdc3fe 100644 --- a/StatefulViewControllerTests/StatefulViewControllerTests.swift +++ b/Tests/StatefulViewControllerTests/StatefulViewControllerTests.swift @@ -6,6 +6,7 @@ // Copyright (c) 2015 Alexander Schuch. All rights reserved. // +#if canImport(UIKit) import UIKit import XCTest import StatefulViewController @@ -66,3 +67,4 @@ class StatefulViewControllerTests: XCTestCase { } } +#endif