Skip to content

Instantly share code, notes, and snippets.

@tomaskraina
Last active September 23, 2018 02:11
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomaskraina/a1f79b27b8b1698cd2211ee6ff18bce0 to your computer and use it in GitHub Desktop.
Save tomaskraina/a1f79b27b8b1698cd2211ee6ff18bce0 to your computer and use it in GitHub Desktop.
NSUserActivity+CustomReflectable extension so an user activity can be po-ed in lldb / Xcode
//
// NSUserActivity+CustomReflectable.swift
// Tom Kraina <me@tomkraina.com>
//
// Created by Tom Kraina on 19/11/2016.
// Copyright © 2016 Tom Kraina <me@tomkraina.com>. All rights reserved.
//
import Foundation
// Inspired by:
// - https://medium.com/@darjeelingsteve/easier-swift-debugging-with-mirrors-3b6e551f3c47
// MARK: - CustomReflectable
extension NSUserActivity : CustomReflectable {
public func customMirror() -> Mirror {
let children = DictionaryLiteral<String, Any>(dictionaryLiteral:
("activityType", activityType),
("title", title),
("userInfo", userInfo.debugDescription),
("requiredUserInfoKeys", requiredUserInfoKeys),
("needsSave", needsSave),
("webpageURL", webpageURL),
("expirationDate", expirationDate.debugDescription),
("keywords", keywords),
("supportsContinuationStreams", supportsContinuationStreams),
("delegate", delegate),
("eligibleForHandoff", eligibleForHandoff),
("eligibleForSearch", eligibleForSearch),
("eligibleForPublicIndexing", eligibleForPublicIndexing))
return Mirror(NSUserActivity.self, children: children, displayStyle: .Class, ancestorRepresentation: .Suppressed)
}
}
@tomaskraina
Copy link
Author

Example output:

(lldb) po userActivity
▿ Optional(<NSUserActivity: 0x7fb890d2a340>)
▿ Some : <NSUserActivity: 0x7fb890d2a340>
- activityType : "NSUserActivityTypeBrowsingWeb"
- title : nil
- userInfo : "Optional([:])"
- requiredUserInfoKeys : []
- needsSave : true
- webpageURL : Optional(http://tomkraina.com/)
- expirationDate : ""
- keywords : []
- supportsContinuationStreams : false
- delegate : nil
- eligibleForHandoff : true
- eligibleForSearch : false
- eligibleForPublicIndexing : false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment