├── .gitignore ├── .swift-version ├── ALRT.podspec ├── ALRT.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcshareddata │ └── xcschemes │ └── ALRT.xcscheme ├── ALRT ├── ALRT.h ├── ALRT.swift └── Info.plist ├── Demo ├── Demo.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ ├── Demo.xcscheme │ │ └── DemoUITests.xcscheme ├── Demo │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── DemoViewController.swift │ └── Info.plist └── DemoTests │ ├── DemoTests.swift │ └── Info.plist ├── LICENSE ├── README.md └── codecov.yml /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | *.DS_Store 5 | 6 | ## Build generated 7 | build/ 8 | DerivedData/ 9 | 10 | ## Various settings 11 | *.pbxuser 12 | !default.pbxuser 13 | *.mode1v3 14 | !default.mode1v3 15 | *.mode2v3 16 | !default.mode2v3 17 | *.perspectivev3 18 | !default.perspectivev3 19 | xcuserdata/ 20 | 21 | ## Other 22 | *.moved-aside 23 | *.xcuserstate 24 | 25 | ## Obj-C/Swift specific 26 | *.hmap 27 | *.ipa 28 | *.dSYM.zip 29 | *.dSYM 30 | 31 | ## Playgrounds 32 | timeline.xctimeline 33 | playground.xcworkspace 34 | 35 | # Swift Package Manager 36 | # 37 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 38 | # Packages/ 39 | .build/ 40 | 41 | # CocoaPods 42 | # 43 | # We recommend against adding the Pods directory to your .gitignore. However 44 | # you should judge for yourself, the pros and cons are mentioned at: 45 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 46 | # 47 | # Pods/ 48 | 49 | # Carthage 50 | # 51 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 52 | # Carthage/Checkouts 53 | 54 | Carthage/Build 55 | 56 | # fastlane 57 | # 58 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 59 | # screenshots whenever they are needed. 60 | # For more information about the recommended setup visit: 61 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 62 | 63 | fastlane/report.xml 64 | fastlane/Preview.html 65 | fastlane/screenshots 66 | fastlane/test_output 67 | -------------------------------------------------------------------------------- /.swift-version: -------------------------------------------------------------------------------- 1 | 5.0 -------------------------------------------------------------------------------- /ALRT.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ALRT" 3 | s.version = "1.3.7" 4 | s.summary = "An easier constructor for UIAlertController. Present from anywhere." 5 | s.homepage = "https://github.com/mshrwtnb/ALRT" 6 | s.screenshots = "https://raw.githubusercontent.com/wiki/mshrwtnb/ALRT/logobanner.png" 7 | s.license = { :type => "MIT", :file => "LICENSE" } 8 | s.author = { "Masahiro Watanabe" => "iammshr@gmail.com" } 9 | s.social_media_url = "https://mshrwtnb.com/" 10 | s.platform = :ios, "9.0" 11 | s.source = { :git => "https://github.com/mshrwtnb/ALRT.git", :tag => "#{s.version}" } 12 | s.source_files = "ALRT/*.swift" 13 | s.requires_arc = true 14 | end 15 | -------------------------------------------------------------------------------- /ALRT.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | DF17F7CC1D4C18B1001DF68B /* ALRT.h in Headers */ = {isa = PBXBuildFile; fileRef = DF17F7CB1D4C18B1001DF68B /* ALRT.h */; settings = {ATTRIBUTES = (Public, ); }; }; 11 | DF17F7F31D4C1BE3001DF68B /* ALRT.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF17F7F11D4C1BE3001DF68B /* ALRT.swift */; }; 12 | /* End PBXBuildFile section */ 13 | 14 | /* Begin PBXFileReference section */ 15 | DF17F7C81D4C18B1001DF68B /* ALRT.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ALRT.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 16 | DF17F7CB1D4C18B1001DF68B /* ALRT.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ALRT.h; sourceTree = ""; }; 17 | DF17F7CD1D4C18B1001DF68B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 18 | DF17F7F11D4C1BE3001DF68B /* ALRT.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ALRT.swift; sourceTree = ""; }; 19 | /* End PBXFileReference section */ 20 | 21 | /* Begin PBXFrameworksBuildPhase section */ 22 | DF17F7C41D4C18B1001DF68B /* Frameworks */ = { 23 | isa = PBXFrameworksBuildPhase; 24 | buildActionMask = 2147483647; 25 | files = ( 26 | ); 27 | runOnlyForDeploymentPostprocessing = 0; 28 | }; 29 | /* End PBXFrameworksBuildPhase section */ 30 | 31 | /* Begin PBXGroup section */ 32 | DF17F7BE1D4C18B1001DF68B = { 33 | isa = PBXGroup; 34 | children = ( 35 | DF17F7CA1D4C18B1001DF68B /* ALRT */, 36 | DF17F7C91D4C18B1001DF68B /* Products */, 37 | ); 38 | sourceTree = ""; 39 | }; 40 | DF17F7C91D4C18B1001DF68B /* Products */ = { 41 | isa = PBXGroup; 42 | children = ( 43 | DF17F7C81D4C18B1001DF68B /* ALRT.framework */, 44 | ); 45 | name = Products; 46 | sourceTree = ""; 47 | }; 48 | DF17F7CA1D4C18B1001DF68B /* ALRT */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | DF17F7F11D4C1BE3001DF68B /* ALRT.swift */, 52 | DF17F7CB1D4C18B1001DF68B /* ALRT.h */, 53 | DF17F7CD1D4C18B1001DF68B /* Info.plist */, 54 | ); 55 | path = ALRT; 56 | sourceTree = ""; 57 | }; 58 | /* End PBXGroup section */ 59 | 60 | /* Begin PBXHeadersBuildPhase section */ 61 | DF17F7C51D4C18B1001DF68B /* Headers */ = { 62 | isa = PBXHeadersBuildPhase; 63 | buildActionMask = 2147483647; 64 | files = ( 65 | DF17F7CC1D4C18B1001DF68B /* ALRT.h in Headers */, 66 | ); 67 | runOnlyForDeploymentPostprocessing = 0; 68 | }; 69 | /* End PBXHeadersBuildPhase section */ 70 | 71 | /* Begin PBXNativeTarget section */ 72 | DF17F7C71D4C18B1001DF68B /* ALRT */ = { 73 | isa = PBXNativeTarget; 74 | buildConfigurationList = DF17F7D01D4C18B1001DF68B /* Build configuration list for PBXNativeTarget "ALRT" */; 75 | buildPhases = ( 76 | DF17F7C31D4C18B1001DF68B /* Sources */, 77 | DF17F7C41D4C18B1001DF68B /* Frameworks */, 78 | DF17F7C51D4C18B1001DF68B /* Headers */, 79 | DF17F7C61D4C18B1001DF68B /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = ALRT; 86 | productName = ALRT; 87 | productReference = DF17F7C81D4C18B1001DF68B /* ALRT.framework */; 88 | productType = "com.apple.product-type.framework"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | DF17F7BF1D4C18B1001DF68B /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastUpgradeCheck = 0930; 97 | ORGANIZATIONNAME = "Masahiro Watanabe"; 98 | TargetAttributes = { 99 | DF17F7C71D4C18B1001DF68B = { 100 | CreatedOnToolsVersion = 7.3.1; 101 | LastSwiftMigration = 0800; 102 | }; 103 | }; 104 | }; 105 | buildConfigurationList = DF17F7C21D4C18B1001DF68B /* Build configuration list for PBXProject "ALRT" */; 106 | compatibilityVersion = "Xcode 3.2"; 107 | developmentRegion = English; 108 | hasScannedForEncodings = 0; 109 | knownRegions = ( 110 | English, 111 | en, 112 | ); 113 | mainGroup = DF17F7BE1D4C18B1001DF68B; 114 | productRefGroup = DF17F7C91D4C18B1001DF68B /* Products */; 115 | projectDirPath = ""; 116 | projectRoot = ""; 117 | targets = ( 118 | DF17F7C71D4C18B1001DF68B /* ALRT */, 119 | ); 120 | }; 121 | /* End PBXProject section */ 122 | 123 | /* Begin PBXResourcesBuildPhase section */ 124 | DF17F7C61D4C18B1001DF68B /* Resources */ = { 125 | isa = PBXResourcesBuildPhase; 126 | buildActionMask = 2147483647; 127 | files = ( 128 | ); 129 | runOnlyForDeploymentPostprocessing = 0; 130 | }; 131 | /* End PBXResourcesBuildPhase section */ 132 | 133 | /* Begin PBXSourcesBuildPhase section */ 134 | DF17F7C31D4C18B1001DF68B /* Sources */ = { 135 | isa = PBXSourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | DF17F7F31D4C1BE3001DF68B /* ALRT.swift in Sources */, 139 | ); 140 | runOnlyForDeploymentPostprocessing = 0; 141 | }; 142 | /* End PBXSourcesBuildPhase section */ 143 | 144 | /* Begin XCBuildConfiguration section */ 145 | DF17F7CE1D4C18B1001DF68B /* Debug */ = { 146 | isa = XCBuildConfiguration; 147 | buildSettings = { 148 | ALWAYS_SEARCH_USER_PATHS = NO; 149 | CLANG_ANALYZER_NONNULL = YES; 150 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 151 | CLANG_CXX_LIBRARY = "libc++"; 152 | CLANG_ENABLE_MODULES = YES; 153 | CLANG_ENABLE_OBJC_ARC = YES; 154 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 155 | CLANG_WARN_BOOL_CONVERSION = YES; 156 | CLANG_WARN_COMMA = YES; 157 | CLANG_WARN_CONSTANT_CONVERSION = YES; 158 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 159 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 160 | CLANG_WARN_EMPTY_BODY = YES; 161 | CLANG_WARN_ENUM_CONVERSION = YES; 162 | CLANG_WARN_INFINITE_RECURSION = YES; 163 | CLANG_WARN_INT_CONVERSION = YES; 164 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 165 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 166 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 167 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 168 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 169 | CLANG_WARN_STRICT_PROTOTYPES = YES; 170 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 171 | CLANG_WARN_UNREACHABLE_CODE = YES; 172 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 173 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 174 | COPY_PHASE_STRIP = NO; 175 | CURRENT_PROJECT_VERSION = 1; 176 | DEBUG_INFORMATION_FORMAT = dwarf; 177 | ENABLE_STRICT_OBJC_MSGSEND = YES; 178 | ENABLE_TESTABILITY = YES; 179 | GCC_C_LANGUAGE_STANDARD = gnu99; 180 | GCC_DYNAMIC_NO_PIC = NO; 181 | GCC_NO_COMMON_BLOCKS = YES; 182 | GCC_OPTIMIZATION_LEVEL = 0; 183 | GCC_PREPROCESSOR_DEFINITIONS = ( 184 | "DEBUG=1", 185 | "$(inherited)", 186 | ); 187 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 188 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 189 | GCC_WARN_UNDECLARED_SELECTOR = YES; 190 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 191 | GCC_WARN_UNUSED_FUNCTION = YES; 192 | GCC_WARN_UNUSED_VARIABLE = YES; 193 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 194 | MTL_ENABLE_DEBUG_INFO = YES; 195 | ONLY_ACTIVE_ARCH = YES; 196 | SDKROOT = iphoneos; 197 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 198 | SWIFT_VERSION = 5.0; 199 | TARGETED_DEVICE_FAMILY = "1,2"; 200 | VERSIONING_SYSTEM = "apple-generic"; 201 | VERSION_INFO_PREFIX = ""; 202 | }; 203 | name = Debug; 204 | }; 205 | DF17F7CF1D4C18B1001DF68B /* Release */ = { 206 | isa = XCBuildConfiguration; 207 | buildSettings = { 208 | ALWAYS_SEARCH_USER_PATHS = NO; 209 | CLANG_ANALYZER_NONNULL = YES; 210 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 211 | CLANG_CXX_LIBRARY = "libc++"; 212 | CLANG_ENABLE_MODULES = YES; 213 | CLANG_ENABLE_OBJC_ARC = YES; 214 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 215 | CLANG_WARN_BOOL_CONVERSION = YES; 216 | CLANG_WARN_COMMA = YES; 217 | CLANG_WARN_CONSTANT_CONVERSION = YES; 218 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 219 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 220 | CLANG_WARN_EMPTY_BODY = YES; 221 | CLANG_WARN_ENUM_CONVERSION = YES; 222 | CLANG_WARN_INFINITE_RECURSION = YES; 223 | CLANG_WARN_INT_CONVERSION = YES; 224 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 225 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 226 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 227 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 228 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 229 | CLANG_WARN_STRICT_PROTOTYPES = YES; 230 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 231 | CLANG_WARN_UNREACHABLE_CODE = YES; 232 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 233 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 234 | COPY_PHASE_STRIP = NO; 235 | CURRENT_PROJECT_VERSION = 1; 236 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 237 | ENABLE_NS_ASSERTIONS = NO; 238 | ENABLE_STRICT_OBJC_MSGSEND = YES; 239 | GCC_C_LANGUAGE_STANDARD = gnu99; 240 | GCC_NO_COMMON_BLOCKS = YES; 241 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 242 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 243 | GCC_WARN_UNDECLARED_SELECTOR = YES; 244 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 245 | GCC_WARN_UNUSED_FUNCTION = YES; 246 | GCC_WARN_UNUSED_VARIABLE = YES; 247 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 248 | MTL_ENABLE_DEBUG_INFO = NO; 249 | SDKROOT = iphoneos; 250 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 251 | SWIFT_VERSION = 5.0; 252 | TARGETED_DEVICE_FAMILY = "1,2"; 253 | VALIDATE_PRODUCT = YES; 254 | VERSIONING_SYSTEM = "apple-generic"; 255 | VERSION_INFO_PREFIX = ""; 256 | }; 257 | name = Release; 258 | }; 259 | DF17F7D11D4C18B1001DF68B /* Debug */ = { 260 | isa = XCBuildConfiguration; 261 | buildSettings = { 262 | CLANG_ENABLE_MODULES = YES; 263 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 264 | DEFINES_MODULE = YES; 265 | DYLIB_COMPATIBILITY_VERSION = 1; 266 | DYLIB_CURRENT_VERSION = 1; 267 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 268 | GCC_GENERATE_TEST_COVERAGE_FILES = NO; 269 | INFOPLIST_FILE = ALRT/Info.plist; 270 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 271 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 272 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 273 | MARKETING_VERSION = 1.3.7; 274 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.ALRT; 275 | PRODUCT_NAME = "$(TARGET_NAME)"; 276 | SKIP_INSTALL = YES; 277 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 278 | SWIFT_VERSION = 5.0; 279 | }; 280 | name = Debug; 281 | }; 282 | DF17F7D21D4C18B1001DF68B /* Release */ = { 283 | isa = XCBuildConfiguration; 284 | buildSettings = { 285 | CLANG_ENABLE_MODULES = YES; 286 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 287 | DEFINES_MODULE = YES; 288 | DYLIB_COMPATIBILITY_VERSION = 1; 289 | DYLIB_CURRENT_VERSION = 1; 290 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 291 | GCC_GENERATE_TEST_COVERAGE_FILES = NO; 292 | INFOPLIST_FILE = ALRT/Info.plist; 293 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 294 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 295 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 296 | MARKETING_VERSION = 1.3.7; 297 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.ALRT; 298 | PRODUCT_NAME = "$(TARGET_NAME)"; 299 | SKIP_INSTALL = YES; 300 | SWIFT_VERSION = 5.0; 301 | }; 302 | name = Release; 303 | }; 304 | /* End XCBuildConfiguration section */ 305 | 306 | /* Begin XCConfigurationList section */ 307 | DF17F7C21D4C18B1001DF68B /* Build configuration list for PBXProject "ALRT" */ = { 308 | isa = XCConfigurationList; 309 | buildConfigurations = ( 310 | DF17F7CE1D4C18B1001DF68B /* Debug */, 311 | DF17F7CF1D4C18B1001DF68B /* Release */, 312 | ); 313 | defaultConfigurationIsVisible = 0; 314 | defaultConfigurationName = Release; 315 | }; 316 | DF17F7D01D4C18B1001DF68B /* Build configuration list for PBXNativeTarget "ALRT" */ = { 317 | isa = XCConfigurationList; 318 | buildConfigurations = ( 319 | DF17F7D11D4C18B1001DF68B /* Debug */, 320 | DF17F7D21D4C18B1001DF68B /* Release */, 321 | ); 322 | defaultConfigurationIsVisible = 0; 323 | defaultConfigurationName = Release; 324 | }; 325 | /* End XCConfigurationList section */ 326 | }; 327 | rootObject = DF17F7BF1D4C18B1001DF68B /* Project object */; 328 | } 329 | -------------------------------------------------------------------------------- /ALRT.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ALRT.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ALRT.xcodeproj/xcshareddata/xcschemes/ALRT.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 34 | 35 | 45 | 46 | 52 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 70 | 71 | 72 | 73 | 75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /ALRT/ALRT.h: -------------------------------------------------------------------------------- 1 | // 2 | // ALRT.h 3 | // ALRT 4 | // 5 | // Created by Masahiro Watanabe on 7/30/16. 6 | // Copyright © 2016 Masahiro Watanabe. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ALRT. 12 | FOUNDATION_EXPORT double ALRTVersionNumber; 13 | 14 | //! Project version string for ALRT. 15 | FOUNDATION_EXPORT const unsigned char ALRTVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ALRT/ALRT.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | /// Responsible for creating and managing an ALRT object. 4 | 5 | public class ALRT { 6 | /** 7 | Configuration struct to define default tintColor for buttons, ok button title and cancel button title. 8 | Use `defaultConfiguration` 9 | */ 10 | public struct Configuration { 11 | public var tintColor: UIColor? 12 | public var okTitle: String? 13 | public var cancelTitle: String? 14 | 15 | public init( 16 | tintColor: UIColor?, 17 | okTitle: String?, 18 | cancelTitle: String? 19 | ) { 20 | self.tintColor = tintColor 21 | self.okTitle = okTitle 22 | self.cancelTitle = cancelTitle 23 | } 24 | } 25 | 26 | /** 27 | Result indicating whether the alert is displayed or not. 28 | 29 | - success: The alert is displayed. 30 | - failure: The alert is not displayed due to an ALRTError. 31 | */ 32 | 33 | public enum Result { 34 | case success 35 | case failure(ALRTError) 36 | } 37 | 38 | /** 39 | ALRTError enums. 40 | 41 | - alertControllerNil: The alert controller is nil. 42 | - popoverNotSet: An attempt to show .ActionSheet type alert controller failed because the popover presentation controller has not been set up. 43 | */ 44 | 45 | public enum ALRTError: Error { 46 | case alertControllerNil 47 | case popoverNotSet 48 | case sourceViewControllerNil 49 | } 50 | 51 | public static var defaultConfiguration: Configuration? 52 | 53 | public var alertController: UIAlertController? 54 | 55 | private init() {} 56 | 57 | private init( 58 | title: String?, 59 | message: String?, 60 | preferredStyle: UIAlertController.Style 61 | ) { 62 | let alertController = UIAlertController( 63 | title: title, 64 | message: message, 65 | preferredStyle: preferredStyle 66 | ) 67 | 68 | if let tintColor = ALRT.defaultConfiguration?.tintColor { 69 | alertController.view.tintColor = tintColor 70 | } 71 | 72 | self.alertController = alertController 73 | } 74 | 75 | // MARK: Creating an ALRT 76 | 77 | /** 78 | Creates an ALRT object. 79 | 80 | - parameter style: UIAlertControllerStyle constants indicating the type of alert to display. 81 | - parameter title: The title of the alert. 82 | - parameter message: The message of the alert. 83 | 84 | - returns: ALRT 85 | */ 86 | 87 | public class func create( 88 | _ style: UIAlertController.Style, 89 | title: String? = nil, 90 | message: String? = nil 91 | ) -> ALRT { 92 | return ALRT(title: title, message: message, preferredStyle: style) 93 | } 94 | 95 | // MARK: Fetching the Alert 96 | 97 | /** 98 | Fetches the ALRT object's alert controller. 99 | 100 | - parameter handler: A block for fetching the alert controller. This block has no return value and takes the alert controller. 101 | 102 | - returns: Self 103 | */ 104 | 105 | @discardableResult 106 | public func fetch(_ handler: (_ alertController: UIAlertController?) -> Void) -> Self { 107 | handler(alertController) 108 | return self 109 | } 110 | 111 | // MARK: Configuring Text Fields 112 | 113 | /** 114 | Adds a text field to an alert. 115 | 116 | - parameter configurationHandler: A block for configuring the text field prior to displaying the alert. This block has no return value and takes a single parameter corresponding to the text field object. Use that parameter to change the text field properties. 117 | 118 | - returns: Self 119 | */ 120 | 121 | @discardableResult 122 | public func addTextField(_ configurationHandler: ((_ textField: UITextField) -> Void)?) -> Self { 123 | guard alertController?.preferredStyle == .alert else { 124 | return self 125 | } 126 | 127 | alertController?.addTextField { textField in 128 | if let configurationHandler = configurationHandler { 129 | configurationHandler(textField) 130 | } 131 | } 132 | 133 | return self 134 | } 135 | 136 | // MARK: Configuring Customizable User Actions 137 | 138 | /** 139 | Attaches an action object to the alert or action sheet. 140 | 141 | - parameter title: The title of the action’s button. 142 | - parameter style: The style that is applied to the action’s button. The default value is .Default. 143 | - parameter preferred: The preferred action for the user to take from an alert(iOS 9 or later). The default value is false. 144 | - parameter handler: A block to execute when the user selects the action. This block has no return value and take the selected action object and the text fields added to the alert controller if any. The default value is nil. 145 | 146 | - returns: Self 147 | */ 148 | 149 | @discardableResult 150 | public func addAction( 151 | _ title: String?, 152 | style: UIAlertAction.Style = .default, 153 | preferred: Bool = false, 154 | handler: ((_ action: UIAlertAction, _ textFields: [UITextField]?) -> Void)? = nil 155 | ) -> Self { 156 | let action = UIAlertAction(title: title, style: style) { action in 157 | handler?(action, self.alertController?.preferredStyle == .alert ? self.alertController?.textFields : nil) 158 | self.alertController = nil 159 | } 160 | 161 | alertController?.addAction(action) 162 | 163 | if preferred { 164 | alertController?.preferredAction = action 165 | } 166 | 167 | return self 168 | } 169 | 170 | // MARK: Configuring Pre-defined User Actions 171 | 172 | /** 173 | Attaches an action object to the alert or action sheet. The default title is "OK". 174 | 175 | - parameter title: The title of the action’s button. The default value is "OK". 176 | - parameter style: The style that is applied to the action’s button. The default value is .Default. 177 | - parameter preferred: The preferred action for the user to take from an alert(iOS 9 or later). The default value is false. 178 | - parameter handler: A block to execute when the user selects the action. This block has no return value and take the selected action object and the text fields added to the alert controller if any. The default value is nil. 179 | 180 | - returns: Self 181 | */ 182 | 183 | @discardableResult 184 | public func addOK( 185 | _ title: String = ALRT.defaultConfiguration?.okTitle ?? "OK", 186 | style: UIAlertAction.Style = .default, 187 | preferred: Bool = false, 188 | handler: ((_ action: UIAlertAction, _ textFields: [UITextField]?) -> Void)? = nil 189 | ) -> Self { 190 | return addAction(title, style: style, preferred: preferred, handler: handler) 191 | } 192 | 193 | /** 194 | Attaches an action object to the alert or action sheet. The default title is "Cancel". 195 | 196 | - parameter title: The title of the action’s button. The default value is "Cancel". 197 | - parameter style: The style that is applied to the action’s button. The default value is .Cancel. 198 | - parameter preferred: The preferred action for the user to take from an alert(iOS 9 or later). The default value is false. 199 | - parameter handler: A block to execute when the user selects the action. This block has no return value and take the selected action object and the text fields added to the alert controller if any. The default value is nil. 200 | 201 | - returns: Self 202 | */ 203 | 204 | @discardableResult 205 | public func addCancel( 206 | _ title: String = ALRT.defaultConfiguration?.cancelTitle ?? "Cancel", 207 | style: UIAlertAction.Style = .cancel, 208 | preferred: Bool = false, 209 | handler: ((_ action: UIAlertAction, _ textFields: [UITextField]?) -> Void)? = nil 210 | ) -> Self { 211 | return addAction(title, style: style, preferred: preferred, handler: handler) 212 | } 213 | 214 | /** 215 | Attaches an action object to the alert or action sheet. The default style is .Destructive. 216 | 217 | - parameter title: The title of the action’s button. 218 | - parameter style: The style that is applied to the action’s button. The default value is .Destructive. 219 | - parameter preferred: The preferred action for the user to take from an alert(iOS 9 or later). The default value is false. 220 | - parameter handler: A block to execute when the user selects the action. This block has no return value and take the selected action object and the text fields added to the alert controller if any. The default value is nil. 221 | 222 | - returns: Self 223 | */ 224 | 225 | @discardableResult 226 | public func addDestructive( 227 | _ title: String?, 228 | style: UIAlertAction.Style = .destructive, 229 | preferred: Bool = false, 230 | handler: ((_ action: UIAlertAction, _ textFields: [UITextField]?) -> Void)? = nil 231 | ) -> Self { 232 | return addAction(title, style: style, preferred: preferred, handler: handler) 233 | } 234 | 235 | // MARK: Configuring the Popover Presentation 236 | 237 | /** Configures the alert controller's popover presentation controller. 238 | 239 | - parameter configurationHandler: A block for configuring the popover presentation controller. This block has no return value and take the alert controller's popover presentation controller. If the alert controller's style is .ActionSheet and the device is iPad, this configuration is necessary. 240 | 241 | - returns: Self 242 | */ 243 | 244 | @discardableResult 245 | public func configurePopoverPresentation(_ configurationHandler: ((_ popover: UIPopoverPresentationController?) -> Void)? = nil) -> Self { 246 | configurationHandler?(alertController?.popoverPresentationController) 247 | return self 248 | } 249 | 250 | // MARK: Showing the Alert 251 | 252 | /** 253 | Displays the alert or action sheet. 254 | 255 | - parameter viewControllerToPresent: The view controller to display the alert from. The default value is nil. If the parameter is not given, the key window's root view controller will present the alert. 256 | - parameter animated: Pass true to animate the presentation; otherwise, pass false. The default value is true. 257 | - parameter completion: The block to execute after the presentation finishes. This block has no return value and takes an Result parameter. The default value is nil. 258 | */ 259 | 260 | public func show( 261 | _ viewControllerToPresent: UIViewController? = nil, 262 | animated: Bool = true, 263 | completion: @escaping ((ALRT.Result) -> Void) = { _ in } 264 | ) { 265 | guard let alert = alertController else { 266 | completion(.failure(.alertControllerNil)) 267 | return 268 | } 269 | 270 | if UIDevice.current.userInterfaceIdiom == .pad, 271 | alert.preferredStyle == .actionSheet, 272 | alert.popoverPresentationController?.sourceView == nil, 273 | alert.popoverPresentationController?.barButtonItem == nil { 274 | completion(.failure(.popoverNotSet)) 275 | return 276 | } 277 | 278 | let sourceViewController: UIViewController? = { 279 | let viewController = viewControllerToPresent ?? UIApplication.shared.topMostViewController() 280 | if let navigationController = viewController as? UINavigationController { 281 | return navigationController.visibleViewController 282 | } 283 | return viewController 284 | }() 285 | 286 | guard let source = sourceViewController else { 287 | completion(.failure(.sourceViewControllerNil)) 288 | return 289 | } 290 | 291 | source.present(alert, animated: animated) { 292 | if let tintColor = ALRT.defaultConfiguration?.tintColor { 293 | alert.view.tintColor = tintColor 294 | } 295 | completion(.success) 296 | } 297 | } 298 | } 299 | 300 | private extension UIViewController { 301 | func topMostViewController() -> UIViewController { 302 | if let presented = presentedViewController { 303 | return presented.topMostViewController() 304 | } 305 | 306 | if let navigation = self as? UINavigationController { 307 | return navigation.visibleViewController?.topMostViewController() ?? navigation 308 | } 309 | 310 | if let tab = self as? UITabBarController { 311 | return tab.selectedViewController?.topMostViewController() ?? tab 312 | } 313 | 314 | return self 315 | } 316 | } 317 | 318 | private extension UIApplication { 319 | func topMostViewController() -> UIViewController? { 320 | guard let keyWindow = windows.first(where: { $0.isKeyWindow }) else { 321 | return nil 322 | } 323 | return keyWindow.rootViewController?.topMostViewController() 324 | } 325 | } 326 | -------------------------------------------------------------------------------- /ALRT/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $(CURRENT_PROJECT_VERSION) 23 | NSPrincipalClass 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 10F423C4217F55D50052F823 /* DemoTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 10F423C3217F55D50052F823 /* DemoTests.swift */; }; 11 | DF17F7E01D4C18DE001DF68B /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF17F7DF1D4C18DE001DF68B /* AppDelegate.swift */; }; 12 | DF17F7E21D4C18DE001DF68B /* DemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF17F7E11D4C18DE001DF68B /* DemoViewController.swift */; }; 13 | DF17F7E51D4C18DE001DF68B /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DF17F7E31D4C18DE001DF68B /* Main.storyboard */; }; 14 | DF17F7E71D4C18DE001DF68B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = DF17F7E61D4C18DE001DF68B /* Assets.xcassets */; }; 15 | DF17F7EA1D4C18DE001DF68B /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = DF17F7E81D4C18DE001DF68B /* LaunchScreen.storyboard */; }; 16 | DF17F8001D4C228F001DF68B /* ALRT.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF17F7FD1D4C228F001DF68B /* ALRT.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXContainerItemProxy section */ 20 | 10F423C6217F55D50052F823 /* PBXContainerItemProxy */ = { 21 | isa = PBXContainerItemProxy; 22 | containerPortal = DF17F7D41D4C18DE001DF68B /* Project object */; 23 | proxyType = 1; 24 | remoteGlobalIDString = DF17F7DB1D4C18DE001DF68B; 25 | remoteInfo = Demo; 26 | }; 27 | /* End PBXContainerItemProxy section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | 10F423C1217F55D50052F823 /* DemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = DemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 31 | 10F423C3217F55D50052F823 /* DemoTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoTests.swift; sourceTree = ""; }; 32 | 10F423C5217F55D50052F823 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | DF17F7DC1D4C18DE001DF68B /* Demo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Demo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 34 | DF17F7DF1D4C18DE001DF68B /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 35 | DF17F7E11D4C18DE001DF68B /* DemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoViewController.swift; sourceTree = ""; }; 36 | DF17F7E41D4C18DE001DF68B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 37 | DF17F7E61D4C18DE001DF68B /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 38 | DF17F7E91D4C18DE001DF68B /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 39 | DF17F7EB1D4C18DE001DF68B /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 40 | DF17F7FB1D4C228F001DF68B /* ALRT.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ALRT.h; sourceTree = ""; }; 41 | DF17F7FD1D4C228F001DF68B /* ALRT.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ALRT.swift; sourceTree = ""; }; 42 | DF17F7FE1D4C228F001DF68B /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 43 | /* End PBXFileReference section */ 44 | 45 | /* Begin PBXFrameworksBuildPhase section */ 46 | 10F423BE217F55D50052F823 /* Frameworks */ = { 47 | isa = PBXFrameworksBuildPhase; 48 | buildActionMask = 2147483647; 49 | files = ( 50 | ); 51 | runOnlyForDeploymentPostprocessing = 0; 52 | }; 53 | DF17F7D91D4C18DE001DF68B /* Frameworks */ = { 54 | isa = PBXFrameworksBuildPhase; 55 | buildActionMask = 2147483647; 56 | files = ( 57 | ); 58 | runOnlyForDeploymentPostprocessing = 0; 59 | }; 60 | /* End PBXFrameworksBuildPhase section */ 61 | 62 | /* Begin PBXGroup section */ 63 | 10F423C2217F55D50052F823 /* DemoTests */ = { 64 | isa = PBXGroup; 65 | children = ( 66 | 10F423C3217F55D50052F823 /* DemoTests.swift */, 67 | 10F423C5217F55D50052F823 /* Info.plist */, 68 | ); 69 | path = DemoTests; 70 | sourceTree = ""; 71 | }; 72 | DF17F7D31D4C18DE001DF68B = { 73 | isa = PBXGroup; 74 | children = ( 75 | DF17F7FA1D4C228F001DF68B /* ALRT */, 76 | DF17F7DE1D4C18DE001DF68B /* Demo */, 77 | 10F423C2217F55D50052F823 /* DemoTests */, 78 | DF17F7DD1D4C18DE001DF68B /* Products */, 79 | ); 80 | sourceTree = ""; 81 | }; 82 | DF17F7DD1D4C18DE001DF68B /* Products */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | DF17F7DC1D4C18DE001DF68B /* Demo.app */, 86 | 10F423C1217F55D50052F823 /* DemoTests.xctest */, 87 | ); 88 | name = Products; 89 | sourceTree = ""; 90 | }; 91 | DF17F7DE1D4C18DE001DF68B /* Demo */ = { 92 | isa = PBXGroup; 93 | children = ( 94 | DF17F7DF1D4C18DE001DF68B /* AppDelegate.swift */, 95 | DF17F7E11D4C18DE001DF68B /* DemoViewController.swift */, 96 | DF17F7E31D4C18DE001DF68B /* Main.storyboard */, 97 | DF17F7E61D4C18DE001DF68B /* Assets.xcassets */, 98 | DF17F7E81D4C18DE001DF68B /* LaunchScreen.storyboard */, 99 | DF17F7EB1D4C18DE001DF68B /* Info.plist */, 100 | ); 101 | path = Demo; 102 | sourceTree = ""; 103 | }; 104 | DF17F7FA1D4C228F001DF68B /* ALRT */ = { 105 | isa = PBXGroup; 106 | children = ( 107 | DF17F7FB1D4C228F001DF68B /* ALRT.h */, 108 | DF17F7FD1D4C228F001DF68B /* ALRT.swift */, 109 | DF17F7FE1D4C228F001DF68B /* Info.plist */, 110 | ); 111 | name = ALRT; 112 | path = ../ALRT; 113 | sourceTree = ""; 114 | }; 115 | /* End PBXGroup section */ 116 | 117 | /* Begin PBXNativeTarget section */ 118 | 10F423C0217F55D50052F823 /* DemoTests */ = { 119 | isa = PBXNativeTarget; 120 | buildConfigurationList = 10F423CA217F55D50052F823 /* Build configuration list for PBXNativeTarget "DemoTests" */; 121 | buildPhases = ( 122 | 10F423BD217F55D50052F823 /* Sources */, 123 | 10F423BE217F55D50052F823 /* Frameworks */, 124 | 10F423BF217F55D50052F823 /* Resources */, 125 | ); 126 | buildRules = ( 127 | ); 128 | dependencies = ( 129 | 10F423C7217F55D50052F823 /* PBXTargetDependency */, 130 | ); 131 | name = DemoTests; 132 | productName = DemoTests; 133 | productReference = 10F423C1217F55D50052F823 /* DemoTests.xctest */; 134 | productType = "com.apple.product-type.bundle.unit-test"; 135 | }; 136 | DF17F7DB1D4C18DE001DF68B /* Demo */ = { 137 | isa = PBXNativeTarget; 138 | buildConfigurationList = DF17F7EE1D4C18DE001DF68B /* Build configuration list for PBXNativeTarget "Demo" */; 139 | buildPhases = ( 140 | DF17F7D81D4C18DE001DF68B /* Sources */, 141 | DF17F7D91D4C18DE001DF68B /* Frameworks */, 142 | DF17F7DA1D4C18DE001DF68B /* Resources */, 143 | ); 144 | buildRules = ( 145 | ); 146 | dependencies = ( 147 | ); 148 | name = Demo; 149 | productName = Demo; 150 | productReference = DF17F7DC1D4C18DE001DF68B /* Demo.app */; 151 | productType = "com.apple.product-type.application"; 152 | }; 153 | /* End PBXNativeTarget section */ 154 | 155 | /* Begin PBXProject section */ 156 | DF17F7D41D4C18DE001DF68B /* Project object */ = { 157 | isa = PBXProject; 158 | attributes = { 159 | LastSwiftUpdateCheck = 1000; 160 | LastUpgradeCheck = 1020; 161 | ORGANIZATIONNAME = "Masahiro Watanabe"; 162 | TargetAttributes = { 163 | 10F423C0217F55D50052F823 = { 164 | CreatedOnToolsVersion = 10.0; 165 | DevelopmentTeam = L28L2GWTEW; 166 | LastSwiftMigration = 1020; 167 | ProvisioningStyle = Automatic; 168 | TestTargetID = DF17F7DB1D4C18DE001DF68B; 169 | }; 170 | DF17F7DB1D4C18DE001DF68B = { 171 | CreatedOnToolsVersion = 7.3.1; 172 | DevelopmentTeam = L28L2GWTEW; 173 | LastSwiftMigration = 0800; 174 | }; 175 | }; 176 | }; 177 | buildConfigurationList = DF17F7D71D4C18DE001DF68B /* Build configuration list for PBXProject "Demo" */; 178 | compatibilityVersion = "Xcode 3.2"; 179 | developmentRegion = en; 180 | hasScannedForEncodings = 0; 181 | knownRegions = ( 182 | en, 183 | Base, 184 | ); 185 | mainGroup = DF17F7D31D4C18DE001DF68B; 186 | productRefGroup = DF17F7DD1D4C18DE001DF68B /* Products */; 187 | projectDirPath = ""; 188 | projectRoot = ""; 189 | targets = ( 190 | DF17F7DB1D4C18DE001DF68B /* Demo */, 191 | 10F423C0217F55D50052F823 /* DemoTests */, 192 | ); 193 | }; 194 | /* End PBXProject section */ 195 | 196 | /* Begin PBXResourcesBuildPhase section */ 197 | 10F423BF217F55D50052F823 /* Resources */ = { 198 | isa = PBXResourcesBuildPhase; 199 | buildActionMask = 2147483647; 200 | files = ( 201 | ); 202 | runOnlyForDeploymentPostprocessing = 0; 203 | }; 204 | DF17F7DA1D4C18DE001DF68B /* Resources */ = { 205 | isa = PBXResourcesBuildPhase; 206 | buildActionMask = 2147483647; 207 | files = ( 208 | DF17F7EA1D4C18DE001DF68B /* LaunchScreen.storyboard in Resources */, 209 | DF17F7E71D4C18DE001DF68B /* Assets.xcassets in Resources */, 210 | DF17F7E51D4C18DE001DF68B /* Main.storyboard in Resources */, 211 | ); 212 | runOnlyForDeploymentPostprocessing = 0; 213 | }; 214 | /* End PBXResourcesBuildPhase section */ 215 | 216 | /* Begin PBXSourcesBuildPhase section */ 217 | 10F423BD217F55D50052F823 /* Sources */ = { 218 | isa = PBXSourcesBuildPhase; 219 | buildActionMask = 2147483647; 220 | files = ( 221 | 10F423C4217F55D50052F823 /* DemoTests.swift in Sources */, 222 | ); 223 | runOnlyForDeploymentPostprocessing = 0; 224 | }; 225 | DF17F7D81D4C18DE001DF68B /* Sources */ = { 226 | isa = PBXSourcesBuildPhase; 227 | buildActionMask = 2147483647; 228 | files = ( 229 | DF17F7E21D4C18DE001DF68B /* DemoViewController.swift in Sources */, 230 | DF17F7E01D4C18DE001DF68B /* AppDelegate.swift in Sources */, 231 | DF17F8001D4C228F001DF68B /* ALRT.swift in Sources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXSourcesBuildPhase section */ 236 | 237 | /* Begin PBXTargetDependency section */ 238 | 10F423C7217F55D50052F823 /* PBXTargetDependency */ = { 239 | isa = PBXTargetDependency; 240 | target = DF17F7DB1D4C18DE001DF68B /* Demo */; 241 | targetProxy = 10F423C6217F55D50052F823 /* PBXContainerItemProxy */; 242 | }; 243 | /* End PBXTargetDependency section */ 244 | 245 | /* Begin PBXVariantGroup section */ 246 | DF17F7E31D4C18DE001DF68B /* Main.storyboard */ = { 247 | isa = PBXVariantGroup; 248 | children = ( 249 | DF17F7E41D4C18DE001DF68B /* Base */, 250 | ); 251 | name = Main.storyboard; 252 | sourceTree = ""; 253 | }; 254 | DF17F7E81D4C18DE001DF68B /* LaunchScreen.storyboard */ = { 255 | isa = PBXVariantGroup; 256 | children = ( 257 | DF17F7E91D4C18DE001DF68B /* Base */, 258 | ); 259 | name = LaunchScreen.storyboard; 260 | sourceTree = ""; 261 | }; 262 | /* End PBXVariantGroup section */ 263 | 264 | /* Begin XCBuildConfiguration section */ 265 | 10F423C8217F55D50052F823 /* Debug */ = { 266 | isa = XCBuildConfiguration; 267 | buildSettings = { 268 | BUNDLE_LOADER = "$(TEST_HOST)"; 269 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 270 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 271 | CLANG_ENABLE_OBJC_WEAK = YES; 272 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 273 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 274 | CODE_SIGN_IDENTITY = "iPhone Developer"; 275 | CODE_SIGN_STYLE = Automatic; 276 | DEVELOPMENT_TEAM = L28L2GWTEW; 277 | GCC_C_LANGUAGE_STANDARD = gnu11; 278 | INFOPLIST_FILE = DemoTests/Info.plist; 279 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 280 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 281 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 282 | MTL_FAST_MATH = YES; 283 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.DemoTests; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 286 | SWIFT_VERSION = 5.0; 287 | TARGETED_DEVICE_FAMILY = "1,2"; 288 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Demo.app/Demo"; 289 | }; 290 | name = Debug; 291 | }; 292 | 10F423C9217F55D50052F823 /* Release */ = { 293 | isa = XCBuildConfiguration; 294 | buildSettings = { 295 | BUNDLE_LOADER = "$(TEST_HOST)"; 296 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 297 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 298 | CLANG_ENABLE_OBJC_WEAK = YES; 299 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 300 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 301 | CODE_SIGN_IDENTITY = "iPhone Developer"; 302 | CODE_SIGN_STYLE = Automatic; 303 | DEVELOPMENT_TEAM = L28L2GWTEW; 304 | GCC_C_LANGUAGE_STANDARD = gnu11; 305 | INFOPLIST_FILE = DemoTests/Info.plist; 306 | IPHONEOS_DEPLOYMENT_TARGET = 12.0; 307 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 308 | MTL_FAST_MATH = YES; 309 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.DemoTests; 310 | PRODUCT_NAME = "$(TARGET_NAME)"; 311 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 312 | SWIFT_VERSION = 5.0; 313 | TARGETED_DEVICE_FAMILY = "1,2"; 314 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Demo.app/Demo"; 315 | }; 316 | name = Release; 317 | }; 318 | DF17F7EC1D4C18DE001DF68B /* Debug */ = { 319 | isa = XCBuildConfiguration; 320 | buildSettings = { 321 | ALWAYS_SEARCH_USER_PATHS = NO; 322 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 323 | CLANG_ANALYZER_NONNULL = YES; 324 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 325 | CLANG_CXX_LIBRARY = "libc++"; 326 | CLANG_ENABLE_MODULES = YES; 327 | CLANG_ENABLE_OBJC_ARC = YES; 328 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 329 | CLANG_WARN_BOOL_CONVERSION = YES; 330 | CLANG_WARN_COMMA = YES; 331 | CLANG_WARN_CONSTANT_CONVERSION = YES; 332 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 333 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 334 | CLANG_WARN_EMPTY_BODY = YES; 335 | CLANG_WARN_ENUM_CONVERSION = YES; 336 | CLANG_WARN_INFINITE_RECURSION = YES; 337 | CLANG_WARN_INT_CONVERSION = YES; 338 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 339 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 340 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 341 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 342 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 343 | CLANG_WARN_STRICT_PROTOTYPES = YES; 344 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 345 | CLANG_WARN_UNREACHABLE_CODE = YES; 346 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 347 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 348 | COPY_PHASE_STRIP = NO; 349 | DEBUG_INFORMATION_FORMAT = dwarf; 350 | ENABLE_STRICT_OBJC_MSGSEND = YES; 351 | ENABLE_TESTABILITY = YES; 352 | GCC_C_LANGUAGE_STANDARD = gnu99; 353 | GCC_DYNAMIC_NO_PIC = NO; 354 | GCC_NO_COMMON_BLOCKS = YES; 355 | GCC_OPTIMIZATION_LEVEL = 0; 356 | GCC_PREPROCESSOR_DEFINITIONS = ( 357 | "DEBUG=1", 358 | "$(inherited)", 359 | ); 360 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 361 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 362 | GCC_WARN_UNDECLARED_SELECTOR = YES; 363 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 364 | GCC_WARN_UNUSED_FUNCTION = YES; 365 | GCC_WARN_UNUSED_VARIABLE = YES; 366 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 367 | MTL_ENABLE_DEBUG_INFO = YES; 368 | ONLY_ACTIVE_ARCH = YES; 369 | SDKROOT = iphoneos; 370 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 371 | SWIFT_VERSION = 5.0; 372 | TARGETED_DEVICE_FAMILY = "1,2"; 373 | }; 374 | name = Debug; 375 | }; 376 | DF17F7ED1D4C18DE001DF68B /* Release */ = { 377 | isa = XCBuildConfiguration; 378 | buildSettings = { 379 | ALWAYS_SEARCH_USER_PATHS = NO; 380 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 381 | CLANG_ANALYZER_NONNULL = YES; 382 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 383 | CLANG_CXX_LIBRARY = "libc++"; 384 | CLANG_ENABLE_MODULES = YES; 385 | CLANG_ENABLE_OBJC_ARC = YES; 386 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 387 | CLANG_WARN_BOOL_CONVERSION = YES; 388 | CLANG_WARN_COMMA = YES; 389 | CLANG_WARN_CONSTANT_CONVERSION = YES; 390 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 391 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 392 | CLANG_WARN_EMPTY_BODY = YES; 393 | CLANG_WARN_ENUM_CONVERSION = YES; 394 | CLANG_WARN_INFINITE_RECURSION = YES; 395 | CLANG_WARN_INT_CONVERSION = YES; 396 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 397 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 398 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 399 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 400 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 401 | CLANG_WARN_STRICT_PROTOTYPES = YES; 402 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 403 | CLANG_WARN_UNREACHABLE_CODE = YES; 404 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 405 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 406 | COPY_PHASE_STRIP = NO; 407 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 408 | ENABLE_NS_ASSERTIONS = NO; 409 | ENABLE_STRICT_OBJC_MSGSEND = YES; 410 | GCC_C_LANGUAGE_STANDARD = gnu99; 411 | GCC_NO_COMMON_BLOCKS = YES; 412 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 413 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 414 | GCC_WARN_UNDECLARED_SELECTOR = YES; 415 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 416 | GCC_WARN_UNUSED_FUNCTION = YES; 417 | GCC_WARN_UNUSED_VARIABLE = YES; 418 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 419 | MTL_ENABLE_DEBUG_INFO = NO; 420 | SDKROOT = iphoneos; 421 | SWIFT_VERSION = 5.0; 422 | TARGETED_DEVICE_FAMILY = "1,2"; 423 | VALIDATE_PRODUCT = YES; 424 | }; 425 | name = Release; 426 | }; 427 | DF17F7EF1D4C18DE001DF68B /* Debug */ = { 428 | isa = XCBuildConfiguration; 429 | buildSettings = { 430 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 431 | CODE_SIGN_IDENTITY = "iPhone Developer"; 432 | INFOPLIST_FILE = Demo/Info.plist; 433 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 434 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 435 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.ALRTDemo; 436 | PRODUCT_NAME = "$(TARGET_NAME)"; 437 | SWIFT_VERSION = 5.0; 438 | }; 439 | name = Debug; 440 | }; 441 | DF17F7F01D4C18DE001DF68B /* Release */ = { 442 | isa = XCBuildConfiguration; 443 | buildSettings = { 444 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 445 | CODE_SIGN_IDENTITY = "iPhone Developer"; 446 | INFOPLIST_FILE = Demo/Info.plist; 447 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 448 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 449 | PRODUCT_BUNDLE_IDENTIFIER = org.nsocean.ALRTDemo; 450 | PRODUCT_NAME = "$(TARGET_NAME)"; 451 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 452 | SWIFT_VERSION = 5.0; 453 | }; 454 | name = Release; 455 | }; 456 | /* End XCBuildConfiguration section */ 457 | 458 | /* Begin XCConfigurationList section */ 459 | 10F423CA217F55D50052F823 /* Build configuration list for PBXNativeTarget "DemoTests" */ = { 460 | isa = XCConfigurationList; 461 | buildConfigurations = ( 462 | 10F423C8217F55D50052F823 /* Debug */, 463 | 10F423C9217F55D50052F823 /* Release */, 464 | ); 465 | defaultConfigurationIsVisible = 0; 466 | defaultConfigurationName = Release; 467 | }; 468 | DF17F7D71D4C18DE001DF68B /* Build configuration list for PBXProject "Demo" */ = { 469 | isa = XCConfigurationList; 470 | buildConfigurations = ( 471 | DF17F7EC1D4C18DE001DF68B /* Debug */, 472 | DF17F7ED1D4C18DE001DF68B /* Release */, 473 | ); 474 | defaultConfigurationIsVisible = 0; 475 | defaultConfigurationName = Release; 476 | }; 477 | DF17F7EE1D4C18DE001DF68B /* Build configuration list for PBXNativeTarget "Demo" */ = { 478 | isa = XCConfigurationList; 479 | buildConfigurations = ( 480 | DF17F7EF1D4C18DE001DF68B /* Debug */, 481 | DF17F7F01D4C18DE001DF68B /* Release */, 482 | ); 483 | defaultConfigurationIsVisible = 0; 484 | defaultConfigurationName = Release; 485 | }; 486 | /* End XCConfigurationList section */ 487 | }; 488 | rootObject = DF17F7D41D4C18DE001DF68B /* Project object */; 489 | } 490 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/xcshareddata/xcschemes/Demo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 31 | 32 | 34 | 40 | 41 | 44 | 45 | 46 | 48 | 54 | 55 | 56 | 57 | 58 | 64 | 65 | 66 | 67 | 68 | 69 | 79 | 81 | 87 | 88 | 89 | 90 | 91 | 92 | 98 | 100 | 106 | 107 | 108 | 109 | 111 | 112 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /Demo/Demo.xcodeproj/xcshareddata/xcschemes/DemoUITests.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 14 | 15 | 17 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 39 | 40 | 41 | 42 | 48 | 49 | 51 | 52 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /Demo/Demo/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | @UIApplicationMain 4 | class AppDelegate: UIResponder, UIApplicationDelegate { 5 | 6 | var window: UIWindow? 7 | 8 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool { 9 | return true 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /Demo/Demo/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | } 88 | ], 89 | "info" : { 90 | "version" : 1, 91 | "author" : "xcode" 92 | } 93 | } -------------------------------------------------------------------------------- /Demo/Demo/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /Demo/Demo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 34 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /Demo/Demo/DemoViewController.swift: -------------------------------------------------------------------------------- 1 | import UIKit 2 | 3 | class DemoViewController: UIViewController { 4 | 5 | @IBOutlet weak var alertButton: UIButton! 6 | @IBOutlet weak var actionSheetButton: UIButton! 7 | 8 | override func viewDidLoad() { 9 | super.viewDidLoad() 10 | } 11 | 12 | @IBAction func didTapAlertButton(_ sender: UIButton) { 13 | ALRT.create(.alert, title: "Show me some alert").addOK().addCancel().show() 14 | } 15 | 16 | @IBAction func didTapActionSheetButton(_ sender: UIButton) { 17 | ALRT.create(.actionSheet, title: "ALRT", message: "Show me some action sheet") 18 | // for iPad 19 | .configurePopoverPresentation { popover in 20 | popover?.sourceView = sender 21 | } 22 | .addAction("Option A") { _, _ in print("Option A has been tapped!") } 23 | .addAction("Option B") { action, textfield in print("\(action.title!) has been tapped!") } 24 | .addDestructive("Destructive Option") 25 | .show() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Demo/Demo/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ALRTDemo 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.1 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | UILaunchStoryboardName 28 | LaunchScreen 29 | UIMainStoryboardFile 30 | Main 31 | UIRequiredDeviceCapabilities 32 | 33 | armv7 34 | 35 | UISupportedInterfaceOrientations 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationLandscapeLeft 39 | UIInterfaceOrientationLandscapeRight 40 | 41 | UISupportedInterfaceOrientations~ipad 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationPortraitUpsideDown 45 | UIInterfaceOrientationLandscapeLeft 46 | UIInterfaceOrientationLandscapeRight 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /Demo/DemoTests/DemoTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DemoTests.swift 3 | // DemoTests 4 | // 5 | // Created by Masahiro Watanabe on 2018/10/23. 6 | // Copyright © 2018 Masahiro Watanabe. All rights reserved. 7 | // 8 | 9 | import XCTest 10 | @testable import Demo 11 | 12 | class DemoTests: XCTestCase { 13 | 14 | override func setUp() { 15 | // Put setup code here. This method is called before the invocation of each test method in the class. 16 | } 17 | 18 | override func tearDown() { 19 | // Put teardown code here. This method is called after the invocation of each test method in the class. 20 | } 21 | 22 | func testViewController() { 23 | let expectation = self.expectation(description: "ALRT should be shown from view controller") 24 | 25 | let test = TestViewController() 26 | 27 | test.showALRT { (result) in 28 | self.inspect(result) 29 | expectation.fulfill() 30 | } 31 | 32 | self.waitForExpectations(timeout: 3.0, handler: nil) 33 | } 34 | 35 | func testPresentedViewController() { 36 | let expectation = self.expectation(description: "ALRT should be shown from presented view controller") 37 | 38 | let first = TestViewController() 39 | let second = TestViewController() 40 | first.present(second, animated: false) 41 | 42 | second.showALRT { (result) in 43 | self.inspect(result) 44 | expectation.fulfill() 45 | } 46 | 47 | self.waitForExpectations(timeout: 3.0, handler: nil) 48 | } 49 | 50 | func testViewControllerEmbeddedInNavigationController() { 51 | let expectation = self.expectation(description: "ALRT should be shown from view controller in UINavigationController") 52 | 53 | let test = TestViewController() 54 | _ = test.embedInNavigationController() 55 | 56 | test.showALRT { (result) in 57 | self.inspect(result) 58 | expectation.fulfill() 59 | } 60 | 61 | self.waitForExpectations(timeout: 3.0, handler: nil) 62 | } 63 | 64 | func testPushedViewController() { 65 | let expectation = self.expectation(description: "ALRT should be shown from pushed view controller") 66 | 67 | let first = TestViewController().embedInNavigationController() 68 | let second = TestViewController() 69 | first.pushViewController(second, animated: true) 70 | 71 | second.showALRT { (result) in 72 | self.inspect(result) 73 | expectation.fulfill() 74 | } 75 | 76 | self.waitForExpectations(timeout: 3.0, handler: nil) 77 | } 78 | 79 | func testTextField() { 80 | let expectation = self.expectation(description: "addTextField should attach a textField to alert") 81 | 82 | let expectedValue = "Test title" 83 | 84 | ALRT.create(.alert, title: "Unit Test Alert") 85 | .addTextField { (textField) in 86 | textField.text = expectedValue 87 | } 88 | .fetch() { alert in 89 | guard let textFields = alert?.textFields, textFields.count == 1 else { 90 | XCTFail("Textfields.count should be 1") 91 | return 92 | } 93 | 94 | guard let text = textFields.first?.text else { 95 | XCTFail("Attached textField should have text") 96 | return 97 | } 98 | XCTAssertEqual(text, expectedValue) 99 | expectation.fulfill() 100 | } 101 | 102 | self.waitForExpectations(timeout: 3.0, handler: nil) 103 | } 104 | 105 | func testDefaultConfiguration() { 106 | defer { 107 | ALRT.defaultConfiguration = nil 108 | } 109 | 110 | let expectation = self.expectation(description: "Setting defaultConfiguration should change tintColor, okTitle, cancelTitle") 111 | 112 | let expectedTintColor = UIColor.red 113 | let expectedOKTitle = "AAA" 114 | let expectedCancelTitle = "BBB" 115 | 116 | ALRT.defaultConfiguration = .init( 117 | tintColor: expectedTintColor, 118 | okTitle: expectedOKTitle, 119 | cancelTitle: expectedCancelTitle 120 | ) 121 | 122 | ALRT.create(.alert) 123 | .addOK() 124 | .addCancel() 125 | .fetch { alert in 126 | let actualTintColor = alert?.view.tintColor 127 | XCTAssertEqual(actualTintColor, expectedTintColor) 128 | 129 | let actualOKTitle = alert?.actions.first?.title 130 | XCTAssertEqual(actualOKTitle, expectedOKTitle) 131 | 132 | let actualCancelTitle = alert?.actions.last?.title 133 | XCTAssertEqual(actualCancelTitle, expectedCancelTitle) 134 | 135 | expectation.fulfill() 136 | } 137 | .show() 138 | 139 | self.waitForExpectations(timeout: 3.0, handler: nil) 140 | } 141 | 142 | func inspect(_ result: ALRT.Result) { 143 | if case .success = result { 144 | XCTAssertTrue(true) 145 | } else { 146 | XCTFail() 147 | } 148 | } 149 | } 150 | 151 | fileprivate class TestViewController: UIViewController { 152 | func showALRT(_ completionHandler: @escaping (ALRT.Result) -> Void) { 153 | ALRT.create(.alert, title: "Unit Test Alert").addOK().show() { 154 | completionHandler($0) 155 | } 156 | } 157 | } 158 | 159 | extension TestViewController { 160 | func embedInNavigationController() -> UINavigationController { 161 | return UINavigationController(rootViewController: self) 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /Demo/DemoTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Masahiro Watanabe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ALRT 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | An easier constructor for UIAlertController. Present an alert from anywhere like this. 11 | 12 | ```swift 13 | ALRT.create(.alert, title: "Alert?").addOK().addCancel().show() 14 | ``` 15 | ## Table of Contents 16 | - [Features](#features) 17 | - [Requirements](#requirements) 18 | - [Installation](#installation) 19 | - [Usage](#usage) 20 | - [License](#license) 21 | 22 | ## Features 23 | * Chainable UIAlertController Setup Methods 24 | * Support `.alert` and `.actionSheet` UIAlertController.Style 25 | * Support `UITextfield` UIAlertAction(`.alert` only) 26 | * Returns `Result` whether an alert is successfully displayed. In other words, [Unit Testable](https://github.com/mshrwtnb/ALRT/blob/master/Demo/DemoTests/DemoTests.swift). 27 | 28 | ## Requirements 29 | * Xcode 10.2+ 30 | * Swift 5.0 31 | * iOS 9.0+ 32 | 33 | ## Installation 34 | ### Carthage 35 | ``` 36 | github "mshrwtnb/ALRT" ~> 1.3.7 37 | ``` 38 | ### Cocoapods 39 | ``` 40 | pod repo update 41 | pod 'ALRT', '~> 1.3.7' 42 | ``` 43 | 44 | ## Usage 45 | ### Basics 46 | #### `.alert` 47 | ```swift 48 | import ALRT 49 | 50 | // Instantiate an .alert-type UIAlertController with OK and Cancel actions. Finally, present the alert by calling `show()`. 51 | ALRT.create(.alert, title: "Title", message: "Message").addOK().addCancel().show() 52 | ``` 53 | 54 | #### `.actionSheet` 55 | ```swift 56 | // Instantiate an .actionSheet-type UIAlertController. 57 | ALRT.create(.actionSheet, message: "Action Sheet") 58 | .addAction("Option A") 59 | .addAction("Option B") 60 | .addDestructive("Destructive Option") 61 | .show() 62 | ``` 63 | 64 | ### Action Types 65 | Each action comes with different `UIAlertAction.Style`. 66 | 67 | ```swift 68 | ALRT.create(.alert, title: "Action Types?") 69 | .addAction("🏂") // .default if not specified 70 | .addOK() // .default 71 | .addCancel("❌") // .cancel 72 | .addDestructive("💣") // .destructive 73 | .show() 74 | ``` 75 | 76 | ### Custom Title 77 | OK and Cancel actions have default titles in English; "OK" and "Cancel". 78 | Here, we're overriding the titles in Japanese. 79 | 80 | ```swift 81 | ALRT.create(.alert, title: "Actions In Japanese?").addOK("オーケー").addCancel("キャンセル").show() 82 | ``` 83 | 84 | ### Action Handling 85 | Each action has `handler` that is called when user taps the action. 86 | The closure takes two parameters: `UIAlertAction` and `[UITextField]?`. 87 | The former is self-explanatory. 88 | The latter is present if text field(s) is/are added to the alert. 89 | 90 | ```swift 91 | ALRT.create(.alert, title: "Action Handling") 92 | .addOK() { action, textFields in 93 | print("\(action.title!) tapped") 94 | } 95 | .show() 96 | ``` 97 | 98 | ### Result Handling 99 | `show()` has a completion handler that takes `Result`. 100 | You can ensure if the alert was shown successfully or not. This is useful for unit tests. 101 | ```swift 102 | ALRT.create(.alert, title: "Result Handling") 103 | .addOK() 104 | .show() { result in 105 | switch result { 106 | case .success: 107 | print("Alert is successfully shown") 108 | case .failure(let error): 109 | print("Error occurred. \(error.localizedDescription)") 110 | } 111 | } 112 | ``` 113 | 114 | ### TextField(s) 115 | Textfield(s) can be added to an alert in an use-case such as login. 116 | 117 | ```swift 118 | enum TextFieldIdentifier: Int { 119 | case username 120 | case password 121 | } 122 | 123 | ALRT.create(.alert, title: "Enter your credentials") 124 | // Configure textfield 125 | .addTextField { textfield in 126 | textfield.placeholder = "Username" 127 | textfield.tag = TextFieldIdentifier.username.rawValue 128 | } 129 | .addTextField() { textField in 130 | textField.placeholder = "Password" 131 | textField.isSecureTextEntry = true 132 | textField.tag = TextFieldIdentifier.password.rawValue 133 | } 134 | // If an user selects "Login", textfields above are retrieved in the trailing closure. Distinguish one from another with a tag or identifier. 135 | .addAction("Login") { _, textfields in 136 | for textField in textfields ?? [] { 137 | if let identifier = TextFieldIdentifier(rawValue: textField.tag) { 138 | switch identifier { 139 | case .username: 140 | // Extract username 141 | case .password: 142 | // Extract password 143 | } 144 | } 145 | } 146 | } 147 | .addCancel() 148 | .show() 149 | ``` 150 | 151 | ### Changing source ViewController to present from 152 | Although ALRT can present an alert anywhere, you might want to specify a source view controller for some reason. This can be done easily by passing a view controller to `show()`. 153 | 154 | ```swift 155 | ALRT.create(.alert, title: "Source?") 156 | .addOK() 157 | .show(self) // self = source view controller 158 | ``` 159 | 160 | ### Default Configuration 161 | Set default tintColor and titles for OK and Cancel buttons. 162 | 163 | ```swift 164 | ALRT.defaultConfiguration = .init( 165 | tintColor: UIColor.blue, 166 | okTitle: "OK👍", 167 | cancelTitle: "Cancel👎" 168 | ) 169 | ``` 170 | 171 | ## License 172 | ALRT is released under the MIT license. [See LICENSE](https://github.com/mshrwtnb/ALRT/blob/master/LICENSE) for details. 173 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | ignore: 2 | - "Demo" 3 | - "Documentation" 4 | - "ALRT.xcodeproj" --------------------------------------------------------------------------------