Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Debugging - Things your senior hasn't told you ...

Debugging - Things your senior hasn't told you about

We as developers are spending 50% of our time either fixing bugs or making code work. In this talk we’re going over breakpoints, commands, arguments and tools that will help you be more efficient and faster when debugging your Apps.

Carola Nitz

April 16, 2018
Tweet

More Decks by Carola Nitz

Other Decks in Technology

Transcript

  1. COVERED TOPICS ▸ Get more information ▸ How you can

    speed up debugging 8 — @_Caro_N, 4/16/2018
  2. COVERED TOPICS ▸ Get more information ▸ How you can

    speed up debugging ▸ Best practices for error handling & debugging 9 — @_Caro_N, 4/16/2018
  3. LAUNCH ARGUMENTS -com.apple.CoreData.ConcurrencyDebug 1 Core Data Concurrency Debugging by Ole

    Begemann https://oleb.net/blog/2014/06/core-data-concurrency-debugging/ 24 — @_Caro_N, 4/16/2018
  4. ✨ iOS Debugging Magic https://developer.apple.com/library/content/technotes/tn2239 ✨ Mac OS X Debugging

    Magic https://developer.apple.com/library/content/technotes/tn2124 27 — @_Caro_N, 4/16/2018
  5. KEYPATHS let colorObservation = textFieldBackground.observe(\.backgroundColor, options:[.old, .new]) { (_, change)

    in) log.debug("color:\( change.oldValue ) -> \( change.newValue )") log.debug("") } 29 — @_Caro_N, 4/16/2018
  6. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' 30 — @_Caro_N, 4/16/2018
  7. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' (lldb) expr -l swift -O -- UIApplication.shared <UIApplication:0x7fa384d00260> 31 — @_Caro_N, 4/16/2018
  8. (lldb) po UIApplication.shared error: property 'shared' not found on object

    of type 'UIApplication' (lldb) expr -l swift -O -- UIApplication.shared <UIApplication:0x7fa384d00260> (lldb) expr @import UIKit (lldb) expr @import Foundation 32 — @_Caro_N, 4/16/2018
  9. USEFUL BREAKPOINTS -UIApplicationMain Debugger command: expr @import UIKit Debugger command:

    expr @import Foundation -NSKVODeallocateBreak -Exception Breakpoint: Objective-C Debugger command: po $arg1 User Breakpoints in Xcode by Michael Ochs https://pspdfkit.com/blog/2017/user-breakpoints-in-xcode/ 36 — @_Caro_N, 4/16/2018
  10. ASSERT func transformString(string: String?) -> String { assert(string != nil,

    "Invalid parameter") return string! + "_transforme" } 39 — @_Caro_N, 4/16/2018
  11. ASSERTIONFAILURE case RemoteNetworkCell.cloud.rawValue: if let networkCell = tableView.dequeueReusableCell(withIdentifier: VLCRemoteNetworkCell.cellIdentifier) {

    networkCell.textLabel?.text = cloudVC.title networkCell.detailTextLabel?.text = cloudVC.detailText networkCell.imageView?.image = cloudVC.cellImage return networkCell } case RemoteNetworkCell.wifi.rawValue: if let wifiCell = tableView.dequeueReusableCell(withIdentifier: VLCWiFiUploadTableViewCell.cellIdentifier()) { return wifiCell } default: assertionFailure("We're not handling a new CellType, add him to the cases") } assertionFailure("Cell is nil, did you forget to register the identifier?") return UITableViewCell() 40 — @_Caro_N, 4/16/2018
  12. SWIFT_OPTIMIZATION_LEVEL = -Onone // debug SWIFT_OPTIMIZATION_LEVEL = -O // release

    SWIFT_OPTIMIZATION_LEVEL = -Ounchecked // unchecked release 41 — @_Caro_N, 4/16/2018
  13. PRECONDITION internal init(_repeating repeatedValue: Element, count: Int) { _precondition(count >=

    0, "Repetition count should be non-negative") self.count = count self.repeatedValue = repeatedValue } 43 — @_Caro_N, 4/16/2018
  14. FATALERROR internal enum _Normalization { // ICU's NFC unorm2 instance

    internal static var _nfcNormalizer: OpaquePointer = { var err = __swift_stdlib_U_ZERO_ERROR let normalizer = __swift_stdlib_unorm2_getNFCInstance(&err) guard err.isSuccess else { // This shouldn't be possible unless some deep (unrecoverable) system // invariants are violated fatalError("Unable to talk to ICU") } return normalizer }() 44 — @_Caro_N, 4/16/2018
  15. DEBUG RELEASE RELEASE function -Onone -O -Ounchecked assert() Yes No

    No assertfailure() Yes No No precondition() Yes Yes No preconditionFailu re() Yes Yes Yes fatalerror() Yes Yes Yes 45 — @_Caro_N, 4/16/2018
  16. SUMMARY ▸ Read register, Launch arguments ▸ Keypaths, User Breakpoints

    ▸ assert, precondition, fatalerror 46 — @_Caro_N, 4/16/2018
  17. Resources: Launch Arguments & Environment Variables by Mattt Thompson http://nshipster.com/launch-arguments-and-environment-variables/

    Swift Assertions by Andy Bargh https://andybargh.com/swift-assertions/ Swift asserts - the missing manual by Marcin Krzyzanowski http://blog.krzyzanowskim.com/2015/03/09/swift-asserts-the-missing-manual/ Debugging by Paul Hudson https://www.hackingwithswift.com/read/18/overview 47 — @_Caro_N, 4/16/2018