+// convert from NSObject to different C++ types: all these functions check
+// that the conversion really makes sense and assert if it doesn't
+wxString ObjectToString(NSObject *object)
+{
+ wxCHECK_MSG( [object isKindOfClass:[NSString class]], "",
+ wxString::Format
+ (
+ "string expected but got %s",
+ wxCFStringRef::AsString([object className])
+ ));
+
+ return wxCFStringRef([((NSString*) object) retain]).AsString();
+}
+
+bool ObjectToBool(NSObject *object)
+{
+ // actually the value must be of NSCFBoolean class but it's private so we
+ // can't check for it directly
+ wxCHECK_MSG( [object isKindOfClass:[NSNumber class]], false,
+ wxString::Format
+ (
+ "number expected but got %s",
+ wxCFStringRef::AsString([object className])
+ ));
+
+ return [(NSNumber *)object boolValue];
+}
+
+long ObjectToLong(NSObject *object)
+{
+ wxCHECK_MSG( [object isKindOfClass:[NSNumber class]], -1,
+ wxString::Format
+ (
+ "number expected but got %s",
+ wxCFStringRef::AsString([object className])
+ ));
+
+ return [(NSNumber *)object longValue];
+}
+
+wxDateTime ObjectToDate(NSObject *object)
+{
+ wxCHECK_MSG( [object isKindOfClass:[NSDate class]], wxInvalidDateTime,
+ wxString::Format
+ (
+ "date expected but got %s",
+ wxCFStringRef::AsString([object className])
+ ));
+
+ // get the number of seconds since 1970-01-01 UTC and this is the only
+ // way to convert a double to a wxLongLong
+ const wxLongLong seconds = [((NSDate*) object) timeIntervalSince1970];
+
+ wxDateTime dt(1, wxDateTime::Jan, 1970);
+ dt.Add(wxTimeSpan(0,0,seconds));
+
+ // the user has entered a date in the local timezone but seconds
+ // contains the number of seconds from date in the local timezone
+ // since 1970-01-01 UTC; therefore, the timezone information has to be
+ // transferred to wxWidgets, too:
+ dt.MakeFromTimezone(wxDateTime::UTC);
+
+ return dt;
+}
+