Skip to content

Instantly share code, notes, and snippets.

@astrokin
Created February 12, 2019 15:38
Show Gist options
  • Save astrokin/131b5f30f68ee7e4ced447d16c6ab9c2 to your computer and use it in GitHub Desktop.
Save astrokin/131b5f30f68ee7e4ced447d16c6ab9c2 to your computer and use it in GitHub Desktop.
Optional+Logging
public extension Optional {
func expectedToBe(_ logMessage: String? = nil, line: Int = #line, file: StaticString = #file) -> Wrapped? {
switch self {
case let .some(some): return some
case .none:
print("[OPTIONAL] \(#function) \(file):\(line) message \(String(describing: logMessage))")
return .none
}
}
}
@astrokin
Copy link
Author

func sendEventToCrashlytics(_ event: AnalyticsEvent) {
        let userInfo = event.payload.expectedToBe("[ERROR] non fatal without payload") ?? [:]
    }

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