diff --git a/Example.xcodeproj/project.pbxproj b/Example.xcodeproj/project.pbxproj index 9fa81a5..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 */ @@ -357,6 +373,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, ); @@ -507,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"; @@ -515,6 +532,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 = ""; @@ -532,13 +550,14 @@ 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"; 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 = ""; @@ -553,11 +572,12 @@ "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)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Debug; @@ -567,11 +587,12 @@ 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)"; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 5.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example"; }; name = Release; @@ -671,6 +692,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 +704,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; }; @@ -696,13 +719,14 @@ 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; 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"; @@ -722,13 +746,14 @@ 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; 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 { 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