Skip to content

Commit

Permalink
Merge pull request zalando#48 from DwayneCoussement/feature/swift4.0
Browse files Browse the repository at this point in the history
Swift 4.0 Support.
  • Loading branch information
wojciechczerski authored Nov 30, 2017
2 parents 1e14f2f + c8480fa commit 3009465
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion SwiftMonkey/MonkeyXCTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ extension Monkey {
let alert = application.alerts.element(boundBy: i)
let buttons = alert.descendants(matching: .button)
XCTAssertNotEqual(buttons.count, 0, "No buttons in alert")
let index = UInt(self!.r.randomUInt32() % UInt32(buttons.count))
let index = self!.r.randomInt(lessThan: buttons.count)
let button = buttons.element(boundBy: index)
button.tap()
}
Expand Down
4 changes: 2 additions & 2 deletions SwiftMonkey/SwiftMonkey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkey;
};
name = Debug;
Expand All @@ -198,7 +198,7 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkey;
};
name = Release;
Expand Down
27 changes: 22 additions & 5 deletions SwiftMonkeyExample/SwiftMonkeyExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0810;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Zalando SE";
TargetAttributes = {
C929B5301DD0A764004B256F = {
CreatedOnToolsVersion = 8.1;
DevelopmentTeam = 9LW237982J;
LastSwiftMigration = 0900;
ProvisioningStyle = Automatic;
};
C929B5461DD0A764004B256F = {
Expand Down Expand Up @@ -386,15 +387,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -436,15 +444,22 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -483,7 +498,8 @@
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -500,7 +516,8 @@
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExample;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -513,7 +530,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = SwiftMonkeyExample;
};
name = Debug;
Expand All @@ -527,7 +544,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = org.zalando.SwiftMonkeyExampleUITests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
TEST_TARGET_NAME = SwiftMonkeyExample;
};
name = Release;
Expand Down
8 changes: 4 additions & 4 deletions SwiftMonkeyPaws/MonkeyPaws.swift
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ public class MonkeyPaws: NSObject, CALayerDelegate {
let originalMethod = class_getInstanceMethod(UIApplication.self, originalSelector)
let swizzledMethod = class_getInstanceMethod(UIApplication.self, swizzledSelector)

let didAddMethod = class_addMethod(UIApplication.self, originalSelector, method_getImplementation(swizzledMethod), method_getTypeEncoding(swizzledMethod))
let didAddMethod = class_addMethod(UIApplication.self, originalSelector, method_getImplementation(swizzledMethod!), method_getTypeEncoding(swizzledMethod!))

if didAddMethod {
class_replaceMethod(UIApplication.self, swizzledSelector, method_getImplementation(originalMethod), method_getTypeEncoding(originalMethod))
class_replaceMethod(UIApplication.self, swizzledSelector, method_getImplementation(originalMethod!), method_getTypeEncoding(originalMethod!))
} else {
method_exchangeImplementations(originalMethod, swizzledMethod)
method_exchangeImplementations(originalMethod!, swizzledMethod!)
}

return true
Expand Down Expand Up @@ -353,7 +353,7 @@ private struct WeakReference<T: AnyObject> {
}

extension UIApplication {
func monkey_sendEvent(_ event: UIEvent) {
@objc func monkey_sendEvent(_ event: UIEvent) {
for weakTrack in MonkeyPaws.tappingTracks {
if let track = weakTrack.value {
track.append(event: event)
Expand Down
11 changes: 9 additions & 2 deletions SwiftMonkeyPaws/SwiftMonkeyPaws.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,11 @@
isa = PBXProject;
attributes = {
LastUpgradeCheck = 9999;
TargetAttributes = {
OBJ_13 = {
LastSwiftMigration = 0900;
};
};
};
buildConfigurationList = OBJ_2 /* Build configuration list for PBXProject "SwiftMonkeyPaws" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -155,7 +160,8 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkeyPaws;
};
name = Debug;
Expand All @@ -176,7 +182,8 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = SWIFT_PACKAGE;
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = Default;
SWIFT_VERSION = 4.0;
TARGET_NAME = SwiftMonkeyPaws;
};
name = Release;
Expand Down

0 comments on commit 3009465

Please sign in to comment.