Created
April 23, 2024 00:01
-
-
Save samsonjs/df4267d0b8c51777937922b53cb17a1e to your computer and use it in GitHub Desktop.
Log info about an event titled "View recent photos"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import EventKit | |
import Foundation | |
import ObjectiveC.runtime | |
func logIvarList(obj: NSObject) { | |
var count: UInt32 = 0 | |
if let ivars = class_copyIvarList(type(of: obj), &count) { | |
for i in 0..<Int(count) { | |
let ivar = ivars[i] | |
let name = ivar_getName(ivar).map(String.init(cString:)) ?? "Unknown" | |
let type = ivar_getTypeEncoding(ivar).map(String.init(cString:)) ?? "Unknown" | |
print(" - [i] \(name) \(type)") | |
} | |
free(ivars) | |
} | |
if let props = class_copyPropertyList(type(of: obj), &count) { | |
for i in 0..<Int(count) { | |
let prop = props[i] | |
let name = String(cString: property_getName(prop)) | |
let type = property_getAttributes(prop).map(String.init(cString:)) ?? "Unknown" | |
print(" - [p] \(name) \(type)") | |
} | |
free(props) | |
} | |
if let methods = class_copyMethodList(type(of: obj), &count) { | |
for i in 0..<Int(count) { | |
let method = methods[i] | |
let name = method_getName(method).description | |
print(" - [m] \(name)") | |
} | |
free(methods) | |
} | |
} | |
class RemindersManager { | |
let eventStore = EKEventStore() | |
func printAllReminders() { | |
eventStore.requestFullAccessToReminders { (granted, error) in | |
if granted && error == nil { | |
let predicate = self.eventStore.predicateForIncompleteReminders( | |
withDueDateStarting: Date(), | |
ending: nil, | |
calendars: nil | |
) | |
self.eventStore.fetchReminders(matching: predicate) { reminders in | |
for reminder in reminders ?? [] where reminder.title == "View recent photos" { | |
// Print details of each reminder | |
print("\(reminder.title ?? "<untitled>"):") | |
print(" - Notes: \(reminder.notes ?? "")") | |
print(" - Action: \((reminder.value(forKey: "action") as? URL)?.absoluteString ?? "")") | |
logIvarList(obj: reminder) | |
print("") | |
} | |
} | |
} else { | |
print("Access Denied: \(granted) \(String(describing: error))") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment