├── .gitignore ├── Debugging.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── Debugging ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── DateFormatHelper.swift ├── DateTableViewCell.swift ├── DetailViewController.swift ├── Info.plist ├── MasterViewController.swift └── TableViewModel.swift ├── README.markdown └── assets ├── cycle.png ├── memory-graph.png ├── symbolic-breakpoint.png └── tsan.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | -------------------------------------------------------------------------------- /Debugging.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 780C2A831EDC6317005017B2 /* DateFormatHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780C2A821EDC6317005017B2 /* DateFormatHelper.swift */; }; 11 | 780C2A851EDC7556005017B2 /* DateTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780C2A841EDC7556005017B2 /* DateTableViewCell.swift */; }; 12 | 780C2A871EDCB4AD005017B2 /* TableViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 780C2A861EDCB4AD005017B2 /* TableViewModel.swift */; }; 13 | 78C7FBE01EC8F9DB00A209A3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C7FBDF1EC8F9DB00A209A3 /* AppDelegate.swift */; }; 14 | 78C7FBE21EC8F9DB00A209A3 /* MasterViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C7FBE11EC8F9DB00A209A3 /* MasterViewController.swift */; }; 15 | 78C7FBE41EC8F9DB00A209A3 /* DetailViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 78C7FBE31EC8F9DB00A209A3 /* DetailViewController.swift */; }; 16 | 78C7FBE71EC8F9DB00A209A3 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78C7FBE51EC8F9DB00A209A3 /* Main.storyboard */; }; 17 | 78C7FBE91EC8F9DB00A209A3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 78C7FBE81EC8F9DB00A209A3 /* Assets.xcassets */; }; 18 | 78C7FBEC1EC8F9DB00A209A3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 78C7FBEA1EC8F9DB00A209A3 /* LaunchScreen.storyboard */; }; 19 | /* End PBXBuildFile section */ 20 | 21 | /* Begin PBXFileReference section */ 22 | 780C2A821EDC6317005017B2 /* DateFormatHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateFormatHelper.swift; sourceTree = ""; }; 23 | 780C2A841EDC7556005017B2 /* DateTableViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateTableViewCell.swift; sourceTree = ""; }; 24 | 780C2A861EDCB4AD005017B2 /* TableViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableViewModel.swift; sourceTree = ""; }; 25 | 78C7FBDC1EC8F9DB00A209A3 /* Debugging.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Debugging.app; sourceTree = BUILT_PRODUCTS_DIR; }; 26 | 78C7FBDF1EC8F9DB00A209A3 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 27 | 78C7FBE11EC8F9DB00A209A3 /* MasterViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MasterViewController.swift; sourceTree = ""; }; 28 | 78C7FBE31EC8F9DB00A209A3 /* DetailViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailViewController.swift; sourceTree = ""; }; 29 | 78C7FBE61EC8F9DB00A209A3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 30 | 78C7FBE81EC8F9DB00A209A3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 31 | 78C7FBEB1EC8F9DB00A209A3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 32 | 78C7FBED1EC8F9DB00A209A3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 33 | /* End PBXFileReference section */ 34 | 35 | /* Begin PBXFrameworksBuildPhase section */ 36 | 78C7FBD91EC8F9DB00A209A3 /* Frameworks */ = { 37 | isa = PBXFrameworksBuildPhase; 38 | buildActionMask = 2147483647; 39 | files = ( 40 | ); 41 | runOnlyForDeploymentPostprocessing = 0; 42 | }; 43 | /* End PBXFrameworksBuildPhase section */ 44 | 45 | /* Begin PBXGroup section */ 46 | 78C7FBD31EC8F9DB00A209A3 = { 47 | isa = PBXGroup; 48 | children = ( 49 | 78C7FBDE1EC8F9DB00A209A3 /* Debugging */, 50 | 78C7FBDD1EC8F9DB00A209A3 /* Products */, 51 | ); 52 | sourceTree = ""; 53 | }; 54 | 78C7FBDD1EC8F9DB00A209A3 /* Products */ = { 55 | isa = PBXGroup; 56 | children = ( 57 | 78C7FBDC1EC8F9DB00A209A3 /* Debugging.app */, 58 | ); 59 | name = Products; 60 | sourceTree = ""; 61 | }; 62 | 78C7FBDE1EC8F9DB00A209A3 /* Debugging */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | 78C7FBDF1EC8F9DB00A209A3 /* AppDelegate.swift */, 66 | 78C7FBE11EC8F9DB00A209A3 /* MasterViewController.swift */, 67 | 78C7FBE31EC8F9DB00A209A3 /* DetailViewController.swift */, 68 | 780C2A841EDC7556005017B2 /* DateTableViewCell.swift */, 69 | 780C2A821EDC6317005017B2 /* DateFormatHelper.swift */, 70 | 780C2A861EDCB4AD005017B2 /* TableViewModel.swift */, 71 | 78C7FBE51EC8F9DB00A209A3 /* Main.storyboard */, 72 | 78C7FBE81EC8F9DB00A209A3 /* Assets.xcassets */, 73 | 78C7FBEA1EC8F9DB00A209A3 /* LaunchScreen.storyboard */, 74 | 78C7FBED1EC8F9DB00A209A3 /* Info.plist */, 75 | ); 76 | path = Debugging; 77 | sourceTree = ""; 78 | }; 79 | /* End PBXGroup section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | 78C7FBDB1EC8F9DB00A209A3 /* Debugging */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = 78C7FBF01EC8F9DB00A209A3 /* Build configuration list for PBXNativeTarget "Debugging" */; 85 | buildPhases = ( 86 | 78C7FBD81EC8F9DB00A209A3 /* Sources */, 87 | 78C7FBD91EC8F9DB00A209A3 /* Frameworks */, 88 | 78C7FBDA1EC8F9DB00A209A3 /* Resources */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = Debugging; 95 | productName = Debugging; 96 | productReference = 78C7FBDC1EC8F9DB00A209A3 /* Debugging.app */; 97 | productType = "com.apple.product-type.application"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | 78C7FBD41EC8F9DB00A209A3 /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | LastSwiftUpdateCheck = 0830; 106 | LastUpgradeCheck = 0830; 107 | ORGANIZATIONNAME = "Greg Heo"; 108 | TargetAttributes = { 109 | 78C7FBDB1EC8F9DB00A209A3 = { 110 | CreatedOnToolsVersion = 8.3.2; 111 | ProvisioningStyle = Automatic; 112 | }; 113 | }; 114 | }; 115 | buildConfigurationList = 78C7FBD71EC8F9DB00A209A3 /* Build configuration list for PBXProject "Debugging" */; 116 | compatibilityVersion = "Xcode 3.2"; 117 | developmentRegion = English; 118 | hasScannedForEncodings = 0; 119 | knownRegions = ( 120 | en, 121 | Base, 122 | ); 123 | mainGroup = 78C7FBD31EC8F9DB00A209A3; 124 | productRefGroup = 78C7FBDD1EC8F9DB00A209A3 /* Products */; 125 | projectDirPath = ""; 126 | projectRoot = ""; 127 | targets = ( 128 | 78C7FBDB1EC8F9DB00A209A3 /* Debugging */, 129 | ); 130 | }; 131 | /* End PBXProject section */ 132 | 133 | /* Begin PBXResourcesBuildPhase section */ 134 | 78C7FBDA1EC8F9DB00A209A3 /* Resources */ = { 135 | isa = PBXResourcesBuildPhase; 136 | buildActionMask = 2147483647; 137 | files = ( 138 | 78C7FBEC1EC8F9DB00A209A3 /* LaunchScreen.storyboard in Resources */, 139 | 78C7FBE91EC8F9DB00A209A3 /* Assets.xcassets in Resources */, 140 | 78C7FBE71EC8F9DB00A209A3 /* Main.storyboard in Resources */, 141 | ); 142 | runOnlyForDeploymentPostprocessing = 0; 143 | }; 144 | /* End PBXResourcesBuildPhase section */ 145 | 146 | /* Begin PBXSourcesBuildPhase section */ 147 | 78C7FBD81EC8F9DB00A209A3 /* Sources */ = { 148 | isa = PBXSourcesBuildPhase; 149 | buildActionMask = 2147483647; 150 | files = ( 151 | 780C2A851EDC7556005017B2 /* DateTableViewCell.swift in Sources */, 152 | 78C7FBE41EC8F9DB00A209A3 /* DetailViewController.swift in Sources */, 153 | 78C7FBE21EC8F9DB00A209A3 /* MasterViewController.swift in Sources */, 154 | 780C2A871EDCB4AD005017B2 /* TableViewModel.swift in Sources */, 155 | 780C2A831EDC6317005017B2 /* DateFormatHelper.swift in Sources */, 156 | 78C7FBE01EC8F9DB00A209A3 /* AppDelegate.swift in Sources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXSourcesBuildPhase section */ 161 | 162 | /* Begin PBXVariantGroup section */ 163 | 78C7FBE51EC8F9DB00A209A3 /* Main.storyboard */ = { 164 | isa = PBXVariantGroup; 165 | children = ( 166 | 78C7FBE61EC8F9DB00A209A3 /* Base */, 167 | ); 168 | name = Main.storyboard; 169 | sourceTree = ""; 170 | }; 171 | 78C7FBEA1EC8F9DB00A209A3 /* LaunchScreen.storyboard */ = { 172 | isa = PBXVariantGroup; 173 | children = ( 174 | 78C7FBEB1EC8F9DB00A209A3 /* Base */, 175 | ); 176 | name = LaunchScreen.storyboard; 177 | sourceTree = ""; 178 | }; 179 | /* End PBXVariantGroup section */ 180 | 181 | /* Begin XCBuildConfiguration section */ 182 | 78C7FBEE1EC8F9DB00A209A3 /* Debug */ = { 183 | isa = XCBuildConfiguration; 184 | buildSettings = { 185 | ALWAYS_SEARCH_USER_PATHS = NO; 186 | CLANG_ANALYZER_NONNULL = YES; 187 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 188 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 189 | CLANG_CXX_LIBRARY = "libc++"; 190 | CLANG_ENABLE_MODULES = YES; 191 | CLANG_ENABLE_OBJC_ARC = YES; 192 | CLANG_WARN_BOOL_CONVERSION = YES; 193 | CLANG_WARN_CONSTANT_CONVERSION = YES; 194 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 195 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 196 | CLANG_WARN_EMPTY_BODY = YES; 197 | CLANG_WARN_ENUM_CONVERSION = YES; 198 | CLANG_WARN_INFINITE_RECURSION = YES; 199 | CLANG_WARN_INT_CONVERSION = YES; 200 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 201 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 202 | CLANG_WARN_UNREACHABLE_CODE = YES; 203 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 204 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 205 | COPY_PHASE_STRIP = NO; 206 | DEBUG_INFORMATION_FORMAT = dwarf; 207 | ENABLE_STRICT_OBJC_MSGSEND = YES; 208 | ENABLE_TESTABILITY = YES; 209 | GCC_C_LANGUAGE_STANDARD = gnu99; 210 | GCC_DYNAMIC_NO_PIC = NO; 211 | GCC_NO_COMMON_BLOCKS = YES; 212 | GCC_OPTIMIZATION_LEVEL = 0; 213 | GCC_PREPROCESSOR_DEFINITIONS = ( 214 | "DEBUG=1", 215 | "$(inherited)", 216 | ); 217 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 218 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 219 | GCC_WARN_UNDECLARED_SELECTOR = YES; 220 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 221 | GCC_WARN_UNUSED_FUNCTION = YES; 222 | GCC_WARN_UNUSED_VARIABLE = YES; 223 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 224 | MTL_ENABLE_DEBUG_INFO = YES; 225 | ONLY_ACTIVE_ARCH = YES; 226 | SDKROOT = iphoneos; 227 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 228 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 229 | TARGETED_DEVICE_FAMILY = "1,2"; 230 | }; 231 | name = Debug; 232 | }; 233 | 78C7FBEF1EC8F9DB00A209A3 /* Release */ = { 234 | isa = XCBuildConfiguration; 235 | buildSettings = { 236 | ALWAYS_SEARCH_USER_PATHS = NO; 237 | CLANG_ANALYZER_NONNULL = YES; 238 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 239 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 240 | CLANG_CXX_LIBRARY = "libc++"; 241 | CLANG_ENABLE_MODULES = YES; 242 | CLANG_ENABLE_OBJC_ARC = YES; 243 | CLANG_WARN_BOOL_CONVERSION = YES; 244 | CLANG_WARN_CONSTANT_CONVERSION = YES; 245 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 246 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 247 | CLANG_WARN_EMPTY_BODY = YES; 248 | CLANG_WARN_ENUM_CONVERSION = YES; 249 | CLANG_WARN_INFINITE_RECURSION = YES; 250 | CLANG_WARN_INT_CONVERSION = YES; 251 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 252 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 253 | CLANG_WARN_UNREACHABLE_CODE = YES; 254 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 255 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 256 | COPY_PHASE_STRIP = NO; 257 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 258 | ENABLE_NS_ASSERTIONS = NO; 259 | ENABLE_STRICT_OBJC_MSGSEND = YES; 260 | GCC_C_LANGUAGE_STANDARD = gnu99; 261 | GCC_NO_COMMON_BLOCKS = YES; 262 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 263 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 264 | GCC_WARN_UNDECLARED_SELECTOR = YES; 265 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 266 | GCC_WARN_UNUSED_FUNCTION = YES; 267 | GCC_WARN_UNUSED_VARIABLE = YES; 268 | IPHONEOS_DEPLOYMENT_TARGET = 10.3; 269 | MTL_ENABLE_DEBUG_INFO = NO; 270 | SDKROOT = iphoneos; 271 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 272 | TARGETED_DEVICE_FAMILY = "1,2"; 273 | VALIDATE_PRODUCT = YES; 274 | }; 275 | name = Release; 276 | }; 277 | 78C7FBF11EC8F9DB00A209A3 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 281 | INFOPLIST_FILE = Debugging/Info.plist; 282 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 283 | PRODUCT_BUNDLE_IDENTIFIER = com.gregheo.Debugging; 284 | PRODUCT_NAME = "$(TARGET_NAME)"; 285 | SWIFT_VERSION = 3.0; 286 | }; 287 | name = Debug; 288 | }; 289 | 78C7FBF21EC8F9DB00A209A3 /* Release */ = { 290 | isa = XCBuildConfiguration; 291 | buildSettings = { 292 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 293 | INFOPLIST_FILE = Debugging/Info.plist; 294 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 295 | PRODUCT_BUNDLE_IDENTIFIER = com.gregheo.Debugging; 296 | PRODUCT_NAME = "$(TARGET_NAME)"; 297 | SWIFT_VERSION = 3.0; 298 | }; 299 | name = Release; 300 | }; 301 | /* End XCBuildConfiguration section */ 302 | 303 | /* Begin XCConfigurationList section */ 304 | 78C7FBD71EC8F9DB00A209A3 /* Build configuration list for PBXProject "Debugging" */ = { 305 | isa = XCConfigurationList; 306 | buildConfigurations = ( 307 | 78C7FBEE1EC8F9DB00A209A3 /* Debug */, 308 | 78C7FBEF1EC8F9DB00A209A3 /* Release */, 309 | ); 310 | defaultConfigurationIsVisible = 0; 311 | defaultConfigurationName = Release; 312 | }; 313 | 78C7FBF01EC8F9DB00A209A3 /* Build configuration list for PBXNativeTarget "Debugging" */ = { 314 | isa = XCConfigurationList; 315 | buildConfigurations = ( 316 | 78C7FBF11EC8F9DB00A209A3 /* Debug */, 317 | 78C7FBF21EC8F9DB00A209A3 /* Release */, 318 | ); 319 | defaultConfigurationIsVisible = 0; 320 | defaultConfigurationName = Release; 321 | }; 322 | /* End XCConfigurationList section */ 323 | }; 324 | rootObject = 78C7FBD41EC8F9DB00A209A3 /* Project object */; 325 | } 326 | -------------------------------------------------------------------------------- /Debugging.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Debugging/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Debugging 4 | // 5 | // Created by Greg Heo on 5/14/17. 6 | // Copyright © 2017 Greg Heo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate, UISplitViewControllerDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 18 | // Override point for customization after application launch. 19 | let splitViewController = window!.rootViewController as! UISplitViewController 20 | let navigationController = splitViewController.viewControllers[splitViewController.viewControllers.count-1] as! UINavigationController 21 | navigationController.topViewController!.navigationItem.leftBarButtonItem = splitViewController.displayModeButtonItem 22 | splitViewController.delegate = self 23 | return true 24 | } 25 | 26 | func applicationWillResignActive(_ application: UIApplication) { 27 | // 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. 28 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game. 29 | } 30 | 31 | func applicationDidEnterBackground(_ application: UIApplication) { 32 | // 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. 33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 34 | } 35 | 36 | func applicationWillEnterForeground(_ application: UIApplication) { 37 | // 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. 38 | } 39 | 40 | func applicationDidBecomeActive(_ application: UIApplication) { 41 | // 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. 42 | } 43 | 44 | func applicationWillTerminate(_ application: UIApplication) { 45 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 46 | } 47 | 48 | // MARK: - Split view 49 | 50 | func splitViewController(_ splitViewController: UISplitViewController, collapseSecondary secondaryViewController:UIViewController, onto primaryViewController:UIViewController) -> Bool { 51 | guard let secondaryAsNavController = secondaryViewController as? UINavigationController else { return false } 52 | guard let topAsDetailController = secondaryAsNavController.topViewController as? DetailViewController else { return false } 53 | if topAsDetailController.detailItem == nil { 54 | // Return true to indicate that we have handled the collapse by doing nothing; the secondary controller will be discarded. 55 | return true 56 | } 57 | return false 58 | } 59 | 60 | } 61 | 62 | -------------------------------------------------------------------------------- /Debugging/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "ipad", 35 | "size" : "29x29", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "ipad", 40 | "size" : "29x29", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "40x40", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "40x40", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "76x76", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "76x76", 61 | "scale" : "2x" 62 | } 63 | ], 64 | "info" : { 65 | "version" : 1, 66 | "author" : "xcode" 67 | } 68 | } -------------------------------------------------------------------------------- /Debugging/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 | -------------------------------------------------------------------------------- /Debugging/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 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 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 | 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 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | -------------------------------------------------------------------------------- /Debugging/DateFormatHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateFormatHelper.swift 3 | // Debugging 4 | // 5 | 6 | import UIKit 7 | 8 | class DateFormatHelper { 9 | var date: Date 10 | var dateFormatter: DateFormatter 11 | 12 | init(date: Date, dateFormatter: DateFormatter) { 13 | self.date = date 14 | self.dateFormatter = dateFormatter 15 | } 16 | 17 | var formatForCell: ((UITableViewCell) -> Void)? 18 | var formatForLabel: ((UILabel) -> Void)? 19 | } 20 | -------------------------------------------------------------------------------- /Debugging/DateTableViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DateTableViewCell.swift 3 | // Debugging 4 | // 5 | // Created by Greg Heo on 5/29/17. 6 | // Copyright © 2017 Greg Heo. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class DateTableViewCell: UITableViewCell { 12 | var dateFormatHelper: DateFormatHelper? 13 | 14 | func refresh() { 15 | self.dateFormatHelper?.formatForCell?(self) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Debugging/DetailViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DetailViewController.swift 3 | // Debugging 4 | // 5 | 6 | import UIKit 7 | 8 | class DetailViewController: UIViewController { 9 | @IBOutlet var detailDescriptionLabel: UILabel? 10 | 11 | var detailItem: Date? 12 | var dateFormatHelper: DateFormatHelper? 13 | 14 | func configureView() { 15 | self.dateFormatHelper?.formatForLabel?(detailDescriptionLabel!) 16 | } 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | 21 | dateFormatHelper?.formatForLabel = { label in 22 | label.text = self.detailItem?.description 23 | } 24 | 25 | // Do any additional setup after loading the view, typically from a nib. 26 | configureView() 27 | } 28 | 29 | override func didReceiveMemoryWarning() { 30 | super.didReceiveMemoryWarning() 31 | // Dispose of any resources that can be recreated. 32 | } 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /Debugging/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 | 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 | UIStatusBarTintParameters 32 | 33 | UINavigationBar 34 | 35 | Style 36 | UIBarStyleDefault 37 | Translucent 38 | 39 | 40 | 41 | UISupportedInterfaceOrientations 42 | 43 | UIInterfaceOrientationPortrait 44 | UIInterfaceOrientationLandscapeLeft 45 | UIInterfaceOrientationLandscapeRight 46 | 47 | UISupportedInterfaceOrientations~ipad 48 | 49 | UIInterfaceOrientationPortrait 50 | UIInterfaceOrientationPortraitUpsideDown 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Debugging/MasterViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // MasterViewController.swift 3 | // Debugging 4 | // 5 | 6 | import UIKit 7 | 8 | class MasterViewController: UITableViewController { 9 | lazy var dateFormatter: DateFormatter = { 10 | let df = DateFormatter() 11 | df.dateStyle = .long 12 | df.timeStyle = .long 13 | return df 14 | }() 15 | 16 | var detailViewController: DetailViewController? = nil 17 | var dates = TableViewModel() 18 | 19 | override func viewDidLoad() { 20 | super.viewDidLoad() 21 | // Do any additional setup after loading the view, typically from a nib. 22 | navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Reverse", style: .plain, target: self, action: #selector(reverseItems)) 23 | 24 | let addButton = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(insertNewObject(_:))) 25 | navigationItem.rightBarButtonItem = addButton 26 | if let split = splitViewController { 27 | let controllers = split.viewControllers 28 | detailViewController = (controllers[controllers.count-1] as! UINavigationController).topViewController as? DetailViewController 29 | } 30 | } 31 | 32 | override func viewWillAppear(_ animated: Bool) { 33 | clearsSelectionOnViewWillAppear = splitViewController!.isCollapsed 34 | super.viewWillAppear(animated) 35 | } 36 | 37 | override func didReceiveMemoryWarning() { 38 | super.didReceiveMemoryWarning() 39 | // Dispose of any resources that can be recreated. 40 | } 41 | 42 | func insertNewObject(_ sender: Any) { 43 | dates.add(Date()) 44 | let indexPath = IndexPath(row: 0, section: 0) 45 | tableView.insertRows(at: [indexPath], with: .automatic) 46 | } 47 | 48 | // MARK: - Segues 49 | 50 | override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 51 | if segue.identifier == "showDetail" { 52 | if let indexPath = tableView.indexPathForSelectedRow, let date = dates.item(at: indexPath.row) { 53 | let controller = (segue.destination as! UINavigationController).topViewController as! DetailViewController 54 | controller.detailItem = date 55 | controller.dateFormatHelper = dateFormatHelperForDate(date: date) 56 | controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem 57 | controller.navigationItem.leftItemsSupplementBackButton = true 58 | } 59 | } 60 | } 61 | 62 | // MARK: - Table View 63 | 64 | override func numberOfSections(in tableView: UITableView) -> Int { 65 | return 1 66 | } 67 | 68 | override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 69 | return dates.items.count 70 | } 71 | 72 | override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> DateTableViewCell { 73 | let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! DateTableViewCell 74 | 75 | if let date = dates.item(at: indexPath.row) { 76 | cell.dateFormatHelper = dateFormatHelperForDate(date: date) 77 | cell.refresh() 78 | } else { 79 | cell.textLabel?.text = "???" 80 | } 81 | 82 | return cell 83 | } 84 | 85 | override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 86 | // Return false if you do not want the specified item to be editable. 87 | return false 88 | } 89 | 90 | override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { 91 | if editingStyle == .delete { 92 | dates.remove(at: indexPath.row) 93 | tableView.deleteRows(at: [indexPath], with: .fade) 94 | } 95 | } 96 | 97 | func reverseItems() { 98 | self.dates.reverse() 99 | self.tableView.reloadData() 100 | } 101 | 102 | private func dateFormatHelperForDate(date: Date) -> DateFormatHelper { 103 | let formatHelper = DateFormatHelper(date: date, dateFormatter: dateFormatter) 104 | formatHelper.formatForCell = { cell in 105 | cell.textLabel?.text = self.dateFormatter.string(from: date) 106 | } 107 | 108 | return formatHelper 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Debugging/TableViewModel.swift: -------------------------------------------------------------------------------- 1 | // 2 | // TableViewModel.swift 3 | // Debugging 4 | // 5 | 6 | import Foundation 7 | 8 | public final class TableViewModel { 9 | var items: [T] = [] 10 | var queue: DispatchQueue 11 | 12 | public init() { 13 | queue = DispatchQueue(label: "xyz.swiftaveiro.queue", 14 | qos: .userInteractive, 15 | attributes: [], 16 | autoreleaseFrequency: .inherit, 17 | target: nil) 18 | } 19 | 20 | public var count: Int { 21 | var count = 0 22 | queue.sync { 23 | count = items.count 24 | } 25 | return count 26 | } 27 | 28 | public func add(_ item: T) { 29 | queue.sync { 30 | let oldCount = self.items.count 31 | self.items.insert(item, at: 0) 32 | assert(self.items.count > oldCount) 33 | } 34 | } 35 | 36 | public func remove(at index: Int) { 37 | queue.async { 38 | self.items.remove(at: index) 39 | } 40 | } 41 | 42 | public func item(at index: Int) -> T? { 43 | var item: T? 44 | queue.sync { 45 | if index < self.items.count { 46 | item = self.items[index] 47 | } 48 | } 49 | return item 50 | } 51 | 52 | public func reverse() { 53 | queue.async { 54 | self.items = self.items.reversed() 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # Swift Aveiro 2017: Debugging Workshop 2 | 3 | ## Part 1: Symbolic Debugging 4 | 5 | We looked at using *symbolic breakpoints* to inspect how an app works. 6 | 7 | ![Symbolic breakpoints](assets/symbolic-breakpoint.png) 8 | 9 | For example, how does the navigation in an app work? We can try adding breakpoints at some common navigation locations: 10 | 11 | * `-[UINavigationController pushViewController:animated:]` 12 | * `-[UIViewController presentViewController:animated:completion:]` 13 | * `-[UIViewController addChildViewController:]` 14 | 15 | We can combine our knowledge of UIKit with lldb to find good places for symbolic breakpoints. 16 | 17 | ### LLDB Tips 18 | 19 | **Remember to import UIKit!** You might need to import it in both "Swift mode" and "Objective-C" mode. 20 | 21 | ``` 22 | expr -l swift -- import UIKit 23 | expr @import UIKit 24 | ``` 25 | 26 | **Swift variables in lldb**: get typed variables in LLDB Swift mode: 27 | 28 | ``` 29 | expr -l Swift -- let $view = unsafeBitCast(0x7df67c50, to: UIView.self) 30 | expr -l Swift -- print($view.frame) 31 | ``` 32 | 33 | **Swift in LLDB**: If you like Swift, you can add a command alias to your `~/.lldbinit` file: 34 | 35 | ``` 36 | command alias sc expression -l swift -- 37 | ``` 38 | 39 | Then in lldb, you can use `sc import UIKit` rather than `expr -l swift -- import UIKit`. Hat tip to [Jorge Ortiz](https://github.com/jdortiz) for the alias! 40 | 41 | 42 | ## Part 2: Chisel 43 | 44 | We looked at [Chisel](https://github.com/facebook/chisel), an open-source project from Facebook that adds extra debugging commands to lldb. 45 | 46 | Remember, you can replace `` below with an instance or a hex address. 47 | 48 | Some favorites: 49 | 50 | |Command |Notes | 51 | |------------------|----------------| 52 | |pviews|Print the `recursiveDescription` of the key window| 53 | |pvc|Print the recursive view controller hierarchy of the key window| 54 | |pinternals |Print the internals (instance variables, etc.) of the object| 55 | |pclass |Print the class hierarchy of an object| 56 | |mask/unmask |Put a transparent color view on top of the view| 57 | |border/unborder |Draw a border around the view| 58 | |visualize |Render the target to a PNG and open it in Preview.app| 59 | |pdocspath |Print out the Documents directory path| 60 | |pbundlepath |Print out the app bundle directory path| 61 | 62 | ## Part 2.5: View Debugging 63 | 64 | We took a quick sidebar to talk about [FLEX](https://github.com/Flipboard/FLEX) and [UIDebuggingInformationOverlay](http://ryanipete.com/blog/ios/swift/objective-c/uidebugginginformationoverlay/) for visual debugging. 65 | 66 | FLEX is an amazing debugging tool (not just for view debugging) and it's very easy to integrate into your own apps. 67 | 68 | ## Part 3: New Debugging Features in Xcode 69 | 70 | We looked at the memory graph debugger in Xcode to inspect memory usage and detect retain cycles. Note that you can't activate the memory graph debugger if you have the thread sanitizer option turned on. 71 | 72 | ![Memory graph debugger button](assets/memory-graph.png) 73 | 74 | Next, we looked at the thread sanitizer to help find race conditions and threading issues. 75 | 76 | The thread sanitizer only works in the simulator and slows down the app. You can activate it in the scheme editor. 77 | 78 | ![Thread sanitizer](assets/tsan.png) 79 | 80 | Here's the lovely retain cycle I made special for this session: 81 | 82 | ![Retain cycle](assets/cycle.png) 83 | 84 | 😜 85 | -------------------------------------------------------------------------------- /assets/cycle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gregheo/SwiftAveiro2017/4f36e2b243279d395882ecc9337f5a80b2c6e57e/assets/cycle.png -------------------------------------------------------------------------------- /assets/memory-graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gregheo/SwiftAveiro2017/4f36e2b243279d395882ecc9337f5a80b2c6e57e/assets/memory-graph.png -------------------------------------------------------------------------------- /assets/symbolic-breakpoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gregheo/SwiftAveiro2017/4f36e2b243279d395882ecc9337f5a80b2c6e57e/assets/symbolic-breakpoint.png -------------------------------------------------------------------------------- /assets/tsan.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gregheo/SwiftAveiro2017/4f36e2b243279d395882ecc9337f5a80b2c6e57e/assets/tsan.png --------------------------------------------------------------------------------