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

Xcode Survival Guide

Kristina Fox
February 20, 2019

Xcode Survival Guide

Want to take your Xcode skills to the next level? Join me as we take a literal journey through various tips, hacks, and tricks that can make you a more efficient iOS developer. Aimed at iOS developers from beginner to advanced, in this session attendees will walk away with at least one new trick up their sleeve to impress and delight their fellow iOS engineers. Presented at Developer Week 2019.

https://kristina.io

Kristina Fox

February 20, 2019
Tweet

More Decks by Kristina Fox

Other Decks in Technology

Transcript

  1. 1
    The Xcode Survival
    Guide
    Kristina Fox 

    Senior iOS Engineer

    @krstnfx

    View Slide

  2. kristina.io | @krstnfx | #devweek2019
    2
    Hi, I’m Kristina

    View Slide

  3. 3

    View Slide

  4. The Xcode Survival Guide

    View Slide

  5. kristina.io | @krstnfx | #devweek2019
    5

    View Slide

  6. kristina.io | @krstnfx | #devweek2019
    6

    View Slide

  7. kristina.io | @krstnfx | #devweek2019
    7


    View Slide

  8. kristina.io | @krstnfx | #devweek2019
    8

    View Slide

  9. kristina.io | @krstnfx | #devweek2019
    9

    View Slide

  10. kristina.io | @krstnfx | #devweek2019
    10

    View Slide

  11. kristina.io | @krstnfx | #devweek2019
    11
    Pete’s very strange day
    )

    View Slide

  12. kristina.io | @krstnfx | #devweek2019
    12

    View Slide

  13. kristina.io | @krstnfx | #devweek2019
    13

    View Slide

  14. kristina.io | @krstnfx | #devweek2019
    14

    View Slide

  15. kristina.io | @krstnfx | #devweek2019
    15

    View Slide

  16. kristina.io | @krstnfx | #devweek2019
    16
    Color assets

    View Slide

  17. kristina.io | @krstnfx | #devweek2019
    17

    View Slide

  18. kristina.io | @krstnfx | #devweek2019
    18
    Lock Storyboard Elements
    Lock -> All Properties

    View Slide

  19. kristina.io | @krstnfx | #devweek2019
    19
    20:00

    View Slide

  20. kristina.io | @krstnfx | #devweek2019
    20

    View Slide

  21. kristina.io | @krstnfx | #devweek2019
    21
    Multiple assistant editors

    View Slide

  22. kristina.io | @krstnfx | #devweek2019
    22

    View Slide

  23. kristina.io | @krstnfx | #devweek2019
    23
    Assistant editor view mode
    All Editors Stacked Horizontally

    View Slide

  24. kristina.io | @krstnfx | #devweek2019
    24
    Select file view location
    Alt + Shift + Click

    View Slide

  25. kristina.io | @krstnfx | #devweek2019
    25

    View Slide

  26. kristina.io | @krstnfx | #devweek2019
    26

    View Slide

  27. kristina.io | @krstnfx | #devweek2019
    27
    Change command-click option

    View Slide

  28. kristina.io | @krstnfx | #devweek2019
    28
    Quick Open function List
    Ctrl + 6

    View Slide

  29. kristina.io | @krstnfx | #devweek2019
    29
    Search function signatures
    Ctrl + 6
    Just start typing

    View Slide

  30. kristina.io | @krstnfx | #devweek2019
    30
    //
    // DryExecutionHandler.swift
    // Resin
    //
    import Foundation
    class DryExecutionHandler: NSObject {
    override init() {
    let network = Network()
    network.executeDrying()
    }
    }
    //
    // RinseExecutionHandler.swift
    // Resin
    //
    import Foundation
    class RinseExecutionHandler: NSObject {
    override init() {
    let network = Network()
    network.executeRinsing()
    }
    }
    //
    // StickExecutionHandler.swift
    // Resin
    //
    //
    import Foundation
    class StickExecutionHandler: NSObject {
    override init() {
    let network = Network()
    network.executeStickiness()
    }
    }

    View Slide

  31. kristina.io | @krstnfx | #devweek2019
    31
    //
    // Network.swift
    // Resin
    //
    import Foundation
    class Network: NSObject {
    func executeDrying() {
    let url = "resin-prod.com/dry"
    executeAction(url: url)
    }
    func executeStickiness() {
    let url = "resin-prod.com/sticky"
    executeAction(url: url)
    }
    func executeRinsing() {
    let url = "resin-dev.com/rinse"
    executeAction(url: url)
    }
    }

    View Slide

  32. kristina.io | @krstnfx | #devweek2019
    32
    //
    // Network.swift
    // Resin
    //
    import Foundation
    class Network: NSObject {
    func executeDrying() {
    let url = "resin-prod.com/dry"
    executeAction(url: url)
    }
    func executeStickiness() {
    let url = "resin-prod.com/sticky"
    executeAction(url: url)
    }
    func executeRinsing() {
    let url = "resin-dev.com/rinse"
    executeAction(url: url)
    }
    }

    View Slide

  33. kristina.io | @krstnfx | #devweek2019
    33
    //
    // Network.swift
    // Resin
    //
    import Foundation
    class Network: NSObject {
    func executeDrying() {
    let url = "resin-prod.com/dry"
    executeAction(url: url)
    }
    func executeStickiness() {
    let url = "resin-prod.com/sticky"
    executeAction(url: url)
    }
    func executeRinsing() {
    let url = "resin-dev.com/rinse"
    executeAction(url: url)
    }
    }

    View Slide

  34. kristina.io | @krstnfx | #devweek2019
    34
    User Defined Build Settings
    Project file -> Build Settings -> User-Defined Settings
    02:49

    View Slide

  35. kristina.io | @krstnfx | #devweek2019
    35

    View Slide

  36. kristina.io | @krstnfx | #devweek2019
    36

    Stage 1
    complete

    View Slide

  37. kristina.io | @krstnfx | #devweek2019
    37

    View Slide

  38. kristina.io | @krstnfx | #devweek2019
    38


    View Slide

  39. kristina.io | @krstnfx | #devweek2019
    39

    View Slide

  40. kristina.io | @krstnfx | #devweek2019
    40

    View Slide

  41. kristina.io | @krstnfx | #devweek2019
    41

    View Slide

  42. kristina.io | @krstnfx | #devweek2019
    42
    Device Crash Logs
    1. Windows -> Devices and Simulators
    2. Choose Devices tab
    3. View device logs

    View Slide

  43. kristina.io | @krstnfx | #devweek2019
    43
    “Catch all” Breakpoints

    View Slide

  44. kristina.io | @krstnfx | #devweek2019
    44
    Editing Breakpoints

    View Slide

  45. kristina.io | @krstnfx | #devweek2019
    45
    Add an Action

    View Slide

  46. kristina.io | @krstnfx | #devweek2019
    46
    //
    // Room.swift
    // GasMask
    //
    import Foundation
    class Room: NSObject, NSCoding {
    var name: String?
    var id: Int?
    required init?(coder aDecoder: NSCoder) {
    self.name = aDecoder.decodeObject(forKey: "names") as? String
    self.id = aDecoder.decodeObject(forKey: "id") as? Int
    }
    func encode(with aCoder: NSCoder) {
    aCoder.encode(self.name, forKey: "name")
    aCoder.encode(self.id, forKey: "id")
    }
    }

    View Slide

  47. kristina.io | @krstnfx | #devweek2019
    47
    //
    // Room.swift
    // GasMask
    //
    import Foundation
    class Room: NSObject, NSCoding {
    var name: String?
    var id: Int?
    required init?(coder aDecoder: NSCoder) {
    self.name = aDecoder.decodeObject(forKey: "names") as? String
    self.id = aDecoder.decodeObject(forKey: "id") as? Int
    }
    func encode(with aCoder: NSCoder) {
    aCoder.encode(self.name, forKey: "name")
    aCoder.encode(self.id, forKey: "id")
    }
    }

    View Slide

  48. kristina.io | @krstnfx | #devweek2019
    48
    //
    // Room.swift
    // GasMask
    //
    import Foundation
    class Room: NSObject, NSCoding {
    var name: String?
    var id: Int?
    required init?(coder aDecoder: NSCoder) {
    self.name = aDecoder.decodeObject(forKey: "names") as? String
    self.id = aDecoder.decodeObject(forKey: "id") as? Int
    }
    func encode(with aCoder: NSCoder) {
    aCoder.encode(self.name, forKey: "name")
    aCoder.encode(self.id, forKey: "id")
    }
    }

    View Slide

  49. kristina.io | @krstnfx | #devweek2019
    49
    struct Rooms: Codable {
    var name: String
    var id: Int
    }

    View Slide

  50. kristina.io | @krstnfx | #devweek2019
    50
    Custom Code Snippets
    1. Highlight code
    2. Drag to code snippets window
    3. Drop & fill completion shortcut

    View Slide

  51. kristina.io | @krstnfx | #devweek2019
    51
    Custom Code Snippets in Use
    4. Profit

    View Slide

  52. kristina.io | @krstnfx | #devweek2019
    52

    View Slide

  53. kristina.io | @krstnfx | #devweek2019
    53

    View Slide

  54. kristina.io | @krstnfx | #devweek2019
    54

    View Slide

  55. kristina.io | @krstnfx | #devweek2019
    55

    Stage 2
    complete

    View Slide

  56. kristina.io | @krstnfx | #devweek2019
    56

    View Slide

  57. kristina.io | @krstnfx | #devweek2019
    57

    View Slide

  58. kristina.io | @krstnfx | #devweek2019
    58
    SUDDEN
    DEATH

    View Slide

  59. kristina.io | @krstnfx | #devweek2019
    59
    > Your colleague is having a hard time debugging an animation in
    simulator. What do you suggest?

    View Slide

  60. kristina.io | @krstnfx | #devweek2019
    60
    Debug animations

    View Slide

  61. kristina.io | @krstnfx | #devweek2019
    61
    > You want to use one of your own photos to test your app. What’s the best
    way to load it in simulator?

    View Slide

  62. kristina.io | @krstnfx | #devweek2019
    62
    Drag and Drop Media into simulator

    View Slide

  63. kristina.io | @krstnfx | #devweek2019
    63
    > What’s the easiest way to find all strings that look like
    email addresses in your app?

    View Slide

  64. kristina.io | @krstnfx | #devweek2019
    64
    Pattern Matching in Search

    View Slide

  65. kristina.io | @krstnfx | #devweek2019
    65
    Pattern Matching in Search

    View Slide

  66. kristina.io | @krstnfx | #devweek2019
    66
    > Looks like your colleague used a regular expression
    before to search, but can’t remember what it was. What do
    you recommend?

    View Slide

  67. kristina.io | @krstnfx | #devweek2019
    67
    Search history

    View Slide

  68. kristina.io | @krstnfx | #devweek2019
    68
    > Say you have to replace some old prefixed enum code:
    enum APPLFontStyle {
    case APPLFontStyleBold
    case APPLFontStyleItalic
    case APPLFontStyleUnderline
    case APPLFontStyleStrikethrough
    }
    > Know any shortcuts?

    View Slide

  69. kristina.io | @krstnfx | #devweek2019
    69
    Multiple Cursors
    Option + drag (rectangular selection)
    Ctrl + shift + click (place multiple cursors)

    View Slide

  70. kristina.io | @krstnfx | #devweek2019
    70
    > How do you debug an issue where the root cause is poor
    network connectivity?

    View Slide

  71. kristina.io | @krstnfx | #devweek2019
    71
    Network link simulator

    View Slide

  72. kristina.io | @krstnfx | #devweek2019
    72
    Network link simulator

    View Slide

  73. kristina.io | @krstnfx | #devweek2019
    73
    Network link simulator

    View Slide

  74. kristina.io | @krstnfx | #devweek2019
    74
    Network link simulator

    View Slide

  75. kristina.io | @krstnfx | #devweek2019
    75
    Network link simulator

    View Slide

  76. kristina.io | @krstnfx | #devweek2019
    76
    30 questions later…

    View Slide

  77. kristina.io | @krstnfx | #devweek2019
    77
    > What is your spirit animal?

    View Slide

  78. kristina.io | @krstnfx | #devweek2019
    78

    View Slide

  79. kristina.io | @krstnfx | #devweek2019
    79

    Stage 3
    complete

    View Slide

  80. kristina.io | @krstnfx | #devweek2019
    80

    View Slide

  81. kristina.io | @krstnfx | #devweek2019
    81
    456

    View Slide

  82. kristina.io | @krstnfx | #devweek2019
    82
    Based on a true story
    Just kidding

    View Slide

  83. kristina.io | @krstnfx | #devweek2019
    83
    Xcode Survival Guide Cheat Sheet
    Name Location Shortcut
    Color assets Assets folder Add color set
    Lock storyboard Identity Inspector Lock - all properties
    Side-by-side editors View -> Assistant Editor All editors stacked horizontally
    Place file in editor Keyboard/Mouse Alt + Shift (Click on file)
    Select Code Structure Keyboard/Mouse Command + click (on function)

    View Slide

  84. kristina.io | @krstnfx | #devweek2019
    84
    Xcode Survival Guide Cheat Sheet
    Name Location Shortcut
    Pre-Xcode 8 style Jump Xcode Settings ->
    Navigation
    Command-click on Code ->Jumps to
    Definition
    User Defined
    Environment Variables
    Project File -> Build
    Settings
    Add variables to User-Defined Settings
    Device Logs for CrashesWindow -> Devices and
    Simulators
    View device logs
    Catch All Breakpoints Breakpoints panel Plus button on bottom left
    Edit Breakpoints Breakpoints Panel Double-click blue breakpoint to bring up
    action menu

    View Slide

  85. kristina.io | @krstnfx | #devweek2019
    85
    Xcode Survival Guide Cheat Sheet
    Name Location Shortcut
    Slow animations Simulator -> Debug Slow animations
    Custom photos Simulator Drag and drop photo
    Pattern matching in
    search/Search History
    Search sidebar Click on magnifying glass drop down,
    Insert Pattern/Recent Queries
    Multiple cursors Editor Ctrl + shift +click (place cursors)

    Option + drag (rectangular selection)
    Simulate poor network System Preferences Network Link Conditioner

    View Slide

  86. kristina.io | @krstnfx | #devweek2019
    86
    Paul Hudson’s Swift Knowledge Base

    https://www.hackingwithswift.com/example-code/
    API Endpoint Configuration

    https://medium.com/@danielgalasko/change-your-api-endpoint-environment-
    using-xcode-configurations-in-swift-c1ad2722200e
    Type Safe JSON in Swift

    https://medium.com/grand-parade/creating-type-safe-json-in-swift-74a612991893
    WWDC-Style Code Snippets

    https://kristina.io/tutorial-wwdc-style-live-code-snippets/
    Resources

    View Slide

  87. kristina.io | @krstnfx | #devweek2019
    87
    How To Simulate A Bad Network Connection On Your iOS Device and
    Simulator

    https://www.natashatherobot.com/simulate-bad-network-ios-simulator/
    Regular Expression Search

    https://medium.com/@onmyway133/regular-expression-search-in-
    xcode-28a1a17fc863
    Twitter iOS Community (@twostraws, @aligatr, @_inside & many more!)

    https://twitter.com/krstnfx/status/940265683690180608
    Resources

    View Slide

  88. kristina.io | @krstnfx | #devweek2019
    88
    Thank you! Questions?
    8

    View Slide