├── .gitignore ├── README.md ├── SimpleCalculator.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── alex.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── SimpleCalculator ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── SettingsViewController.swift └── ViewController.swift └── screenshot.png /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | *.xcworkspace 3 | xcuserdata 4 | .idea/ 5 | Build/* 6 | SimpleCalculatorUITests2/ 7 | _site/ 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple iOS Calculator 2 | This is a Simple iOS Calculator written in Swift for demonstration purposes in my [blog](https://alexilyenko.github.io/). 3 | 4 | [![Application live preview][2]][1] 5 | 6 | [1]: https://alexilyenko.github.io/ 7 | [2]: screenshot.png (live preview) 8 | -------------------------------------------------------------------------------- /SimpleCalculator.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | FA8C667B1F71CD0600D6E428 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8C667A1F71CD0600D6E428 /* AppDelegate.swift */; }; 11 | FA8C667D1F71CD0600D6E428 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA8C667C1F71CD0600D6E428 /* ViewController.swift */; }; 12 | FA8C66801F71CD0600D6E428 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA8C667E1F71CD0600D6E428 /* Main.storyboard */; }; 13 | FA8C66821F71CD0600D6E428 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = FA8C66811F71CD0600D6E428 /* Assets.xcassets */; }; 14 | FA8C66851F71CD0600D6E428 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FA8C66831F71CD0600D6E428 /* LaunchScreen.storyboard */; }; 15 | FD58D8DA2117B1B800EC0D10 /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD58D8D92117B1B800EC0D10 /* SettingsViewController.swift */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | FA8C66771F71CD0600D6E428 /* SimpleCalculator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SimpleCalculator.app; sourceTree = BUILT_PRODUCTS_DIR; }; 20 | FA8C667A1F71CD0600D6E428 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 21 | FA8C667C1F71CD0600D6E428 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 22 | FA8C667F1F71CD0600D6E428 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | FA8C66811F71CD0600D6E428 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | FA8C66841F71CD0600D6E428 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | FA8C66861F71CD0600D6E428 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | FD58D8D92117B1B800EC0D10 /* SettingsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | FA8C66741F71CD0500D6E428 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | FA8C666E1F71CD0500D6E428 = { 41 | isa = PBXGroup; 42 | children = ( 43 | FA8C66791F71CD0600D6E428 /* SimpleCalculator */, 44 | FA8C66781F71CD0600D6E428 /* Products */, 45 | ); 46 | sourceTree = ""; 47 | }; 48 | FA8C66781F71CD0600D6E428 /* Products */ = { 49 | isa = PBXGroup; 50 | children = ( 51 | FA8C66771F71CD0600D6E428 /* SimpleCalculator.app */, 52 | ); 53 | name = Products; 54 | sourceTree = ""; 55 | }; 56 | FA8C66791F71CD0600D6E428 /* SimpleCalculator */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | FA8C667A1F71CD0600D6E428 /* AppDelegate.swift */, 60 | FA8C667C1F71CD0600D6E428 /* ViewController.swift */, 61 | FA8C667E1F71CD0600D6E428 /* Main.storyboard */, 62 | FA8C66811F71CD0600D6E428 /* Assets.xcassets */, 63 | FA8C66831F71CD0600D6E428 /* LaunchScreen.storyboard */, 64 | FA8C66861F71CD0600D6E428 /* Info.plist */, 65 | FD58D8D92117B1B800EC0D10 /* SettingsViewController.swift */, 66 | ); 67 | path = SimpleCalculator; 68 | sourceTree = ""; 69 | }; 70 | /* End PBXGroup section */ 71 | 72 | /* Begin PBXNativeTarget section */ 73 | FA8C66761F71CD0500D6E428 /* SimpleCalculator */ = { 74 | isa = PBXNativeTarget; 75 | buildConfigurationList = FA8C66941F71CD0600D6E428 /* Build configuration list for PBXNativeTarget "SimpleCalculator" */; 76 | buildPhases = ( 77 | FA8C66731F71CD0500D6E428 /* Sources */, 78 | FA8C66741F71CD0500D6E428 /* Frameworks */, 79 | FA8C66751F71CD0500D6E428 /* Resources */, 80 | ); 81 | buildRules = ( 82 | ); 83 | dependencies = ( 84 | ); 85 | name = SimpleCalculator; 86 | productName = SimpleCalculator; 87 | productReference = FA8C66771F71CD0600D6E428 /* SimpleCalculator.app */; 88 | productType = "com.apple.product-type.application"; 89 | }; 90 | /* End PBXNativeTarget section */ 91 | 92 | /* Begin PBXProject section */ 93 | FA8C666F1F71CD0500D6E428 /* Project object */ = { 94 | isa = PBXProject; 95 | attributes = { 96 | LastSwiftUpdateCheck = 0940; 97 | LastUpgradeCheck = 0900; 98 | ORGANIZATIONNAME = "Alex Ilyenko"; 99 | TargetAttributes = { 100 | FA8C66761F71CD0500D6E428 = { 101 | CreatedOnToolsVersion = 9.0; 102 | ProvisioningStyle = Automatic; 103 | }; 104 | }; 105 | }; 106 | buildConfigurationList = FA8C66721F71CD0500D6E428 /* Build configuration list for PBXProject "SimpleCalculator" */; 107 | compatibilityVersion = "Xcode 8.0"; 108 | developmentRegion = en; 109 | hasScannedForEncodings = 0; 110 | knownRegions = ( 111 | en, 112 | Base, 113 | ); 114 | mainGroup = FA8C666E1F71CD0500D6E428; 115 | productRefGroup = FA8C66781F71CD0600D6E428 /* Products */; 116 | projectDirPath = ""; 117 | projectRoot = ""; 118 | targets = ( 119 | FA8C66761F71CD0500D6E428 /* SimpleCalculator */, 120 | ); 121 | }; 122 | /* End PBXProject section */ 123 | 124 | /* Begin PBXResourcesBuildPhase section */ 125 | FA8C66751F71CD0500D6E428 /* Resources */ = { 126 | isa = PBXResourcesBuildPhase; 127 | buildActionMask = 2147483647; 128 | files = ( 129 | FA8C66851F71CD0600D6E428 /* LaunchScreen.storyboard in Resources */, 130 | FA8C66821F71CD0600D6E428 /* Assets.xcassets in Resources */, 131 | FA8C66801F71CD0600D6E428 /* Main.storyboard in Resources */, 132 | ); 133 | runOnlyForDeploymentPostprocessing = 0; 134 | }; 135 | /* End PBXResourcesBuildPhase section */ 136 | 137 | /* Begin PBXSourcesBuildPhase section */ 138 | FA8C66731F71CD0500D6E428 /* Sources */ = { 139 | isa = PBXSourcesBuildPhase; 140 | buildActionMask = 2147483647; 141 | files = ( 142 | FA8C667D1F71CD0600D6E428 /* ViewController.swift in Sources */, 143 | FA8C667B1F71CD0600D6E428 /* AppDelegate.swift in Sources */, 144 | FD58D8DA2117B1B800EC0D10 /* SettingsViewController.swift in Sources */, 145 | ); 146 | runOnlyForDeploymentPostprocessing = 0; 147 | }; 148 | /* End PBXSourcesBuildPhase section */ 149 | 150 | /* Begin PBXVariantGroup section */ 151 | FA8C667E1F71CD0600D6E428 /* Main.storyboard */ = { 152 | isa = PBXVariantGroup; 153 | children = ( 154 | FA8C667F1F71CD0600D6E428 /* Base */, 155 | ); 156 | name = Main.storyboard; 157 | sourceTree = ""; 158 | }; 159 | FA8C66831F71CD0600D6E428 /* LaunchScreen.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | FA8C66841F71CD0600D6E428 /* Base */, 163 | ); 164 | name = LaunchScreen.storyboard; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXVariantGroup section */ 168 | 169 | /* Begin XCBuildConfiguration section */ 170 | FA8C66921F71CD0600D6E428 /* Debug */ = { 171 | isa = XCBuildConfiguration; 172 | buildSettings = { 173 | ALWAYS_SEARCH_USER_PATHS = NO; 174 | CLANG_ANALYZER_NONNULL = YES; 175 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 176 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 177 | CLANG_CXX_LIBRARY = "libc++"; 178 | CLANG_ENABLE_MODULES = YES; 179 | CLANG_ENABLE_OBJC_ARC = YES; 180 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 181 | CLANG_WARN_BOOL_CONVERSION = YES; 182 | CLANG_WARN_COMMA = YES; 183 | CLANG_WARN_CONSTANT_CONVERSION = YES; 184 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 185 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 186 | CLANG_WARN_EMPTY_BODY = YES; 187 | CLANG_WARN_ENUM_CONVERSION = YES; 188 | CLANG_WARN_INFINITE_RECURSION = YES; 189 | CLANG_WARN_INT_CONVERSION = YES; 190 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 191 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 192 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 193 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 194 | CLANG_WARN_STRICT_PROTOTYPES = YES; 195 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 196 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | CODE_SIGN_IDENTITY = "iPhone Developer"; 200 | COPY_PHASE_STRIP = NO; 201 | DEBUG_INFORMATION_FORMAT = dwarf; 202 | ENABLE_STRICT_OBJC_MSGSEND = YES; 203 | ENABLE_TESTABILITY = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu11; 205 | GCC_DYNAMIC_NO_PIC = NO; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 219 | MTL_ENABLE_DEBUG_INFO = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = iphoneos; 222 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 223 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 224 | }; 225 | name = Debug; 226 | }; 227 | FA8C66931F71CD0600D6E428 /* Release */ = { 228 | isa = XCBuildConfiguration; 229 | buildSettings = { 230 | ALWAYS_SEARCH_USER_PATHS = NO; 231 | CLANG_ANALYZER_NONNULL = YES; 232 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 233 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 234 | CLANG_CXX_LIBRARY = "libc++"; 235 | CLANG_ENABLE_MODULES = YES; 236 | CLANG_ENABLE_OBJC_ARC = YES; 237 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 238 | CLANG_WARN_BOOL_CONVERSION = YES; 239 | CLANG_WARN_COMMA = YES; 240 | CLANG_WARN_CONSTANT_CONVERSION = YES; 241 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 242 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 243 | CLANG_WARN_EMPTY_BODY = YES; 244 | CLANG_WARN_ENUM_CONVERSION = YES; 245 | CLANG_WARN_INFINITE_RECURSION = YES; 246 | CLANG_WARN_INT_CONVERSION = YES; 247 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 248 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 249 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 250 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 251 | CLANG_WARN_STRICT_PROTOTYPES = YES; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 254 | CLANG_WARN_UNREACHABLE_CODE = YES; 255 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 256 | CODE_SIGN_IDENTITY = "iPhone Developer"; 257 | COPY_PHASE_STRIP = NO; 258 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 259 | ENABLE_NS_ASSERTIONS = NO; 260 | ENABLE_STRICT_OBJC_MSGSEND = YES; 261 | GCC_C_LANGUAGE_STANDARD = gnu11; 262 | GCC_NO_COMMON_BLOCKS = YES; 263 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 264 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 265 | GCC_WARN_UNDECLARED_SELECTOR = YES; 266 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 267 | GCC_WARN_UNUSED_FUNCTION = YES; 268 | GCC_WARN_UNUSED_VARIABLE = YES; 269 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 270 | MTL_ENABLE_DEBUG_INFO = NO; 271 | SDKROOT = iphoneos; 272 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 273 | VALIDATE_PRODUCT = YES; 274 | }; 275 | name = Release; 276 | }; 277 | FA8C66951F71CD0600D6E428 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | CODE_SIGN_STYLE = Automatic; 282 | INFOPLIST_FILE = SimpleCalculator/Info.plist; 283 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 284 | PRODUCT_BUNDLE_IDENTIFIER = com.github.alexilyenko.SimpleCalculator; 285 | PRODUCT_NAME = "$(TARGET_NAME)"; 286 | SWIFT_VERSION = 4.0; 287 | TARGETED_DEVICE_FAMILY = "1,2"; 288 | }; 289 | name = Debug; 290 | }; 291 | FA8C66961F71CD0600D6E428 /* Release */ = { 292 | isa = XCBuildConfiguration; 293 | buildSettings = { 294 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 295 | CODE_SIGN_STYLE = Automatic; 296 | INFOPLIST_FILE = SimpleCalculator/Info.plist; 297 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 298 | PRODUCT_BUNDLE_IDENTIFIER = com.github.alexilyenko.SimpleCalculator; 299 | PRODUCT_NAME = "$(TARGET_NAME)"; 300 | SWIFT_VERSION = 4.0; 301 | TARGETED_DEVICE_FAMILY = "1,2"; 302 | }; 303 | name = Release; 304 | }; 305 | /* End XCBuildConfiguration section */ 306 | 307 | /* Begin XCConfigurationList section */ 308 | FA8C66721F71CD0500D6E428 /* Build configuration list for PBXProject "SimpleCalculator" */ = { 309 | isa = XCConfigurationList; 310 | buildConfigurations = ( 311 | FA8C66921F71CD0600D6E428 /* Debug */, 312 | FA8C66931F71CD0600D6E428 /* Release */, 313 | ); 314 | defaultConfigurationIsVisible = 0; 315 | defaultConfigurationName = Release; 316 | }; 317 | FA8C66941F71CD0600D6E428 /* Build configuration list for PBXNativeTarget "SimpleCalculator" */ = { 318 | isa = XCConfigurationList; 319 | buildConfigurations = ( 320 | FA8C66951F71CD0600D6E428 /* Debug */, 321 | FA8C66961F71CD0600D6E428 /* Release */, 322 | ); 323 | defaultConfigurationIsVisible = 0; 324 | defaultConfigurationName = Release; 325 | }; 326 | /* End XCConfigurationList section */ 327 | }; 328 | rootObject = FA8C666F1F71CD0500D6E428 /* Project object */; 329 | } 330 | -------------------------------------------------------------------------------- /SimpleCalculator.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SimpleCalculator.xcodeproj/xcuserdata/alex.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | SimpleCalculator.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | SimpleCalculatorUITests.xcscheme 13 | 14 | orderHint 15 | 1 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | FA8C66761F71CD0500D6E428 21 | 22 | primary 23 | 24 | 25 | FA8C668A1F71CD0600D6E428 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /SimpleCalculator/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // SimpleCalculator 4 | // 5 | // Created by Alex Ilyenko on 9/19/17. 6 | // Copyright © 2017 Alex Ilyenko. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, 17 | didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | if !UserDefaults.standard.bool(forKey: "isNotFirstLaunch") { 19 | //Set autoAdjustSettings and isNotFirstLaunch to true 20 | UserDefaults.standard.set(false, forKey: "enableWaits") 21 | UserDefaults.standard.set(true, forKey: "isNotFirstLaunch") 22 | 23 | //Sync NSUserDefaults 24 | UserDefaults.standard.synchronize() 25 | } 26 | 27 | return true 28 | } 29 | 30 | func applicationWillResignActive(_ application: UIApplication) { 31 | } 32 | 33 | func applicationDidEnterBackground(_ application: UIApplication) { 34 | } 35 | 36 | func applicationWillEnterForeground(_ application: UIApplication) { 37 | } 38 | 39 | func applicationDidBecomeActive(_ application: UIApplication) { 40 | } 41 | 42 | func applicationWillTerminate(_ application: UIApplication) { 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /SimpleCalculator/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 | "idiom": "ios-marketing", 90 | "size": "1024x1024", 91 | "scale": "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /SimpleCalculator/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 | -------------------------------------------------------------------------------- /SimpleCalculator/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 | 32 | 46 | 60 | 74 | 85 | 99 | 113 | 127 | 138 | 152 | 166 | 180 | 191 | 205 | 216 | 227 | 238 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | -------------------------------------------------------------------------------- /SimpleCalculator/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 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /SimpleCalculator/SettingsViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SettingsViewController.swift 3 | // SimpleCalculator 4 | // 5 | // Created by Alex Ilyenko on 8/5/18. 6 | // Copyright © 2018 Alex Ilyenko. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class SettingsViewController: UIViewController { 12 | 13 | @IBOutlet weak var mySwitch: UISwitch! 14 | 15 | override func viewDidLoad() { 16 | super.viewDidLoad() 17 | mySwitch.isOn = UserDefaults.standard.bool(forKey: "enableWaits") 18 | } 19 | 20 | @IBAction func toggleSwitch(_ sender: UISwitch) { 21 | UserDefaults.standard.set(sender.isOn, forKey: "enableWaits") 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /SimpleCalculator/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // SimpleCalculator 4 | // 5 | // Created by Alex Ilyenko on 9/19/17. 6 | // Copyright © 2017 Alex Ilyenko. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | static var isWaitEnabled: Bool! = false 14 | @IBOutlet weak var resultLabel: UILabel! 15 | private var firstNumber: Double = 0.0 16 | private var symbol: String = "" 17 | private var isSymbolPressed: Bool = false 18 | var settings: SettingsViewController! 19 | 20 | override func viewDidLoad() { 21 | super.viewDidLoad() 22 | // Do any additional setup after loading the view, typically from a nib. 23 | } 24 | 25 | override func didReceiveMemoryWarning() { 26 | super.didReceiveMemoryWarning() 27 | // Dispose of any resources that can be recreated. 28 | } 29 | 30 | @IBAction func pressNumber(_ sender: UIButton) { 31 | let buttonText = sender.titleLabel?.text! 32 | let labelText = resultLabel.text! 33 | if buttonText == "." && labelText.contains(".") { 34 | return 35 | } 36 | if isSymbolPressed { 37 | resultLabel.text = buttonText 38 | isSymbolPressed = false 39 | return 40 | } 41 | resultLabel.text = 42 | "\((Double(labelText) != 0.0 || labelText.contains(".") || buttonText == ".") ? labelText : "")" + 43 | "\(buttonText!)" 44 | } 45 | 46 | @IBAction func pressSymbol(_ sender: UIButton) { 47 | firstNumber = Double(resultLabel.text!)! 48 | symbol = (sender.titleLabel?.text)! 49 | isSymbolPressed = true 50 | } 51 | 52 | @IBAction func pressReset(_ sender: UIButton) { 53 | wait() 54 | resultLabel.text = String(0) 55 | firstNumber = 0.0 56 | symbol = "" 57 | isSymbolPressed = false 58 | } 59 | 60 | @IBAction func pressCalculate(_ sender: UIButton) { 61 | let secondNumber = Double(resultLabel.text!)! 62 | let result = calculate(secondNumber) 63 | wait() 64 | resultLabel.text = String(result) 65 | firstNumber = 0.0 66 | symbol = "" 67 | isSymbolPressed = true 68 | } 69 | 70 | private func calculate(_ secondNumber: Double) -> Double { 71 | switch symbol { 72 | case "+": return firstNumber + secondNumber 73 | case "-": return firstNumber - secondNumber 74 | case "*": return firstNumber * secondNumber 75 | case "/": return firstNumber / secondNumber 76 | default: return Double(resultLabel.text!)! 77 | } 78 | } 79 | 80 | private func wait() { 81 | if UserDefaults.standard.bool(forKey: "enableWaits") { 82 | sleep(2) 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexilyenko/SimpleIOSCalculator/8f0b3eb4e1fd16e13dfb890557f6766eae44b03d/screenshot.png --------------------------------------------------------------------------------