├── HSUndoRedoTutorial1.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ └── xcuserdata │ │ └── sotsys216.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── sotsys216.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ └── xcschememanagement.plist ├── HSUndoRedoTutorial1 ├── AppDelegate.swift ├── Assets.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── Info.plist ├── Student.swift ├── StudentTableViewCell.swift └── StudentsListViewController.swift ├── README.md └── Undo-Redo.gif /HSUndoRedoTutorial1.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | F7856E6A2268402E006CA575 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7856E692268402E006CA575 /* AppDelegate.swift */; }; 11 | F7856E6F2268402E006CA575 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7856E6D2268402E006CA575 /* Main.storyboard */; }; 12 | F7856E712268402F006CA575 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F7856E702268402F006CA575 /* Assets.xcassets */; }; 13 | F7856E742268402F006CA575 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7856E722268402F006CA575 /* LaunchScreen.storyboard */; }; 14 | F7856E7C22684159006CA575 /* StudentTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7856E7B22684159006CA575 /* StudentTableViewCell.swift */; }; 15 | F7856E7E22684168006CA575 /* Student.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7856E7D22684168006CA575 /* Student.swift */; }; 16 | F7856E802268436E006CA575 /* StudentsListViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7856E7F2268436E006CA575 /* StudentsListViewController.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | F7856E662268402E006CA575 /* HSUndoRedoTutorial1.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HSUndoRedoTutorial1.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | F7856E692268402E006CA575 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | F7856E6E2268402E006CA575 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 23 | F7856E702268402F006CA575 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 24 | F7856E732268402F006CA575 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 25 | F7856E752268402F006CA575 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 26 | F7856E7B22684159006CA575 /* StudentTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentTableViewCell.swift; sourceTree = ""; }; 27 | F7856E7D22684168006CA575 /* Student.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Student.swift; sourceTree = ""; }; 28 | F7856E7F2268436E006CA575 /* StudentsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudentsListViewController.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | F7856E632268402E006CA575 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | F7856E5D2268402E006CA575 = { 43 | isa = PBXGroup; 44 | children = ( 45 | F7856E682268402E006CA575 /* HSUndoRedoTutorial1 */, 46 | F7856E672268402E006CA575 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | F7856E672268402E006CA575 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | F7856E662268402E006CA575 /* HSUndoRedoTutorial1.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | F7856E682268402E006CA575 /* HSUndoRedoTutorial1 */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | F7856E692268402E006CA575 /* AppDelegate.swift */, 62 | F7856E6D2268402E006CA575 /* Main.storyboard */, 63 | F7856E702268402F006CA575 /* Assets.xcassets */, 64 | F7856E722268402F006CA575 /* LaunchScreen.storyboard */, 65 | F7856E752268402F006CA575 /* Info.plist */, 66 | F7856E7B22684159006CA575 /* StudentTableViewCell.swift */, 67 | F7856E7D22684168006CA575 /* Student.swift */, 68 | F7856E7F2268436E006CA575 /* StudentsListViewController.swift */, 69 | ); 70 | path = HSUndoRedoTutorial1; 71 | sourceTree = ""; 72 | }; 73 | /* End PBXGroup section */ 74 | 75 | /* Begin PBXNativeTarget section */ 76 | F7856E652268402E006CA575 /* HSUndoRedoTutorial1 */ = { 77 | isa = PBXNativeTarget; 78 | buildConfigurationList = F7856E782268402F006CA575 /* Build configuration list for PBXNativeTarget "HSUndoRedoTutorial1" */; 79 | buildPhases = ( 80 | F7856E622268402E006CA575 /* Sources */, 81 | F7856E632268402E006CA575 /* Frameworks */, 82 | F7856E642268402E006CA575 /* Resources */, 83 | ); 84 | buildRules = ( 85 | ); 86 | dependencies = ( 87 | ); 88 | name = HSUndoRedoTutorial1; 89 | productName = HSUndoRedoTutorial1; 90 | productReference = F7856E662268402E006CA575 /* HSUndoRedoTutorial1.app */; 91 | productType = "com.apple.product-type.application"; 92 | }; 93 | /* End PBXNativeTarget section */ 94 | 95 | /* Begin PBXProject section */ 96 | F7856E5E2268402E006CA575 /* Project object */ = { 97 | isa = PBXProject; 98 | attributes = { 99 | LastSwiftUpdateCheck = 1020; 100 | LastUpgradeCheck = 1020; 101 | ORGANIZATIONNAME = "Hitendra iDev"; 102 | TargetAttributes = { 103 | F7856E652268402E006CA575 = { 104 | CreatedOnToolsVersion = 10.2; 105 | }; 106 | }; 107 | }; 108 | buildConfigurationList = F7856E612268402E006CA575 /* Build configuration list for PBXProject "HSUndoRedoTutorial1" */; 109 | compatibilityVersion = "Xcode 9.3"; 110 | developmentRegion = en; 111 | hasScannedForEncodings = 0; 112 | knownRegions = ( 113 | en, 114 | Base, 115 | ); 116 | mainGroup = F7856E5D2268402E006CA575; 117 | productRefGroup = F7856E672268402E006CA575 /* Products */; 118 | projectDirPath = ""; 119 | projectRoot = ""; 120 | targets = ( 121 | F7856E652268402E006CA575 /* HSUndoRedoTutorial1 */, 122 | ); 123 | }; 124 | /* End PBXProject section */ 125 | 126 | /* Begin PBXResourcesBuildPhase section */ 127 | F7856E642268402E006CA575 /* Resources */ = { 128 | isa = PBXResourcesBuildPhase; 129 | buildActionMask = 2147483647; 130 | files = ( 131 | F7856E742268402F006CA575 /* LaunchScreen.storyboard in Resources */, 132 | F7856E712268402F006CA575 /* Assets.xcassets in Resources */, 133 | F7856E6F2268402E006CA575 /* Main.storyboard in Resources */, 134 | ); 135 | runOnlyForDeploymentPostprocessing = 0; 136 | }; 137 | /* End PBXResourcesBuildPhase section */ 138 | 139 | /* Begin PBXSourcesBuildPhase section */ 140 | F7856E622268402E006CA575 /* Sources */ = { 141 | isa = PBXSourcesBuildPhase; 142 | buildActionMask = 2147483647; 143 | files = ( 144 | F7856E802268436E006CA575 /* StudentsListViewController.swift in Sources */, 145 | F7856E6A2268402E006CA575 /* AppDelegate.swift in Sources */, 146 | F7856E7C22684159006CA575 /* StudentTableViewCell.swift in Sources */, 147 | F7856E7E22684168006CA575 /* Student.swift in Sources */, 148 | ); 149 | runOnlyForDeploymentPostprocessing = 0; 150 | }; 151 | /* End PBXSourcesBuildPhase section */ 152 | 153 | /* Begin PBXVariantGroup section */ 154 | F7856E6D2268402E006CA575 /* Main.storyboard */ = { 155 | isa = PBXVariantGroup; 156 | children = ( 157 | F7856E6E2268402E006CA575 /* Base */, 158 | ); 159 | name = Main.storyboard; 160 | sourceTree = ""; 161 | }; 162 | F7856E722268402F006CA575 /* LaunchScreen.storyboard */ = { 163 | isa = PBXVariantGroup; 164 | children = ( 165 | F7856E732268402F006CA575 /* Base */, 166 | ); 167 | name = LaunchScreen.storyboard; 168 | sourceTree = ""; 169 | }; 170 | /* End PBXVariantGroup section */ 171 | 172 | /* Begin XCBuildConfiguration section */ 173 | F7856E762268402F006CA575 /* Debug */ = { 174 | isa = XCBuildConfiguration; 175 | buildSettings = { 176 | ALWAYS_SEARCH_USER_PATHS = NO; 177 | CLANG_ANALYZER_NONNULL = YES; 178 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 179 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 180 | CLANG_CXX_LIBRARY = "libc++"; 181 | CLANG_ENABLE_MODULES = YES; 182 | CLANG_ENABLE_OBJC_ARC = YES; 183 | CLANG_ENABLE_OBJC_WEAK = YES; 184 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 185 | CLANG_WARN_BOOL_CONVERSION = YES; 186 | CLANG_WARN_COMMA = YES; 187 | CLANG_WARN_CONSTANT_CONVERSION = YES; 188 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 191 | CLANG_WARN_EMPTY_BODY = YES; 192 | CLANG_WARN_ENUM_CONVERSION = YES; 193 | CLANG_WARN_INFINITE_RECURSION = YES; 194 | CLANG_WARN_INT_CONVERSION = YES; 195 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 196 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 197 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 198 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 199 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 200 | CLANG_WARN_STRICT_PROTOTYPES = YES; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 203 | CLANG_WARN_UNREACHABLE_CODE = YES; 204 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 205 | CODE_SIGN_IDENTITY = "iPhone Developer"; 206 | COPY_PHASE_STRIP = NO; 207 | DEBUG_INFORMATION_FORMAT = dwarf; 208 | ENABLE_STRICT_OBJC_MSGSEND = YES; 209 | ENABLE_TESTABILITY = YES; 210 | GCC_C_LANGUAGE_STANDARD = gnu11; 211 | GCC_DYNAMIC_NO_PIC = NO; 212 | GCC_NO_COMMON_BLOCKS = YES; 213 | GCC_OPTIMIZATION_LEVEL = 0; 214 | GCC_PREPROCESSOR_DEFINITIONS = ( 215 | "DEBUG=1", 216 | "$(inherited)", 217 | ); 218 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 219 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 220 | GCC_WARN_UNDECLARED_SELECTOR = YES; 221 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 222 | GCC_WARN_UNUSED_FUNCTION = YES; 223 | GCC_WARN_UNUSED_VARIABLE = YES; 224 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 225 | MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; 226 | MTL_FAST_MATH = YES; 227 | ONLY_ACTIVE_ARCH = YES; 228 | SDKROOT = iphoneos; 229 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 230 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 231 | }; 232 | name = Debug; 233 | }; 234 | F7856E772268402F006CA575 /* Release */ = { 235 | isa = XCBuildConfiguration; 236 | buildSettings = { 237 | ALWAYS_SEARCH_USER_PATHS = NO; 238 | CLANG_ANALYZER_NONNULL = YES; 239 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 240 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 241 | CLANG_CXX_LIBRARY = "libc++"; 242 | CLANG_ENABLE_MODULES = YES; 243 | CLANG_ENABLE_OBJC_ARC = YES; 244 | CLANG_ENABLE_OBJC_WEAK = YES; 245 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 246 | CLANG_WARN_BOOL_CONVERSION = YES; 247 | CLANG_WARN_COMMA = YES; 248 | CLANG_WARN_CONSTANT_CONVERSION = YES; 249 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 250 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 251 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 252 | CLANG_WARN_EMPTY_BODY = YES; 253 | CLANG_WARN_ENUM_CONVERSION = YES; 254 | CLANG_WARN_INFINITE_RECURSION = YES; 255 | CLANG_WARN_INT_CONVERSION = YES; 256 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 257 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 258 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 259 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 260 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 261 | CLANG_WARN_STRICT_PROTOTYPES = YES; 262 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 263 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 264 | CLANG_WARN_UNREACHABLE_CODE = YES; 265 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 266 | CODE_SIGN_IDENTITY = "iPhone Developer"; 267 | COPY_PHASE_STRIP = NO; 268 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 269 | ENABLE_NS_ASSERTIONS = NO; 270 | ENABLE_STRICT_OBJC_MSGSEND = YES; 271 | GCC_C_LANGUAGE_STANDARD = gnu11; 272 | GCC_NO_COMMON_BLOCKS = YES; 273 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 274 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 275 | GCC_WARN_UNDECLARED_SELECTOR = YES; 276 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 277 | GCC_WARN_UNUSED_FUNCTION = YES; 278 | GCC_WARN_UNUSED_VARIABLE = YES; 279 | IPHONEOS_DEPLOYMENT_TARGET = 12.2; 280 | MTL_ENABLE_DEBUG_INFO = NO; 281 | MTL_FAST_MATH = YES; 282 | SDKROOT = iphoneos; 283 | SWIFT_COMPILATION_MODE = wholemodule; 284 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 285 | VALIDATE_PRODUCT = YES; 286 | }; 287 | name = Release; 288 | }; 289 | F7856E792268402F006CA575 /* Debug */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | CODE_SIGN_STYLE = Automatic; 294 | INFOPLIST_FILE = HSUndoRedoTutorial1/Info.plist; 295 | LD_RUNPATH_SEARCH_PATHS = ( 296 | "$(inherited)", 297 | "@executable_path/Frameworks", 298 | ); 299 | PRODUCT_BUNDLE_IDENTIFIER = com.hitendra.medium.undoRedoTutorial1.HSUndoRedoTutorial1; 300 | PRODUCT_NAME = "$(TARGET_NAME)"; 301 | SWIFT_VERSION = 5.0; 302 | TARGETED_DEVICE_FAMILY = "1,2"; 303 | }; 304 | name = Debug; 305 | }; 306 | F7856E7A2268402F006CA575 /* Release */ = { 307 | isa = XCBuildConfiguration; 308 | buildSettings = { 309 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 310 | CODE_SIGN_STYLE = Automatic; 311 | INFOPLIST_FILE = HSUndoRedoTutorial1/Info.plist; 312 | LD_RUNPATH_SEARCH_PATHS = ( 313 | "$(inherited)", 314 | "@executable_path/Frameworks", 315 | ); 316 | PRODUCT_BUNDLE_IDENTIFIER = com.hitendra.medium.undoRedoTutorial1.HSUndoRedoTutorial1; 317 | PRODUCT_NAME = "$(TARGET_NAME)"; 318 | SWIFT_VERSION = 5.0; 319 | TARGETED_DEVICE_FAMILY = "1,2"; 320 | }; 321 | name = Release; 322 | }; 323 | /* End XCBuildConfiguration section */ 324 | 325 | /* Begin XCConfigurationList section */ 326 | F7856E612268402E006CA575 /* Build configuration list for PBXProject "HSUndoRedoTutorial1" */ = { 327 | isa = XCConfigurationList; 328 | buildConfigurations = ( 329 | F7856E762268402F006CA575 /* Debug */, 330 | F7856E772268402F006CA575 /* Release */, 331 | ); 332 | defaultConfigurationIsVisible = 0; 333 | defaultConfigurationName = Release; 334 | }; 335 | F7856E782268402F006CA575 /* Build configuration list for PBXNativeTarget "HSUndoRedoTutorial1" */ = { 336 | isa = XCConfigurationList; 337 | buildConfigurations = ( 338 | F7856E792268402F006CA575 /* Debug */, 339 | F7856E7A2268402F006CA575 /* Release */, 340 | ); 341 | defaultConfigurationIsVisible = 0; 342 | defaultConfigurationName = Release; 343 | }; 344 | /* End XCConfigurationList section */ 345 | }; 346 | rootObject = F7856E5E2268402E006CA575 /* Project object */; 347 | } 348 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1.xcodeproj/project.xcworkspace/xcuserdata/sotsys216.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hitendradeveloper/Simple-Undo-Redo-Example/85bab6ba25d8ebfd1de945e142ad7ad1d09402cd/HSUndoRedoTutorial1.xcodeproj/project.xcworkspace/xcuserdata/sotsys216.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /HSUndoRedoTutorial1.xcodeproj/xcuserdata/sotsys216.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1.xcodeproj/xcuserdata/sotsys216.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | HSUndoRedoTutorial1.xcscheme_^#shared#^_ 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // HSUndoRedoTutorial1 4 | // 5 | // Created by Hitendra on 18/04/19. 6 | // Copyright © 2019 Hitendra iDev. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/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 | } -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/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 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/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 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 59 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/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 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/Student.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Student.swift 3 | // HSUndoRedoTutorial1 4 | // 5 | // Created by Hitendra on 18/04/19. 6 | // Copyright © 2019 Hitendra iDev. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | 11 | struct Student { 12 | var name: String 13 | var studyInClass: String 14 | 15 | static let allStudents : [Student] = [ 16 | Student(name: "Hitendra Solanki", studyInClass: "9th standard"), 17 | Student(name: "Yajaira Coplan", studyInClass: "7th standard"), 18 | Student(name: "Loyd Stage", studyInClass: "8th standard"), 19 | Student(name: "Jan Hester", studyInClass: "1st standard"), 20 | Student(name: "Vennie Loranger", studyInClass: "9th standard"), 21 | Student(name: "Brady Sartor", studyInClass: "7th standard"), 22 | Student(name: "Jasmin Mcgillis", studyInClass: "8th standard"), 23 | Student(name: "Octavia Martens", studyInClass: "1st standard"), 24 | Student(name: "Latosha Bingaman", studyInClass: "9th standard"), 25 | Student(name: "Scarlet Noto", studyInClass: "7th standard"), 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/StudentTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StudentTableViewCell.swift 3 | // HSUndoRedoTutorial1 4 | // 5 | // Created by Hitendra on 18/04/19. 6 | // Copyright © 2019 Hitendra iDev. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class StudentTableViewCell: UITableViewCell { 12 | var student: Student! { 13 | didSet { 14 | self.textLabel?.text = self.student.name 15 | self.detailTextLabel?.text = self.student.studyInClass 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /HSUndoRedoTutorial1/StudentsListViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // StudentsListViewController.swift 3 | // HSUndoRedoTutorial1 4 | // 5 | // Created by Hitendra on 18/04/19. 6 | // Copyright © 2019 Hitendra iDev. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class StudentsListViewController: UIViewController { 12 | 13 | //IBOutlets:- 14 | @IBOutlet weak var btnAdd: UIBarButtonItem! 15 | @IBOutlet weak var btnUndo: UIBarButtonItem! 16 | @IBOutlet weak var btnRedo: UIBarButtonItem! 17 | 18 | @IBOutlet weak var tableview: UITableView! 19 | 20 | //iVars:- 21 | 22 | //list of students visible in tableview screen appear 23 | var students: [Student] = [ 24 | Student.allStudents[0] 25 | ] 26 | 27 | //ViewController LifeCycle 28 | override func viewDidLoad() { 29 | super.viewDidLoad() 30 | self.enableDisbaleActionsButtons() 31 | } 32 | } 33 | 34 | //MARK:- IBActions + Enable/Disable UI buttons 35 | extension StudentsListViewController { 36 | @IBAction func btnAddNewStudentDidTap(_ sender: UIBarButtonItem) { 37 | let index = self.students.count 38 | self.addNewStudent(at: index) //add student in array and update table 39 | self.addNewStudentUndoActionRegister(at: index) //register for Undo action 40 | 41 | self.enableDisbaleActionsButtons() 42 | } 43 | 44 | @IBAction func btnUndoDidTap(_ sender: UIBarButtonItem) { 45 | self.undoManager?.undo() 46 | self.enableDisbaleActionsButtons() 47 | } 48 | 49 | @IBAction func btnRedoDidTap(_ sender: UIBarButtonItem) { 50 | self.undoManager?.redo() 51 | self.enableDisbaleActionsButtons() 52 | } 53 | 54 | func enableDisbaleActionsButtons(){ 55 | self.btnAdd.isEnabled = Student.allStudents.count > self.students.count 56 | self.btnUndo.isEnabled = self.undoManager?.canUndo ?? false 57 | self.btnRedo.isEnabled = self.undoManager?.canRedo ?? false 58 | } 59 | } 60 | 61 | //MARK:- Add/Remove Student : Data Actions 62 | // Data Change Actions + UI Updates 63 | extension StudentsListViewController { 64 | func addNewStudent(at index: Int){ 65 | let newStudent = Student.allStudents[index] 66 | self.students.append(newStudent) 67 | self.tableview.reloadData() 68 | } 69 | 70 | func removeNewStudent(at index: Int) { 71 | self.students.remove(at: index) 72 | self.tableview.reloadData() 73 | } 74 | } 75 | 76 | //MARK:- Add/Remove Student : Undo/Redo Actions 77 | // Register inverse Actions that automatically performs 78 | extension StudentsListViewController { 79 | func addNewStudentUndoActionRegister(at index: Int){ 80 | self.undoManager?.registerUndo(withTarget: self, handler: { (selfTarget) in 81 | selfTarget.removeNewStudent(at: index) 82 | selfTarget.removeNewStudentUndoActionRegister(at: index) 83 | }) 84 | } 85 | 86 | func removeNewStudentUndoActionRegister(at index: Int){ 87 | self.undoManager?.registerUndo(withTarget: self, handler: { (selfTarget) in 88 | selfTarget.addNewStudent(at: index) 89 | selfTarget.addNewStudentUndoActionRegister(at: index) 90 | }) 91 | } 92 | } 93 | 94 | //MARK:- UITableViewDelegate + UITableViewDataSource 95 | extension StudentsListViewController: UITableViewDelegate, UITableViewDataSource { 96 | func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 97 | return self.students.count 98 | } 99 | 100 | func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 101 | let cell = tableView.dequeueReusableCell(withIdentifier: "StudentTableViewCell") as! StudentTableViewCell 102 | cell.student = self.students[indexPath.row] 103 | return cell 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple-Undo-Redo-Example 2 | implementation of UndoManager in Swift5 Xcode 10.2 3 | 4 | # DEMO 5 | ![DEMO GIF](https://github.com/hitendradeveloper/Simple-Undo-Redo-Example/blob/master/Undo-Redo.gif) 6 | 7 | 8 | # Demo project for the medium article 9 | 10 | [UndoManager in Swift 5 with example - Perform undo-redo actions in a more simple way](https://medium.com/p/8c791e231b87) 11 | -------------------------------------------------------------------------------- /Undo-Redo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hitendradeveloper/Simple-Undo-Redo-Example/85bab6ba25d8ebfd1de945e142ad7ad1d09402cd/Undo-Redo.gif --------------------------------------------------------------------------------