对于我的EVReflection库,我遇到了一个EKEvent镜像没有返回任何信息的情况。即使在完成基础知识时镜子也没有返回任何内容。在镜像线后设置断点时,您将看到镜像对象中没有任何内容。这是一个错误还是我错过了什么?
更新 我使用旧的Objective C objc_property_t和property_getName函数扩展了获取属性的演示。它将返回属性列表。但是当你得到.value(forKey:
)时会崩溃#if os(tvOS)
// Eventkit is not supported on tvOS
#else
import XCTest
import Foundation
import EventKit
let store = EKEventStore()
class EVReflectionEventKitTests: XCTestCase {
func testEventKit() {
let exp = expectation(description: "eventStore")
store.requestAccess(to: .event, completion: { (granted, error) in
let event = EKEvent(eventStore: store)
event.startDate = Date().addingTimeInterval(10000)
event.title = "title"
event.location = "here"
event.endDate = Date().addingTimeInterval(20000)
event.notes = "notes"
event.calendar = store.defaultCalendarForNewEvents
event.addAlarm(EKAlarm(absoluteDate: Date().addingTimeInterval(10000)))
//WARNING: You will get events in your agenda! Disable next line if you don't want that
//try? store.save(event, span: EKSpan.thisEvent, commit: true)
let m = Mirror(reflecting: event)
print("mirror children = \(m.children.count)")
let oc = self.properties(event)
print(oc)
for p in oc {
var value: Any? = nil
value = event.value(forKey: p)
print("\(p) = \(String(describing: value))")
}
exp.fulfill()
})
waitForExpectations(timeout: 10) { error in
XCTAssertNil(error, "\(error?.localizedDescription ?? "")")
}
}
func properties(_ classToInspect: NSObject) -> [String] {
var count = UInt32()
let classToInspect = NSURL.self
let properties = class_copyPropertyList(classToInspect, &count)
var propertyNames = [String]()
let intCount = Int(count)
for i in 0 ..< intCount {
let property : objc_property_t = properties![i]!
guard let propertyName = NSString(utf8String: property_getName(property)) as String? else {
debugPrint("Couldn't unwrap property name for \(property)")
break
}
propertyNames.append(propertyName)
}
free(properties)
return propertyNames
}
}
#endif
答案 0 :(得分:0)
import Foundation
import EventKit
import EVReflection
class serializedEvent: EVObject {
var myEvent: EKEvent = EKEvent(eventStore: globalStore)
//globalstore is an EKEventstore global object
然后在我的一个控制器中(我只有一个完整的事件名为:使用EKalarms类型的警报创建的事件和EKRecurrencyRule类型的重复规则):
print("event before serialization :")
print(event)
let serEvent: serializedEvent = serializedEvent()
serEvent.myEvent=event
let jsonEvent = serEvent.toJsonString()
let newEvent = serializedEvent(json: jsonEvent).myEvent
print("newEvent: =")
print(newEvent)
这是一个真实的输出示例:
event before serialization :
EKEvent <0x174130040>
{
EKEvent <0x174130040>
{ title = Matrimonio;
location = ;
calendar = EKCalendar <0x1740b4d60> {title = Calendario; type = CalDAV; allowsModify = YES; color = #029ae4;};
alarms = (
"EKAlarm <0x1740d9d00> {triggerInterval = -54000.000000}",
"EKAlarm <0x1740d8950> {triggerInterval = 0.000000}"
);
URL = (null);
lastModified = 2016-06-06 15:15:17 +0000;
startTimeZone = (null);
startTimeZone = (null)
};
location = ;
structuredLocation = (null);
startDate = 2009-06-06 22:00:00 +0000;
endDate = 2009-06-07 21:59:59 +0000;
allDay = 1;
floating = 1;
recurrence = EKRecurrenceRule <0x1702b2c00> RRULE FREQ=YEARLY;INTERVAL=1;BYMONTH=6;BYMONTHDAY=7;
attendees = (null);
travelTime = (null);
startLocation = (null);
};
2017-04-28 21:23:25.226855 InstaEvent Share[19166:5967595] ERROR:
Unexpected type while converting value for JsonSerialization:
EKEvent <0x174130040>
{
EKEvent <0x174130040>
{ title = Matrimonio;
location = ;
calendar = EKCalendar <0x1740b4d60> {title = Calendario; type
= CalDAV; allowsModify = YES; color = #029ae4;};
alarms = (
"EKAlarm <0x1740d9d00> {triggerInterval = -54000.000000}",
"EKAlarm <0x1740d8950> {triggerInterval = 0.000000}"
);
URL = (null);
lastModified = 2016-06-06 15:15:17 +0000;
startTimeZone = (null);
startTimeZone = (null)
};
location = ;
structuredLocation = (null);
startDate = 2009-06-06 22:00:00 +0000;
endDate = 2009-06-07 21:59:59 +0000;
allDay = 1;
floating = 1;
recurrence = EKRecurrenceRule <0x1702b2c00> RRULE
FREQ=YEARLY;INTERVAL=1;BYMONTH=6;BYMONTHDAY=7;
attendees = (null);
travelTime = (null);
startLocation = (null);
};
newEvent: =
EKEvent <0x174130040>
{
EKEvent <0x174130040>
{ title = Matrimonio;
location = ;
calendar = EKCalendar <0x1740b4d60> {title = Calendario; type
= CalDAV; allowsModify = YES; color = #029ae4;};
alarms = (
"EKAlarm <0x1740d9d00> {triggerInterval = -54000.000000}",
"EKAlarm <0x1740d8950> {triggerInterval = 0.000000}"
);
URL = (null);
lastModified = 2016-06-06 15:15:17 +0000;
startTimeZone = (null);
startTimeZone = (null)
};
location = ;
structuredLocation = (null);
startDate = 2009-06-06 22:00:00 +0000;
endDate = 2009-06-07 21:59:59 +0000;
allDay = 1;
floating = 1;
recurrence = EKRecurrenceRule <0x1702b2c00> RRULE
FREQ=YEARLY;INTERVAL=1;BYMONTH=6;BYMONTHDAY=7;
attendees = (null);
travelTime = (null);
startLocation = (null);
};
但是当我们询问它是否有警报(它应该有,看着输出)
print(newEvent.hasAlarms)
它以
失败 19170:5969208] -[__NSCFString hasAlarms]: unrecognized selector sent to instance 0x17425d340
这很棘手:(
编辑:如果在SERIALIZER.SWITF类中我添加: 扩展EKEvent:EVReflectable {} 那么newEvent就是空的。
..真的很棘手:D
维克多