Skip to content
This repository has been archived by the owner on May 4, 2024. It is now read-only.

Commit

Permalink
SuperDelegate to Swift 3.0 & v0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Federman committed Sep 21, 2016
1 parent 01e5f6a commit 41edd64
Show file tree
Hide file tree
Showing 36 changed files with 780 additions and 808 deletions.
1 change: 1 addition & 0 deletions .swift-version
@@ -0,0 +1 @@
3.0
6 changes: 3 additions & 3 deletions .travis.yml
@@ -1,8 +1,8 @@
language: objective-c
osx_image: xcode7.3
osx_image: xcode8
before_script:
- bundle install
script:
- xctool -project SuperDelegate.xcodeproj -scheme SuperDelegate -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPad Air 2" test
- xctool -project Sample/SampleDelegate/SampleDelegate.xcodeproj -scheme SampleDelegate -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPad Air 2" build
- xcodebuild -project SuperDelegate.xcodeproj -scheme SuperDelegate -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone SE" test
- xcodebuild -project Sample/SampleDelegate/SampleDelegate.xcodeproj -scheme SampleDelegate -sdk iphonesimulator -destination "platform=iOS Simulator,name=iPhone SE" build
- pod lib lint --verbose --fail-fast
3 changes: 1 addition & 2 deletions Gemfile
@@ -1,4 +1,3 @@
source 'https://rubygems.org' do
gem 'cocoapods', '1.0.0'
gem 'activesupport', '~> 4.0'
gem 'cocoapods', '1.1.0.rc.2'
end
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -77,8 +77,8 @@ To opt into more AppDelegate features, have your `AppDelegate` class conform to

## Versions
* 0.8.* – Swift 2.3 and Xcode 7.3+. This version has been thouroughly vetted.
* 0.9.* – Swift 3.0 and Beta Xcode 8. This version is in active development.
* 1.0 – Will be released when iOS 10 is near release.
* 0.9.* – Swift 3.0 and Xcode 8+.
* 1.0 – Swift 3.0, Xcode 8+, and iOS 10 SDK adoption.

## Contributing

Expand Down
36 changes: 23 additions & 13 deletions Sample/SampleDelegate/SampleDelegate.xcodeproj/project.pbxproj
Expand Up @@ -7,15 +7,15 @@
objects = {

/* Begin PBXBuildFile section */
EAB6215D1D877D930087F1D3 /* SuperDelegate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAECD1BB1D0CAC07008BB9F5 /* SuperDelegate.framework */; };
EAB6215E1D877D930087F1D3 /* SuperDelegate.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EAECD1BB1D0CAC07008BB9F5 /* SuperDelegate.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EAEA845E1D8A1C0200F63F90 /* SuperDelegate.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = EAECD1BB1D0CAC07008BB9F5 /* SuperDelegate.framework */; };
EAEA845F1D8A1C0200F63F90 /* SuperDelegate.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = EAECD1BB1D0CAC07008BB9F5 /* SuperDelegate.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
EAECD1A41D0CABFD008BB9F5 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAECD1A31D0CABFD008BB9F5 /* AppDelegate.swift */; };
EAECD1A61D0CABFD008BB9F5 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = EAECD1A51D0CABFD008BB9F5 /* ViewController.swift */; };
EAECD1AB1D0CABFD008BB9F5 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = EAECD1AA1D0CABFD008BB9F5 /* Assets.xcassets */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
EAB6215F1D877D930087F1D3 /* PBXContainerItemProxy */ = {
EAEA84601D8A1C0200F63F90 /* PBXContainerItemProxy */ = {
isa = PBXContainerItemProxy;
containerPortal = EAECD1B51D0CAC07008BB9F5 /* SuperDelegate.xcodeproj */;
proxyType = 1;
Expand All @@ -39,13 +39,13 @@
/* End PBXContainerItemProxy section */

/* Begin PBXCopyFilesBuildPhase section */
EAB621611D877D930087F1D3 /* Embed Frameworks */ = {
EAEA84621D8A1C0200F63F90 /* Embed Frameworks */ = {
isa = PBXCopyFilesBuildPhase;
buildActionMask = 2147483647;
dstPath = "";
dstSubfolderSpec = 10;
files = (
EAB6215E1D877D930087F1D3 /* SuperDelegate.framework in Embed Frameworks */,
EAEA845F1D8A1C0200F63F90 /* SuperDelegate.framework in Embed Frameworks */,
);
name = "Embed Frameworks";
runOnlyForDeploymentPostprocessing = 0;
Expand All @@ -66,7 +66,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
EAB6215D1D877D930087F1D3 /* SuperDelegate.framework in Frameworks */,
EAEA845E1D8A1C0200F63F90 /* SuperDelegate.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -120,12 +120,12 @@
EAECD19C1D0CABFD008BB9F5 /* Sources */,
EAECD19D1D0CABFD008BB9F5 /* Frameworks */,
EAECD19E1D0CABFD008BB9F5 /* Resources */,
EAB621611D877D930087F1D3 /* Embed Frameworks */,
EAEA84621D8A1C0200F63F90 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
EAB621601D877D930087F1D3 /* PBXTargetDependency */,
EAEA84611D8A1C0200F63F90 /* PBXTargetDependency */,
);
name = SampleDelegate;
productName = SampleDelegate;
Expand All @@ -139,11 +139,12 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0730;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Square, Inc.";
TargetAttributes = {
EAECD19F1D0CABFD008BB9F5 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0800;
};
};
};
Expand Down Expand Up @@ -212,10 +213,10 @@
/* End PBXSourcesBuildPhase section */

/* Begin PBXTargetDependency section */
EAB621601D877D930087F1D3 /* PBXTargetDependency */ = {
EAEA84611D8A1C0200F63F90 /* PBXTargetDependency */ = {
isa = PBXTargetDependency;
name = SuperDelegate;
targetProxy = EAB6215F1D877D930087F1D3 /* PBXContainerItemProxy */;
targetProxy = EAEA84601D8A1C0200F63F90 /* PBXContainerItemProxy */;
};
/* End PBXTargetDependency section */

Expand All @@ -234,8 +235,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -262,6 +265,7 @@
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -279,8 +283,10 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
Expand All @@ -299,31 +305,35 @@
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
SWIFT_VERSION = 3.0;
VALIDATE_PRODUCT = YES;
};
name = Release;
};
EAECD1B31D0CABFD008BB9F5 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = SampleDelegate/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.SampleDelegate;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
};
name = Debug;
};
EAECD1B41D0CABFD008BB9F5 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
EMBEDDED_CONTENT_CONTAINS_SWIFT = YES;
INFOPLIST_FILE = SampleDelegate/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.squareup.SampleDelegate;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
72 changes: 36 additions & 36 deletions Sample/SampleDelegate/SampleDelegate/AppDelegate.swift
Expand Up @@ -24,7 +24,7 @@ import SuperDelegate

@UIApplicationMain
class AppDelegate: SuperDelegate, ApplicationLaunched {

let window = UIWindow()

// MARK: ApplicationLaunched
Expand All @@ -33,65 +33,65 @@ class AppDelegate: SuperDelegate, ApplicationLaunched {
// Setup app model, networking, logging, etc.
}

func loadInterfaceWithLaunchItem(launchItem: LaunchItem) {
func loadInterface(launchItem: LaunchItem) {
// Setup our main window since we don't have a storyboard.
setupMainWindow(window)
setup(mainWindow: window)
window.rootViewController = ViewController()

switch launchItem {
case let .RemoteNotificationItem(remoteNotification):
case let .remoteNotification(item):
// Show UI for the remote notification that brought us into the foreground.
didReceiveRemoteNotification(remoteNotification, notificationOrigin: .UserTappedToBringAppToForeground, fetchCompletionHandler: { (_) in
didReceive(remoteNotification: item, origin: .userTappedToBringAppToForeground, fetchCompletionHandler: { (_) in
// Nothing to do here.
})

case let .LocalNotificationItem(localNotification):
case let .localNotification(item):
// Show UI for the local notification that brought us into the foreground.
didReceiveLocalNotification(localNotification, notificationOrigin: .UserTappedToBringAppToForeground)
didReceive(localNotification: item, origin: .userTappedToBringAppToForeground)

case let .OpenURLItem(urlToOpen):
case let .openURL(item):
// If we have a urlToOpen launch item, SuperDelegate has guaranteed that we can open that URL.
handleURLToOpen(urlToOpen)
let _ = handle(urlToOpen: item)

case let .ShortcutItem(shortcutItem):
case let .shortcut(item):
// Process the shortcut item.
handleShortcutItem(shortcutItem, completionHandler: {
handle(shortcutItem: item, completionHandler: {
// Nothing to do here.
})

case let .UserActivityItem(userActivity):
case let .userActivity(item):
// If we have a userActivity launch item, SuperDelegate has guaranteed that we can continue this user activity.
continueUserActivity(userActivity, restorationHandler: { (_) in
let _ = resume(userActivity: item, restorationHandler: { (_) in
// Nothing to do here.
})

case .NoItem:
case .none:
// We were launched because the launched us from Springboard or the App Switcher.
break
}
}
}

extension AppDelegate: RemoteNotificationCapable {
func didRegisterForRemoteNotificationsWithToken(deviceToken: NSData) {
func didRegisterForRemoteNotifications(withDeviceToken deviceToken: Data) {
// Update server with the new token.
}

func didFailToRegisterForRemoteNotificationsWithError(error: NSError) {
func didFailToRegisterForRemoteNotifications(withError error: Error) {
// Tell the server that push can't succeed right now.
}

func didReceiveRemoteNotification(remoteNotification: RemoteNotification, notificationOrigin: UserNotificationOrigin, fetchCompletionHandler completionHandler: ((UIBackgroundFetchResult) -> Void)) {
switch notificationOrigin {
case .UserTappedToBringAppToForeground:
func didReceive(remoteNotification: RemoteNotification, origin: UserNotificationOrigin, fetchCompletionHandler completionHandler: (@escaping (UIBackgroundFetchResult) -> Void)) {
switch origin {
case .userTappedToBringAppToForeground:
// The customer tapped on the notification. Show UI about the notification.
break

case .DeliveredWhileInForground:
case .deliveredWhileInForeground:
// The customer has not seen this notification. Alert the customer somehow.
break

case .DeliveredWhileInBackground:
case .deliveredWhileInBackground:
// Process the background notification.
break
}
Expand All @@ -100,62 +100,62 @@ extension AppDelegate: RemoteNotificationCapable {

extension AppDelegate: UserNotificationCapable {
func requestedUserNotificationSettings() -> UIUserNotificationSettings {
return UIUserNotificationSettings(forTypes: [.Badge, .Sound, .Alert], categories: nil)
return UIUserNotificationSettings(types: [.badge, .sound, .alert], categories: nil)
}

func didReceiveUserNotificationPermissions(userNotificationPermissionsGranted: UserNotificationPermissionsGranted) {
switch userNotificationPermissionsGranted {
case .None:
func didReceive(userNotificationPermissions: UserNotificationPermissionsGranted) {
switch userNotificationPermissions {
case .none:
// The customer has denied user (e.g. local and loud remote) notification permissions.
break
case .Requested:
case .requested:
// The customer has given us permission for all requested user notifications.
break
case let .Some(grantedPermissions):
print("Customer refused to give us permissions for \(requestedUserNotificationSettings().types.exclusiveOr(grantedPermissions))")
case let .partial(grantedPermissions):
print("Customer refused to give us permissions for \(requestedUserNotificationSettings().types.symmetricDifference(grantedPermissions))")
break
}
}
}

extension AppDelegate: LocalNotificationCapable {
func didReceiveLocalNotification(localNotification: UILocalNotification, notificationOrigin: UserNotificationOrigin) {
func didReceive(localNotification: UILocalNotification, origin: UserNotificationOrigin) {
// Process the notification.
}
}

extension AppDelegate: OpenURLCapable {
func canOpenLaunchURL(launchURLToOpen: URLToOpen) -> Bool {
func canOpen(launchURL: URLToOpen) -> Bool {
// SampleDelegate can handle all URLs given to us at launch! If some URLs shouldn't open your app, return false here.
return true
}

func handleURLToOpen(urlToOpen: URLToOpen) -> Bool {
func handle(urlToOpen: URLToOpen) -> Bool {
// Show UI that corresponds to the opened URL. If you can't open the URL, return false here.
return true
}
}

extension AppDelegate: ShortcutCapable {
func canHandleShortcutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
func canHandle(shortcutItem: UIApplicationShortcutItem) -> Bool {
// SampleDelegate can handle all shortcut items! If your app needs to invalidate shortcut items that were set by a previous version of the app, return false here.
return true
}

func handleShortcutItem(shortcutItem: UIApplicationShortcutItem, completionHandler: () -> Void) {
func handle(shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping () -> Void) {
// Process the shortcut, then tell iOS that we've handled the shortcut.
completionHandler()
}
}

extension AppDelegate: UserActivityCapable {
func canHandleUserActivity(userActivity: NSUserActivity) -> Bool {
func canResume(userActivity: NSUserActivity) -> Bool {
// SampleDelegate can handle all user activity items!
return true
}

func continueUserActivity(userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool {
func resume(userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {
// Show UI for the user activity.
return true
}
}
}
2 changes: 1 addition & 1 deletion Sample/SampleDelegate/SampleDelegate/ViewController.swift
Expand Up @@ -26,7 +26,7 @@ class ViewController: UIViewController {
super.viewDidLoad()

// Show that our view has been loaded by changing our background color to blue.
view.backgroundColor = UIColor.blueColor()
view.backgroundColor = UIColor.blue
}
}

0 comments on commit 41edd64

Please sign in to comment.