|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
|
Journeyman |
Hello-
So I'm interested in finding timeblocks on a particular day, but have run into a couple of roadblocks. I can get timeblocks if I know not only the month and day, but also the hour and minute, which is too precise. So, with the following, I can find the specific timeblock on 3/14/06 at 9:21 AM PST (if it exists) - NSCalendarDate *myDate = [NSCalendarDate dateWithYear:2006 month:3 day:14 hour:9 minute:21 second:0 timeZone:[NSTimeZone defaultTimeZone]]; BDQualifier *qual = [BDQualifier qualifierWhereValueOfKey:@"startDate" isLike:myDate]; NSArray *mtimeblocks = [oc objectsForEntityNamed:@"Timeblock" matchingQualifier:qual]; But I don't want to have to know the actual time - just find anything on 3/14. (So if hour is 0, minute is 0, the qualifier doesn't find anything with the above). My second though was to format the passed date with a date formatter and build a string to qualify against the 'startAndEndDateAsString' key. So I build a string this way, and get "3/14/06 - 3/14/06" which looks identical to what that key returns - but, using this as a qualifier BDQualifier *qual = [BDQualifier qualifierWhereValueOfKey:@"startAndEndDateAsString" isLike:myFormattedString]; returns nothing.. Any ideas? Thanks! -E |
||
|
|
Marketcircle Team |
What you have to do is use 'greaterThan' and 'lessThan' operators.
id startDate = [[NSCalendarDate calendarDate] dateAsBeginningOfDay]. id endDate = [[NSCalendarDate calendarDate] dateAsEndOfDay]. id qual1 = [BDKeyValueQualifier keyValueQualifierWithKey:@"startDate" operatorSelector:BDQualifierOperatorGreaterThan value:startDate]; id qual2 = [BDKeyValueQualifier keyValueQualifierWithKey:@"endDate" operatorSelector:BDQualifierOperatorLessThan value:startDate]; id andQualifier = [BDAndQualifier andQualifierWithQualifiers:qual1, qual2, nil]. id timeblocks = [objectContext objectsForEntityNamed:@"Timeblock" matchingQualifier:andQualifier]. There are 2 other considerations 1) the qualifier does not account for the user 2) the call, since direct to the database, does not account for repeats There is a call for #2, but I forget what it is. I'll have to get an engineer to answer that one. |
|||
|
|
Marketcircle Team |
In regards to your formatter question.
You never query against formatted values because we don't store those. We store the raw data only. Formats are applied on the fly. Once you have a date object (NSCalendarDate), you can apply a formatter to it (NSDateFormatter) and get the string representation based on the format string you specified. |
|||
|
|
Journeyman |
Is there some header file or something I have to import for this? On the lines:
id qual1 = [BDKeyValueQualifier keyValueQualifierWithKey:@"startDate" operatorSelector:BDQualifierOperatorGreaterThan value:startDate]; I get 'error: BDKeyValueQualifier undeclared (first use in this function)' (I've also tried BDKeyValueQualifier qual1 = [...] with same results) Which I don't get with a regular BDQualifier. Or do I somehow have to init these first? As a follow-up to the second approach I was taking, am I correct to assume that any of the keys 'xyzAsString' are not fields to filter on? All these fields are 'formatted on the fly'? Thank you as always AJ |
|||
|
|
Marketcircle Team |
Humm ... maybe those are recently added methods. You can use the alloc] init...] autorelease] variants. Those are declared in the published headers.
As far as the 'asString' methods - yes those are derived. Someone else recently pointed out that we do not denote 'derived' and 'read only' methods in our documentation. We will have to rectify that. I'm not sure how I missed that for so long. |
|||
|
|
Marketcircle Team |
Here is a cover method we have on the document (GWDataContext) that does the right thing for getting timeblocks
- (NSArray*)calendarObjectsFromDate: (NSCalendarDate*)fromDate toDate: (NSCalendarDate*)toDate forOwner: (id)owner timedType: (BOOL)wantsTimed includeRepeatOccurrences: (BOOL)wantsRepeats additionalQualifier: (BDQualifier*)qualifier; This is new and not published yet, so you will have to manually add this to a header file. For owner, pass the currentUser timedType: YES for appointments, NO for events in additionalQualifier, you can add things like category. This should make it a lot easier for you. |
|||
|
|
Journeyman |
Well, that method looks perfect and a lot better than dealing with the qualifiers. Bear with me as I'm still trying to get a grasp of Obj-C in general, and how it is applied within the DL plugins in particular, but I'm not sure which header file to put this into - I would assume the GWDataContext.h based on your email, but it won't compile: I have
-(NSArray* )calendarObjectsFromDate:(NSCalendarDate*)fromDate toDate:(NSCalendarDate*)toDate forOwner:(id)owner timedType:(BOOL)wantsTimed includeRepeatOccurrences:(BOOL)wantsRepeats additionalQualifier:(BDQualifier*)qualifier; and it gives me an 'error: parse error before 'BDQualifier'. If I put it into, say, my own command header, it compiles, but of course at runtime it doesn't know anything about the actual method implementation. This is the one big thing that frustrates me about Cocoa - I just don't have enough experience to know what is exposed and what isn't. I like the messaging and all that, but it just seems like there are a billion things (like delegator methods) that you just have to 'know' about. I also have a question about identifying the current user - Is there something like [MCUser currentUser] to get this? I didn't see anything about this in the dev docs. Thanks AJ, perhaps there will be some time to talk about some of this next week too... |
|||
|
|
Journeyman |
... One more thing. One problem I'm seeing is that in the BDKeyValueQualifier.m file, we need to
#import "MCFoundationDefines.h" And I don't think this header file is available to us.. I've almost got this thing compiling but it is getting hung up on that and a 'MCGenericException' undeclared error, which I imagine is defined in the missing header. |
|||
|
|
Marketcircle Team |
Humm ....
I'll have to look at that. In the meanwhile, replace BDKeyValueQualifier with BDQualifier or id in the method declaration. This will work because a BDKeyValueQualifier is a kind of BDQualifier (subclass) which is a kind of NSObject (id, subclass). So just do this in the GWDataContext.h header
-(NSArray* )calendarObjectsFromDate:(NSCalendarDate*)fromDate
toDate:(NSCalendarDate*)toDate
forOwner:(id)owner
timedType:(BOOL)wantsTimed
includeRepeatOccurrences:(BOOL)wantsRepeats
additionalQualifier:(id)qualifier;
The thing to keep in mind about Objective-C is that it is a late bound, dynamically typed language. This means that all you need is method signatures. As long as the compiler finds the signature, you are good. Sorry for the inconvenience. |
|||
|
| Previous Topic | Next Topic | powered by eve community |
| Please Wait. Your request is being processed... |
|

