Skip to content

Commit 1f04de6

Browse files
authored
Merge pull request #136 from button/wes/introduce_swiftier_registration
A more Swift friendly route registration
2 parents dbc972f + 0a4d77a commit 1f04de6

13 files changed

+125
-34
lines changed

DeepLinkKit.podspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "DeepLinkKit"
3-
s.version = "1.4.0"
3+
s.version = "1.5.0"
44
s.summary = "A splendid route-matching, block-based way to handle your deep links."
55
s.description = <<-DESC
66
DeepLink Kit is a splendid route-handling block-based way to handle deep links. Use DeepLink Kit to parse incoming URLs, extract parameters from the host, url etc.. and even build outgoing deep links. All with a simple, block-based interface.

DeepLinkKit.xcodeproj/project.pbxproj

+47-5
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,15 @@
830830
attributes = {
831831
CLASSPREFIX = DPL;
832832
LastSwiftUpdateCheck = 0700;
833-
LastUpgradeCheck = 0700;
833+
LastUpgradeCheck = 0900;
834834
ORGANIZATIONNAME = "Button, Inc.";
835835
TargetAttributes = {
836836
6003F5AD195388D20070C39A = {
837837
TestTargetID = 6003F589195388D20070C39A;
838838
};
839839
62335DD51B57003300E3818C = {
840840
CreatedOnToolsVersion = 6.4;
841+
LastSwiftMigration = 0900;
841842
};
842843
BFDB96ED1F3BFF8E001AE303 = {
843844
CreatedOnToolsVersion = 8.3.3;
@@ -922,7 +923,7 @@
922923
);
923924
runOnlyForDeploymentPostprocessing = 0;
924925
shellPath = /bin/sh;
925-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
926+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
926927
showEnvVarsInLog = 0;
927928
};
928929
169E441B24A0182ECBEA02B1 /* [CP] Embed Pods Frameworks */ = {
@@ -982,7 +983,7 @@
982983
);
983984
runOnlyForDeploymentPostprocessing = 0;
984985
shellPath = /bin/sh;
985-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
986+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
986987
showEnvVarsInLog = 0;
987988
};
988989
78E4A2B7A96651F3AE873F35 /* [CP] Check Pods Manifest.lock */ = {
@@ -997,7 +998,7 @@
997998
);
998999
runOnlyForDeploymentPostprocessing = 0;
9991000
shellPath = /bin/sh;
1000-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
1001+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
10011002
showEnvVarsInLog = 0;
10021003
};
10031004
92CBDC92946CE1B22732C030 /* [CP] Copy Pods Resources */ = {
@@ -1057,7 +1058,7 @@
10571058
);
10581059
runOnlyForDeploymentPostprocessing = 0;
10591060
shellPath = /bin/sh;
1060-
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
1061+
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n";
10611062
showEnvVarsInLog = 0;
10621063
};
10631064
D0318767A555E3ECB0E5307A /* [CP] Copy Pods Resources */ = {
@@ -1243,19 +1244,30 @@
12431244
CLANG_CXX_LIBRARY = "libc++";
12441245
CLANG_ENABLE_MODULES = YES;
12451246
CLANG_ENABLE_OBJC_ARC = YES;
1247+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
12461248
CLANG_WARN_BOOL_CONVERSION = YES;
1249+
CLANG_WARN_COMMA = YES;
12471250
CLANG_WARN_CONSTANT_CONVERSION = YES;
12481251
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
12491252
CLANG_WARN_EMPTY_BODY = YES;
12501253
CLANG_WARN_ENUM_CONVERSION = YES;
1254+
CLANG_WARN_INFINITE_RECURSION = YES;
12511255
CLANG_WARN_INT_CONVERSION = YES;
1256+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
1257+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
12521258
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1259+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1260+
CLANG_WARN_STRICT_PROTOTYPES = YES;
1261+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
1262+
CLANG_WARN_UNREACHABLE_CODE = YES;
12531263
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
12541264
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
12551265
COPY_PHASE_STRIP = NO;
1266+
ENABLE_STRICT_OBJC_MSGSEND = YES;
12561267
ENABLE_TESTABILITY = YES;
12571268
GCC_C_LANGUAGE_STANDARD = gnu99;
12581269
GCC_DYNAMIC_NO_PIC = NO;
1270+
GCC_NO_COMMON_BLOCKS = YES;
12591271
GCC_OPTIMIZATION_LEVEL = 0;
12601272
GCC_PREPROCESSOR_DEFINITIONS = (
12611273
"DEBUG=1",
@@ -1284,18 +1296,29 @@
12841296
CLANG_CXX_LIBRARY = "libc++";
12851297
CLANG_ENABLE_MODULES = YES;
12861298
CLANG_ENABLE_OBJC_ARC = YES;
1299+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
12871300
CLANG_WARN_BOOL_CONVERSION = YES;
1301+
CLANG_WARN_COMMA = YES;
12881302
CLANG_WARN_CONSTANT_CONVERSION = YES;
12891303
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
12901304
CLANG_WARN_EMPTY_BODY = YES;
12911305
CLANG_WARN_ENUM_CONVERSION = YES;
1306+
CLANG_WARN_INFINITE_RECURSION = YES;
12921307
CLANG_WARN_INT_CONVERSION = YES;
1308+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
1309+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
12931310
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1311+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1312+
CLANG_WARN_STRICT_PROTOTYPES = YES;
1313+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
1314+
CLANG_WARN_UNREACHABLE_CODE = YES;
12941315
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
12951316
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
12961317
COPY_PHASE_STRIP = YES;
12971318
ENABLE_NS_ASSERTIONS = NO;
1319+
ENABLE_STRICT_OBJC_MSGSEND = YES;
12981320
GCC_C_LANGUAGE_STANDARD = gnu99;
1321+
GCC_NO_COMMON_BLOCKS = YES;
12991322
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
13001323
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
13011324
GCC_WARN_UNDECLARED_SELECTOR = YES;
@@ -1304,6 +1327,7 @@
13041327
GCC_WARN_UNUSED_VARIABLE = YES;
13051328
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
13061329
SDKROOT = iphoneos;
1330+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
13071331
TARGETED_DEVICE_FAMILY = "1,2";
13081332
VALIDATE_PRODUCT = YES;
13091333
};
@@ -1397,6 +1421,8 @@
13971421
PRODUCT_NAME = "$(TARGET_NAME)";
13981422
SWIFT_OBJC_BRIDGING_HEADER = "SampleApps/ReceiverDemoSwift/ReceiverDemoSwift-Bridging-Header.h";
13991423
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
1424+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
1425+
SWIFT_VERSION = 4.0;
14001426
TARGETED_DEVICE_FAMILY = 1;
14011427
};
14021428
name = Debug;
@@ -1419,6 +1445,8 @@
14191445
PRODUCT_BUNDLE_IDENTIFIER = "com.usebutton.$(PRODUCT_NAME:rfc1034identifier)";
14201446
PRODUCT_NAME = "$(TARGET_NAME)";
14211447
SWIFT_OBJC_BRIDGING_HEADER = "SampleApps/ReceiverDemoSwift/ReceiverDemoSwift-Bridging-Header.h";
1448+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
1449+
SWIFT_VERSION = 4.0;
14221450
TARGETED_DEVICE_FAMILY = 1;
14231451
};
14241452
name = Test;
@@ -1441,6 +1469,8 @@
14411469
PRODUCT_BUNDLE_IDENTIFIER = "com.usebutton.$(PRODUCT_NAME:rfc1034identifier)";
14421470
PRODUCT_NAME = "$(TARGET_NAME)";
14431471
SWIFT_OBJC_BRIDGING_HEADER = "SampleApps/ReceiverDemoSwift/ReceiverDemoSwift-Bridging-Header.h";
1472+
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
1473+
SWIFT_VERSION = 4.0;
14441474
TARGETED_DEVICE_FAMILY = 1;
14451475
};
14461476
name = Release;
@@ -1548,18 +1578,29 @@
15481578
CLANG_CXX_LIBRARY = "libc++";
15491579
CLANG_ENABLE_MODULES = YES;
15501580
CLANG_ENABLE_OBJC_ARC = YES;
1581+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
15511582
CLANG_WARN_BOOL_CONVERSION = YES;
1583+
CLANG_WARN_COMMA = YES;
15521584
CLANG_WARN_CONSTANT_CONVERSION = YES;
15531585
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
15541586
CLANG_WARN_EMPTY_BODY = YES;
15551587
CLANG_WARN_ENUM_CONVERSION = YES;
1588+
CLANG_WARN_INFINITE_RECURSION = YES;
15561589
CLANG_WARN_INT_CONVERSION = YES;
1590+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
1591+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
15571592
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
1593+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
1594+
CLANG_WARN_STRICT_PROTOTYPES = YES;
1595+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
1596+
CLANG_WARN_UNREACHABLE_CODE = YES;
15581597
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
15591598
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
15601599
COPY_PHASE_STRIP = NO;
1600+
ENABLE_STRICT_OBJC_MSGSEND = YES;
15611601
GCC_C_LANGUAGE_STANDARD = gnu99;
15621602
GCC_DYNAMIC_NO_PIC = NO;
1603+
GCC_NO_COMMON_BLOCKS = YES;
15631604
GCC_OPTIMIZATION_LEVEL = 0;
15641605
GCC_PREPROCESSOR_DEFINITIONS = (
15651606
"DEBUG=1",
@@ -1730,6 +1771,7 @@
17301771
BFDB96F51F3BFF8E001AE303 /* Release */,
17311772
);
17321773
defaultConfigurationIsVisible = 0;
1774+
defaultConfigurationName = Release;
17331775
};
17341776
DEDB14AD1A3F944E00A837F8 /* Build configuration list for PBXNativeTarget "SenderDemo" */ = {
17351777
isa = XCConfigurationList;

DeepLinkKit.xcodeproj/xcshareddata/xcschemes/DeepLinkKit.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0830"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -36,6 +37,7 @@
3637
buildConfiguration = "Debug"
3738
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3839
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
40+
language = ""
3941
launchStyle = "0"
4042
useCustomWorkingDirectory = "NO"
4143
ignoresPersistentStateOnLaunch = "NO"

DeepLinkKit.xcodeproj/xcshareddata/xcschemes/ReceiverDemo.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0700"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Test"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES"
3031
codeCoverageEnabled = "YES">
3132
<Testables>
@@ -56,6 +57,7 @@
5657
buildConfiguration = "Debug"
5758
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5859
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
60+
language = ""
5961
launchStyle = "0"
6062
useCustomWorkingDirectory = "NO"
6163
ignoresPersistentStateOnLaunch = "NO"

DeepLinkKit.xcodeproj/xcshareddata/xcschemes/SenderDemo.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0700"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -40,6 +40,7 @@
4040
buildConfiguration = "Test"
4141
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4242
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
43+
language = ""
4344
shouldUseLaunchSchemeArgsEnv = "YES">
4445
<Testables>
4546
<TestableReference
@@ -69,6 +70,7 @@
6970
buildConfiguration = "Debug"
7071
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
7172
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
73+
language = ""
7274
launchStyle = "0"
7375
useCustomWorkingDirectory = "NO"
7476
ignoresPersistentStateOnLaunch = "NO"

DeepLinkKit/Router/DPLDeepLinkRouter.h

+11-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
6868
- (void)registerBlock:(DPLRouteHandlerBlock)routeHandlerBlock forRoute:(NSString *)route;
6969

7070

71+
/**
72+
A Swift friendly version of -registerBlock:forRoute:
73+
74+
@see -registerBlock:forRoute:
75+
*/
76+
- (void)register:(NSString *)route routeHandlerBlock:(DPLRouteHandlerBlock)routeHandlerBlock;
77+
78+
7179

7280
///-------------------------
7381
/// @name Routing Deep Links
@@ -128,7 +136,8 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
128136
}
129137
@endcode
130138
*/
131-
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key;
139+
- (void)setObject:(id)obj forKeyedSubscript:(NSString *)key
140+
NS_SWIFT_UNAVAILABLE("Available in Swift as: register(route: String, routeHandlerBlock: (DPLDeepLink) -> ())");
132141

133142

134143
/**
@@ -138,6 +147,6 @@ typedef void(^DPLRouteCompletionBlock)(BOOL handled, NSError *error);
138147
@endcode
139148
@note The type of the returned handler is the type you registered for that route.
140149
*/
141-
- (id)objectForKeyedSubscript:(NSString *)key;
150+
- (id)objectForKeyedSubscript:(NSString *)key NS_SWIFT_UNAVAILABLE("Not Available");
142151

143152
@end

DeepLinkKit/Router/DPLDeepLinkRouter.m

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ - (void)registerBlock:(DPLRouteHandlerBlock)routeHandlerBlock forRoute:(NSString
6262
}
6363

6464

65+
- (void)register:(NSString *)route routeHandlerBlock:(DPLRouteHandlerBlock)routeHandlerBlock {
66+
[self registerBlock:routeHandlerBlock forRoute:route];
67+
}
68+
69+
6570
#pragma mark - Registering Routes via Object Subscripting
6671

6772
- (id)objectForKeyedSubscript:(NSString *)key {

Podfile

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
project 'DeepLinkKit.xcodeproj', 'Test' => :debug
22
inhibit_all_warnings!
33
use_frameworks!
4+
platform :ios, '8.0'
45

56
target 'SenderDemo' do
67
pod 'DeepLinkKit', :path => '.'

Podfile.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- DeepLinkKit (1.4.0)
2+
- DeepLinkKit (1.5.0)
33
- Expecta (1.0.6)
44
- KIF (3.6.0):
55
- KIF/Core (= 3.6.0)
@@ -19,12 +19,12 @@ EXTERNAL SOURCES:
1919
:path: "."
2020

2121
SPEC CHECKSUMS:
22-
DeepLinkKit: bffd3b5e51549222f974d631b4e0e7484600b9d8
22+
DeepLinkKit: 98a26f2c5cf4c86b97c1170cdf3737ae49a3a50c
2323
Expecta: 3b6bd90a64b9a1dcb0b70aa0e10a7f8f631667d5
2424
KIF: bd770edd8ce49bc7308501e4871e58a02d137be3
2525
OCMock: 35ae71d6a8fcc1b59434d561d1520b9dd4f15765
2626
Specta: 3e1bd89c3517421982dc4d1c992503e48bd5fe66
2727

28-
PODFILE CHECKSUM: 47a943bbf5fb3be0a7f74806f054afe0fc7974ff
28+
PODFILE CHECKSUM: c390f027c860b497aa35e691b8e585f706ac36a5
2929

30-
COCOAPODS: 1.2.0
30+
COCOAPODS: 1.2.1

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,22 @@ Add deep link support to your app in 5 minutes or less following these simple st
7979
<br />
8080
**4. Register a route handler**
8181

82+
Objective-C
8283
````objc
8384
self.router[@"/log/:message"] = ^(DPLDeepLink *link) {
8485
NSLog(@"%@", link.routeParameters[@"message"]);
8586
};
8687
````
88+
89+
Swift
90+
````swift
91+
self.router.register("/log/:message") { link in
92+
if let link = link {
93+
print("\(link.routeParameters["message"])")
94+
}
95+
}
96+
````
97+
8798
<br />
8899
**5. Pass incoming URLs to the router**
89100

0 commit comments

Comments
 (0)