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

Code Snippets for Debugging

Carola Nitz
September 15, 2017

Code Snippets for Debugging

A lightning talk held at NSSpain 2017 about code snippets for debugging

Carola Nitz

September 15, 2017
Tweet

More Decks by Carola Nitz

Other Decks in Technology

Transcript

  1. Getting all the notifications: let center = NotificationCenter.default center.addObserver(forName: nil,

    object: nil, queue: nil) { notification in print(notification.name) }
  2. … Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIKeyboardWillChangeFrameNotification) Name(rawValue: UIKeyboardPrivateWillChangeFrameNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue:

    UIKeyboardWillShowNotification) Name(rawValue: UIKeyboardPrivateWillShowNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UITextViewTextDidBeginEditingNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) … Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIKeyboardDidChangeFrameNotification) Name(rawValue: UIKeyboardPrivateDidChangeFrameNotification) Name(rawValue: UIKeyboardDidShowNotification)
  3. … Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIKeyboardWillChangeFrameNotification) Name(rawValue: UIKeyboardPrivateWillChangeFrameNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue:

    UIKeyboardWillShowNotification) Name(rawValue: UIKeyboardPrivateWillShowNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UITextViewTextDidBeginEditingNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) … Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UIViewAnimationDidCommitNotification) Name(rawValue: UIViewAnimationDidStopNotification) Name(rawValue: UITextEffectsWindowDidRotateNotification) Name(rawValue: UIKeyboardDidChangeFrameNotification) Name(rawValue: UIKeyboardPrivateDidChangeFrameNotification) Name(rawValue: UIKeyboardDidShowNotification)
  4. Getting all the properties: var count: CUnsignedInt = 0 let

    ivarList = class_copyIvarList(UICollectionView.self, &count) for i in (0..<Int(count)) { let unwrapped = ivarList?[i].unsafelyUnwrapped if let ivar = ivar_getName(unwrapped), let typeEncoding = ivar_getTypeEncoding(unwrapped) { let propertyName = String(cString: ivar) let typeEncoding = String(cString: typeEncoding) print("Property:\(propertyName), Type:\(typeEncoding)") } } free(ivarList)
  5. Property:_layout, Type:@"UICollectionViewLayout" Property:_dataSource, Type:@"<UICollectionViewDataSource_Private>" Property:_backgroundView, Type:@"UIView" Property:_indexPathsForSelectedItems, Type:@"NSMutableSet" Property:_cellReuseQueues, Type:@"NSMutableDictionary"

    Property:_supplementaryViewReuseQueues, Type:@"NSMutableDictionary" Property:_indexPathsForHighlightedItems, Type:@"NSMutableSet" Property:_reloadingSuspendedCount, Type:q … Property:_focusedViewType, Type:q Property:_contentFocusContainerGuide, Type:@"UIFocusContainerGuide" Property:_collectionViewFlags, Type:{? ="delegateShouldHighlightItemAtIndexPath"b1"delegateDidHighlightItemAtIndexPath"b1"delegateDidUnhighlightItemAtIndexPath"b1"delegateShouldSelectItemAtInde xPath"b1"delegateShouldDeselectItemAtIndexPath"b1"delegateDidSelectItemAtIndexPath"b1"delegateDidDeselectItemAtIndexPath"b1"delegateSupportsMenus"b1"del egateWillDisplayCell"b1"delegateWillDisplaySupplementaryView"b1"delegateDidEndDisplayingCell"b1"delegateDidEndDisplayingSupplementaryView"b1"delegateIndex ForReferenceItemDuringLayoutTransition"b1"delegateOverrideForTransitionOffsetSize"b1"delegateTargetContentOffsetForProposedContentOffsetSPI"b1"delegateTarg etContentOffsetForProposedContentOffset"b1"delegateTargetIndexPathForMoveSPI"b1"delegateTargetIndexPathForMove"b1"delegateCanFocusItemAtIndexPath depr ecated"b1"delegateDidFocusItemAtIndexPath deprecated"b1"delegateCanFocusItemAtIndexPath"b1"delegateDidFocusItemAtIndexPath"b1"delegateDidUnfocusItemAtI ndexPath"b1"delegateShouldChangeFocusedItem"b1"delegateIndexPathForPreferredFocusedItem"b1"delegateShouldUpdateFocusFromRowAtIndexPathToView"b1”…} Property:_lastLayoutOffset, Type:{CGPoint="x"d"y"d} Property:_prefetchMode, Type:q Property:_currentPrefetchingContext, Type:@" UICollectionViewPrefetchingContext" Property: prefetchCacheItems, Type:@"NSMutableDictionary" Property: prefetchVelocityIntegrator, Type:@" UIVelocityIntegrator" Property:_prefetchDataSource, Type:@"<UICollectionViewDataSourcePrefetching>" Property:_containerScrollViewVisitationCount, Type:q Property:_prefetchingEnabled, Type:B Property:_focusedCellIndexPath, Type:@"NSIndexPath” Property:_focusedCell, Type:@"UICollectionReusableView" …
  6. (lldb) e -l swift -- import <App> (lldb) e -l

    swift -- print(<object of interest>)
  7. (lldb) e -l swift -- import <App> (lldb) e -l

    swift -- print(<Object of interest>) (lldb) settings set target.language swift
  8. (lldb) e -l swift -- import <App> (lldb) e -l

    swift -- print(<Object of interest>) (lldb) settings set target.language swift caro$ touch ~/.lldbinit caro$ chmod +x ~/.lldbinit
  9. Some useful commands: • pviews - Print the recursive view

    description for the key window • pactions - Print the actions and targets of a control
  10. Some useful commands: • pviews - Print the recursive view

    description for the key window • pactions - Print the actions and targets of a control • paltrace - Print the Auto Layout trace for the given view
  11. Resources: • CFHipsterRef: Low-Level Programming on iOS & Mac OS

    X by Mattt Thompson • Swift funtime ! by Boris Bügling • Facebook Chisel : https://github.com/facebook/chisel