Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Attempting to read OSLogStore in iOS 14 Beta 2
import OSLog
class LogReader: ObservableObject {
var log: OSLogStore
init?() {
do {
log = try OSLogStore.init(scope: .currentProcessIdentifier)
dump(log)
/*
* Declared in OSLog/Store.h
* as - (nullable OSLogEnumerator *)entriesEnumeratorWithOptions:(OSLogEnumeratorOptions)options
position:(nullable OSLogPosition *)position
predicate:(nullable NSPredicate *)predicate
error:(NSError **)error
API_AVAILABLE(macos(10.15), ios(14.0), tvos(14.0), watchos(7.0))
NS_REFINED_FOR_SWIFT;
* Swift refinement not visible? — use name prefixed with __
* See https://developer.apple.com/documentation/swift/objective-c_and_c_code_customization/improving_objective-c_api_declarations_for_swift
*/
let enumerator = try log.__entriesEnumerator(options: [], position: nil, predicate: nil)
dump(enumerator)
var next: Any?
repeat {
next = enumerator.nextObject()
dump(next)
} while next != nil
} catch {
dump(error)
return nil
}
}
}
/*
Result: Error Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service on pid 0 named com.apple.OSLogService was invalidated." UserInfo={NSDebugDescription=The connection to service on pid 0 named com.apple.OSLogService was invalidated.}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment