diff --git a/.hound.yml b/.hound.yml new file mode 100644 index 0000000..d659195 --- /dev/null +++ b/.hound.yml @@ -0,0 +1,2 @@ +swift: + config_file: .swiftlint.yml diff --git a/.swiftlint.yml b/.swiftlint.yml index 0ef64f7..d36bf77 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -15,7 +15,8 @@ disabled_rules: - line_length - force_try - vertical_whitespace - +- redundant_string_enum_value + force_try: warning line_length: 150 diff --git a/CHANGELOG.md b/CHANGELOG.md index 32d6941..8c9d217 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # CHANGELOG +### v2.1 +- Added HouncCI for linting swift code. #33 +- Fixed minor bugs. #35 +- Added support for Objective-C #36 + ### v2.0 - Realistic animation like Facebook Messenger #24, #26 - Redesign of ProxyDelegate #25, #27 diff --git a/ObjcDemo/ObjcDemo.xcodeproj/project.pbxproj b/ObjcDemo/ObjcDemo.xcodeproj/project.pbxproj new file mode 100644 index 0000000..7e46303 --- /dev/null +++ b/ObjcDemo/ObjcDemo.xcodeproj/project.pbxproj @@ -0,0 +1,352 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 46; + objects = { + +/* Begin PBXBuildFile section */ + 4D2D09E31E7A6A0700EEF278 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D2D09E21E7A6A0700EEF278 /* main.m */; }; + 4D2D09E61E7A6A0700EEF278 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D2D09E51E7A6A0700EEF278 /* AppDelegate.m */; }; + 4D2D09E91E7A6A0700EEF278 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D2D09E81E7A6A0700EEF278 /* ViewController.m */; }; + 4D2D09EC1E7A6A0700EEF278 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D2D09EA1E7A6A0700EEF278 /* Main.storyboard */; }; + 4D2D09EE1E7A6A0700EEF278 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 4D2D09ED1E7A6A0700EEF278 /* Assets.xcassets */; }; + 4D2D09F11E7A6A0700EEF278 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 4D2D09EF1E7A6A0700EEF278 /* LaunchScreen.storyboard */; }; + 4D2D09F91E7A6B5400EEF278 /* PullToDismiss.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4D2D09F81E7A6B5400EEF278 /* PullToDismiss.framework */; }; + 4D2D09FA1E7A6B5400EEF278 /* PullToDismiss.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 4D2D09F81E7A6B5400EEF278 /* PullToDismiss.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; + 4D2D0A011E7A6C3200EEF278 /* SampleTableViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D2D0A001E7A6C3200EEF278 /* SampleTableViewController.m */; }; + 4D871A591E7CFFE800DE0C35 /* CustomShadowEffect.m in Sources */ = {isa = PBXBuildFile; fileRef = 4D871A581E7CFFE800DE0C35 /* CustomShadowEffect.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXCopyFilesBuildPhase section */ + 4D2D09FB1E7A6B5500EEF278 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 4D2D09FA1E7A6B5400EEF278 /* PullToDismiss.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + +/* Begin PBXFileReference section */ + 4D2D09DE1E7A6A0700EEF278 /* ObjcDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjcDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 4D2D09E21E7A6A0700EEF278 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 4D2D09E41E7A6A0700EEF278 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 4D2D09E51E7A6A0700EEF278 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 4D2D09E71E7A6A0700EEF278 /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; + 4D2D09E81E7A6A0700EEF278 /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; + 4D2D09EB1E7A6A0700EEF278 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; + 4D2D09ED1E7A6A0700EEF278 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 4D2D09F01E7A6A0700EEF278 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; + 4D2D09F21E7A6A0700EEF278 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 4D2D09F81E7A6B5400EEF278 /* PullToDismiss.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = PullToDismiss.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4D2D09FF1E7A6C3200EEF278 /* SampleTableViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SampleTableViewController.h; sourceTree = ""; }; + 4D2D0A001E7A6C3200EEF278 /* SampleTableViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SampleTableViewController.m; sourceTree = ""; }; + 4D871A571E7CFFE800DE0C35 /* CustomShadowEffect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomShadowEffect.h; sourceTree = ""; }; + 4D871A581E7CFFE800DE0C35 /* CustomShadowEffect.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CustomShadowEffect.m; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 4D2D09DB1E7A6A0700EEF278 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 4D2D09F91E7A6B5400EEF278 /* PullToDismiss.framework in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 4D2D09D51E7A6A0700EEF278 = { + isa = PBXGroup; + children = ( + 4D2D09F81E7A6B5400EEF278 /* PullToDismiss.framework */, + 4D2D09E01E7A6A0700EEF278 /* ObjcDemo */, + 4D2D09DF1E7A6A0700EEF278 /* Products */, + ); + sourceTree = ""; + }; + 4D2D09DF1E7A6A0700EEF278 /* Products */ = { + isa = PBXGroup; + children = ( + 4D2D09DE1E7A6A0700EEF278 /* ObjcDemo.app */, + ); + name = Products; + sourceTree = ""; + }; + 4D2D09E01E7A6A0700EEF278 /* ObjcDemo */ = { + isa = PBXGroup; + children = ( + 4D2D09E41E7A6A0700EEF278 /* AppDelegate.h */, + 4D2D09E51E7A6A0700EEF278 /* AppDelegate.m */, + 4D2D09E71E7A6A0700EEF278 /* ViewController.h */, + 4D2D09E81E7A6A0700EEF278 /* ViewController.m */, + 4D2D09FF1E7A6C3200EEF278 /* SampleTableViewController.h */, + 4D2D0A001E7A6C3200EEF278 /* SampleTableViewController.m */, + 4D871A571E7CFFE800DE0C35 /* CustomShadowEffect.h */, + 4D871A581E7CFFE800DE0C35 /* CustomShadowEffect.m */, + 4D2D09EA1E7A6A0700EEF278 /* Main.storyboard */, + 4D2D09ED1E7A6A0700EEF278 /* Assets.xcassets */, + 4D2D09EF1E7A6A0700EEF278 /* LaunchScreen.storyboard */, + 4D2D09F21E7A6A0700EEF278 /* Info.plist */, + 4D2D09E11E7A6A0700EEF278 /* Supporting Files */, + ); + path = ObjcDemo; + sourceTree = ""; + }; + 4D2D09E11E7A6A0700EEF278 /* Supporting Files */ = { + isa = PBXGroup; + children = ( + 4D2D09E21E7A6A0700EEF278 /* main.m */, + ); + name = "Supporting Files"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 4D2D09DD1E7A6A0700EEF278 /* ObjcDemo */ = { + isa = PBXNativeTarget; + buildConfigurationList = 4D2D09F51E7A6A0700EEF278 /* Build configuration list for PBXNativeTarget "ObjcDemo" */; + buildPhases = ( + 4D2D09DA1E7A6A0700EEF278 /* Sources */, + 4D2D09DB1E7A6A0700EEF278 /* Frameworks */, + 4D2D09DC1E7A6A0700EEF278 /* Resources */, + 4D2D09FB1E7A6B5500EEF278 /* Embed Frameworks */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ObjcDemo; + productName = ObjcDemo; + productReference = 4D2D09DE1E7A6A0700EEF278 /* ObjcDemo.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 4D2D09D61E7A6A0700EEF278 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 0820; + ORGANIZATIONNAME = "Suguru Kishimoto"; + TargetAttributes = { + 4D2D09DD1E7A6A0700EEF278 = { + CreatedOnToolsVersion = 8.2.1; + DevelopmentTeam = KW3G83N6K6; + ProvisioningStyle = Automatic; + }; + }; + }; + buildConfigurationList = 4D2D09D91E7A6A0700EEF278 /* Build configuration list for PBXProject "ObjcDemo" */; + compatibilityVersion = "Xcode 3.2"; + developmentRegion = English; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 4D2D09D51E7A6A0700EEF278; + productRefGroup = 4D2D09DF1E7A6A0700EEF278 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 4D2D09DD1E7A6A0700EEF278 /* ObjcDemo */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 4D2D09DC1E7A6A0700EEF278 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4D2D09F11E7A6A0700EEF278 /* LaunchScreen.storyboard in Resources */, + 4D2D09EE1E7A6A0700EEF278 /* Assets.xcassets in Resources */, + 4D2D09EC1E7A6A0700EEF278 /* Main.storyboard in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 4D2D09DA1E7A6A0700EEF278 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 4D2D09E91E7A6A0700EEF278 /* ViewController.m in Sources */, + 4D871A591E7CFFE800DE0C35 /* CustomShadowEffect.m in Sources */, + 4D2D09E61E7A6A0700EEF278 /* AppDelegate.m in Sources */, + 4D2D09E31E7A6A0700EEF278 /* main.m in Sources */, + 4D2D0A011E7A6C3200EEF278 /* SampleTableViewController.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 4D2D09EA1E7A6A0700EEF278 /* Main.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4D2D09EB1E7A6A0700EEF278 /* Base */, + ); + name = Main.storyboard; + sourceTree = ""; + }; + 4D2D09EF1E7A6A0700EEF278 /* LaunchScreen.storyboard */ = { + isa = PBXVariantGroup; + children = ( + 4D2D09F01E7A6A0700EEF278 /* Base */, + ); + name = LaunchScreen.storyboard; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 4D2D09F31E7A6A0700EEF278 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = 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_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"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + }; + name = Debug; + }; + 4D2D09F41E7A6A0700EEF278 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BOOL_CONVERSION = 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_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"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 10.2; + MTL_ENABLE_DEBUG_INFO = NO; + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 4D2D09F61E7A6A0700EEF278 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = KW3G83N6K6; + INFOPLIST_FILE = ObjcDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "-.ObjcDemo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 4D2D09F71E7A6A0700EEF278 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = KW3G83N6K6; + INFOPLIST_FILE = ObjcDemo/Info.plist; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = "-.ObjcDemo"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 4D2D09D91E7A6A0700EEF278 /* Build configuration list for PBXProject "ObjcDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4D2D09F31E7A6A0700EEF278 /* Debug */, + 4D2D09F41E7A6A0700EEF278 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 4D2D09F51E7A6A0700EEF278 /* Build configuration list for PBXNativeTarget "ObjcDemo" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 4D2D09F61E7A6A0700EEF278 /* Debug */, + 4D2D09F71E7A6A0700EEF278 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 4D2D09D61E7A6A0700EEF278 /* Project object */; +} diff --git a/ObjcDemo/ObjcDemo/AppDelegate.h b/ObjcDemo/ObjcDemo/AppDelegate.h new file mode 100644 index 0000000..95e3e44 --- /dev/null +++ b/ObjcDemo/ObjcDemo/AppDelegate.h @@ -0,0 +1,17 @@ +// +// AppDelegate.h +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import + +@interface AppDelegate : UIResponder + +@property (strong, nonatomic) UIWindow *window; + + +@end + diff --git a/ObjcDemo/ObjcDemo/AppDelegate.m b/ObjcDemo/ObjcDemo/AppDelegate.m new file mode 100644 index 0000000..8a02b8f --- /dev/null +++ b/ObjcDemo/ObjcDemo/AppDelegate.m @@ -0,0 +1,51 @@ +// +// AppDelegate.m +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@end + +@implementation AppDelegate + + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + // Override point for customization after application launch. + return YES; +} + + +- (void)applicationWillResignActive:(UIApplication *)application { + // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. + // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. +} + + +- (void)applicationDidEnterBackground:(UIApplication *)application { + // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. + // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. +} + + +- (void)applicationWillEnterForeground:(UIApplication *)application { + // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. +} + + +- (void)applicationDidBecomeActive:(UIApplication *)application { + // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. +} + + +- (void)applicationWillTerminate:(UIApplication *)application { + // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. +} + + +@end diff --git a/ObjcDemo/ObjcDemo/Assets.xcassets/AppIcon.appiconset/Contents.json b/ObjcDemo/ObjcDemo/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..b8236c6 --- /dev/null +++ b/ObjcDemo/ObjcDemo/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,48 @@ +{ + "images" : [ + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "20x20", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "29x29", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "40x40", + "scale" : "3x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "2x" + }, + { + "idiom" : "iphone", + "size" : "60x60", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/ObjcDemo/ObjcDemo/Base.lproj/LaunchScreen.storyboard b/ObjcDemo/ObjcDemo/Base.lproj/LaunchScreen.storyboard new file mode 100644 index 0000000..fdf3f97 --- /dev/null +++ b/ObjcDemo/ObjcDemo/Base.lproj/LaunchScreen.storyboard @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ObjcDemo/ObjcDemo/Base.lproj/Main.storyboard b/ObjcDemo/ObjcDemo/Base.lproj/Main.storyboard new file mode 100644 index 0000000..9bc1c6d --- /dev/null +++ b/ObjcDemo/ObjcDemo/Base.lproj/Main.storyboard @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ObjcDemo/ObjcDemo/CustomShadowEffect.h b/ObjcDemo/ObjcDemo/CustomShadowEffect.h new file mode 100644 index 0000000..b66eae9 --- /dev/null +++ b/ObjcDemo/ObjcDemo/CustomShadowEffect.h @@ -0,0 +1,17 @@ +// +// CustomShadowEffect.h +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/18/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import +@import PullToDismiss; + +@interface CustomShadowEffect : NSObject +@property (nonatomic, strong) UIColor * _Nullable color; +@property (nonatomic) CGFloat alpha; +@property (nonatomic, readonly) enum BackgroundTarget target; + +@end diff --git a/ObjcDemo/ObjcDemo/CustomShadowEffect.m b/ObjcDemo/ObjcDemo/CustomShadowEffect.m new file mode 100644 index 0000000..44c58d1 --- /dev/null +++ b/ObjcDemo/ObjcDemo/CustomShadowEffect.m @@ -0,0 +1,25 @@ +// +// CustomShadowEffect.m +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/18/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import "CustomShadowEffect.h" +@import PullToDismiss; + +@implementation CustomShadowEffect + +- (UIView * _Nonnull)makeBackgroundView { + UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; + view.backgroundColor = self.color; + view.alpha = self.alpha; + return view; +} + +- (void)applyEffectWithView:(UIView * _Nullable)view rate:(CGFloat)rate { + view.alpha = self.alpha * rate; +} + +@end diff --git a/ObjcDemo/ObjcDemo/Info.plist b/ObjcDemo/ObjcDemo/Info.plist new file mode 100644 index 0000000..38e98af --- /dev/null +++ b/ObjcDemo/ObjcDemo/Info.plist @@ -0,0 +1,38 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSRequiresIPhoneOS + + UILaunchStoryboardName + LaunchScreen + UIMainStoryboardFile + Main + UIRequiredDeviceCapabilities + + armv7 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + + diff --git a/ObjcDemo/ObjcDemo/SampleTableViewController.h b/ObjcDemo/ObjcDemo/SampleTableViewController.h new file mode 100644 index 0000000..5c9dbdd --- /dev/null +++ b/ObjcDemo/ObjcDemo/SampleTableViewController.h @@ -0,0 +1,13 @@ +// +// SampleTableViewController.h +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import + +@interface SampleTableViewController : UITableViewController + +@end diff --git a/ObjcDemo/ObjcDemo/SampleTableViewController.m b/ObjcDemo/ObjcDemo/SampleTableViewController.m new file mode 100644 index 0000000..1acf502 --- /dev/null +++ b/ObjcDemo/ObjcDemo/SampleTableViewController.m @@ -0,0 +1,67 @@ +// +// SampleTableViewController.m +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import "SampleTableViewController.h" +@import PullToDismiss; +#import "CustomShadowEffect.h" + +@interface SampleTableViewController () +@property(nonatomic, nullable) PullToDismiss *pullToDismiss; +@end + +@implementation SampleTableViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"]; + self.pullToDismiss = [[PullToDismiss alloc] initWithScrollView:self.tableView]; + + self.pullToDismiss.edgeShadow = [EdgeShadow defaultEdgeShadow]; + self.pullToDismiss.delegate = self; + CustomShadowEffect *effect = [[CustomShadowEffect alloc] init]; + effect.alpha = 0.5; + effect.color = [UIColor purpleColor]; + self.pullToDismiss.backgroundEffect = effect; + self.pullToDismiss.dismissableHeightPercentage = 0.5f; + __weak typeof(self) wSelf = self; + self.pullToDismiss.dismissAction = ^{ + NSLog(@"!!!"); + [wSelf dismissViewControllerAnimated:YES completion:nil]; + }; +} + +- (void)didReceiveMemoryWarning { + [super didReceiveMemoryWarning]; + // Dispose of any resources that can be recreated. +} + +#pragma mark - Table view data source + +- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { + return 1; +} + +- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + return 100; +} + +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { + UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; + cell.textLabel.text = @(indexPath.row).stringValue; + return cell; +} + +- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { + UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"!!!" + message:@(indexPath.row).stringValue + preferredStyle:UIAlertControllerStyleAlert]; + [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil]]; + [self presentViewController:alert animated:YES completion:nil]; +} + +@end diff --git a/ObjcDemo/ObjcDemo/ViewController.h b/ObjcDemo/ObjcDemo/ViewController.h new file mode 100644 index 0000000..a168e74 --- /dev/null +++ b/ObjcDemo/ObjcDemo/ViewController.h @@ -0,0 +1,15 @@ +// +// ViewController.h +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import + +@interface ViewController : UIViewController + + +@end + diff --git a/ObjcDemo/ObjcDemo/ViewController.m b/ObjcDemo/ObjcDemo/ViewController.m new file mode 100644 index 0000000..f67956d --- /dev/null +++ b/ObjcDemo/ObjcDemo/ViewController.m @@ -0,0 +1,32 @@ +// +// ViewController.m +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import "ViewController.h" +#import "SampleTableViewController.h" + +@import PullToDismiss; + +@interface ViewController () +@property(nonatomic, weak) IBOutlet UIButton *button; +@end + +@implementation ViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + [self.button addTarget:self action:@selector(buttonDidTap:) forControlEvents:UIControlEventTouchUpInside]; +} + +- (void)buttonDidTap:(UIButton *)button { + SampleTableViewController *tableViewController = [[SampleTableViewController alloc] init]; + UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController]; + navigationController.modalPresentationStyle = UIModalPresentationOverCurrentContext; + [self presentViewController:navigationController animated:YES completion:nil]; +} + +@end diff --git a/ObjcDemo/ObjcDemo/main.m b/ObjcDemo/ObjcDemo/main.m new file mode 100644 index 0000000..0529ffc --- /dev/null +++ b/ObjcDemo/ObjcDemo/main.m @@ -0,0 +1,16 @@ +// +// main.m +// ObjcDemo +// +// Created by Suguru Kishimoto on 3/16/17. +// Copyright © 2017 Suguru Kishimoto. All rights reserved. +// + +#import +#import "AppDelegate.h" + +int main(int argc, char * argv[]) { + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/PullToDismiss.podspec b/PullToDismiss.podspec index 6751acb..de6bc68 100644 --- a/PullToDismiss.podspec +++ b/PullToDismiss.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "PullToDismiss" - s.version = "2.0" + s.version = "2.1" s.summary = "Dismiss ViewController by pulling scroll view or navigation bar in Swift." s.homepage = "https://github.com/sgr-ksmt/PullToDismiss" # s.screenshots = "" diff --git a/PullToDismiss.xcworkspace/contents.xcworkspacedata b/PullToDismiss.xcworkspace/contents.xcworkspacedata index 788a947..afe3e76 100644 --- a/PullToDismiss.xcworkspace/contents.xcworkspacedata +++ b/PullToDismiss.xcworkspace/contents.xcworkspacedata @@ -1,6 +1,9 @@ + + diff --git a/README.md b/README.md index 40e8b24..329ac5a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ PullToDismiss provides dismiss modal viewcontroller function like Facebook Messe - Available in UIViewController, UINavigationController. - Automatically add pan gesture to navigation bar. - Blur effect support. +- **Objective-C support.** (from *v2.1~*) ### Migration guide If you update from 1.x to 2.0, see [migration guide](Documents/PullToDismiss2MigrationGuide.md) if needed. @@ -135,7 +136,7 @@ pullToDismiss?.dismissableHeightPercentage = 0.5 - Add the following to your *Cartfile*: ```bash -github "sgr-ksmt/PullToDismiss" ~> 2.0 +github "sgr-ksmt/PullToDismiss" ~> 2.1 ``` - Run `carthage update` @@ -149,7 +150,7 @@ github "sgr-ksmt/PullToDismiss" ~> 2.0 it, simply add the following line to your Podfile: ```ruby -pod 'PullToDismiss', '~> 2.0' +pod 'PullToDismiss', '~> 2.1' ``` and run `pod install` diff --git a/Sources/BackgroundEffect.swift b/Sources/BackgroundEffect.swift index 9b295ff..49623ab 100644 --- a/Sources/BackgroundEffect.swift +++ b/Sources/BackgroundEffect.swift @@ -7,8 +7,9 @@ // import Foundation +import UIKit -public protocol BackgroundEffect { +@objc public protocol BackgroundEffect: NSObjectProtocol { var color: UIColor? { get set } var alpha: CGFloat { get set } var target: BackgroundTarget { get } @@ -21,23 +22,31 @@ public protocol BackgroundEffect { /// /// - targetViewController: add background view to target viewcontroller /// - presentingViewController: add background view to target viewcontroller's presenting viewcontroller -public enum BackgroundTarget { +@objc public enum BackgroundTarget: Int { case targetViewController case presentingViewController } -public struct ShadowEffect: BackgroundEffect { +public final class ShadowEffect: NSObject, BackgroundEffect { public var color: UIColor? public var alpha: CGFloat public var target: BackgroundTarget = .targetViewController - public static var `default`: ShadowEffect = ShadowEffect(color: .black, alpha: 0.8) + @objc(defaultShadowEffedt) + public static let `default`: ShadowEffect = ShadowEffect(color: .black, alpha: 0.8) public init(color: UIColor?, alpha: CGFloat) { self.color = color self.alpha = alpha } + // only Objective-C + @available(*, unavailable) + public class func shadowEffect(color: UIColor?, alpha: CGFloat) -> ShadowEffect { + return ShadowEffect(color: color, alpha: alpha) + } + + public func makeBackgroundView() -> UIView { let view = UIView(frame: .zero) view.backgroundColor = color @@ -51,7 +60,7 @@ public struct ShadowEffect: BackgroundEffect { } @available(iOS, introduced: 9.0) -public struct BlurEffect: BackgroundEffect { +public final class BlurEffect: NSObject, BackgroundEffect { public var color: UIColor? public var alpha: CGFloat public var blurRadius: CGFloat @@ -59,28 +68,32 @@ public struct BlurEffect: BackgroundEffect { public var target: BackgroundTarget = .presentingViewController - public static var `default`: BlurEffect = BlurEffect( + @objc(defaultBlur) + public static let `default`: BlurEffect = BlurEffect( color: nil, alpha: 0.0, blurRadius: 20.0, saturationDeltaFactor: 1.8 ) - public static var extraLight: BlurEffect = BlurEffect( + @objc(extraLightBlurEffect) + public static let extraLight: BlurEffect = BlurEffect( color: UIColor(white: 0.97, alpha: 0.82), alpha: 1.0, blurRadius: 20.0, saturationDeltaFactor: 1.8 ) - public static var light: BlurEffect = BlurEffect( + @objc(lightBlurEffect) + public static let light: BlurEffect = BlurEffect( color: UIColor(white: 1.0, alpha: 0.3), alpha: 1.0, blurRadius: 30.0, saturationDeltaFactor: 1.8 ) - public static var dark: BlurEffect = BlurEffect( + @objc(darkBlurEffect) + public static let dark: BlurEffect = BlurEffect( color: UIColor(white: 0.11, alpha: 0.73), alpha: 1.0, blurRadius: 20.0, @@ -94,6 +107,11 @@ public struct BlurEffect: BackgroundEffect { self.saturationDeltaFactor = saturationDeltaFactor } + // only Objective-C + @available(*, unavailable) + public class func blurEffect(color: UIColor?, alpha: CGFloat, blurRadius: CGFloat, saturationDeltaFactor: CGFloat) -> BlurEffect { + return BlurEffect(color: color, alpha: alpha, blurRadius: blurRadius, saturationDeltaFactor: saturationDeltaFactor) + } public func makeBackgroundView() -> UIView { let view = CustomBlurView(radius: blurRadius) diff --git a/Sources/EdgeShadow.swift b/Sources/EdgeShadow.swift index 64badd9..3eeaa81 100644 --- a/Sources/EdgeShadow.swift +++ b/Sources/EdgeShadow.swift @@ -9,13 +9,28 @@ import Foundation import UIKit -public struct EdgeShadow { - static let `default` = EdgeShadow( +public final class EdgeShadow: NSObject { + @objc(defaultEdgeShadow) + public static let `default` = EdgeShadow( opacity: 0.5, radius: 5.0, color: .black, offset: CGSize(width: 0.0, height: -5.0) ) - let opacity: Float - let radius: CGFloat - let color: UIColor - let offset: CGSize + public let opacity: Float + public let radius: CGFloat + public let color: UIColor + public let offset: CGSize + + public init(opacity: Float, radius: CGFloat, color: UIColor, offset: CGSize) { + self.opacity = opacity + self.radius = radius + self.color = color + self.offset = offset + super.init() + } + + // only Objective-C + @available(*, unavailable) + public class func edgeShadow(opacity: Float, radius: CGFloat, color: UIColor, offset: CGSize) -> EdgeShadow { + return EdgeShadow.init(opacity: opacity, radius: radius, color: color, offset: offset) + } } diff --git a/Sources/PullToDismiss.swift b/Sources/PullToDismiss.swift index 3c5b9ed..fbedb05 100644 --- a/Sources/PullToDismiss.swift +++ b/Sources/PullToDismiss.swift @@ -62,13 +62,15 @@ open class PullToDismiss: NSObject { public init(scrollView: UIScrollView, viewController: UIViewController, navigationBar: UIView? = nil) { super.init() - __scrollView = scrollView - proxy = ScrollViewDelegateProxy(delegates: [self]) + self.proxy = ScrollViewDelegateProxy(delegates: [self]) + self.__scrollView = scrollView + self.__scrollView?.delegate = self.proxy self.viewController = viewController + if let navigationBar = navigationBar ?? viewController.navigationController?.navigationBar { let gesture = UIPanGestureRecognizer(target: self, action: #selector(handlePanGesture(_:))) navigationBar.addGestureRecognizer(gesture) - navigationBarHeight = navigationBar.frame.height + self.navigationBarHeight = navigationBar.frame.height self.panGesture = gesture } }