I am working with the following function atm, but I'm banging my head against a wall.
-(double)fetchTimeUntilNextUpdateInSeconds{
NSFetchRequest *fetchReq = [[NSFetchRequest alloc]initWithEntityName:@"DataInfo"];
fetchReq.predicate = [NSPredicate predicateWithFormat:@"data_info_id == 1"];
[fetchReq setPropertiesToFetch:[NSArray arrayWithObject:@"nextupdate"]];
NSArray *array = [self.context executeFetchRequest:fetchReq error:nil];
NSString *string = [[array valueForKey:@"nextupdate"] stringValue];
NSLog(@"string: %@ array count:%lu", string, (unsigned long)array.count);
NSArray *hoursAndMins = [string componentsSeparatedByString:@":"];
int hours = [hoursAndMins[0] intValue];
int mins = [hoursAndMins[1] intValue];
return (mins*60)+(hours*60*60);
}
LOG: string: ( "05:42" ) array count:1
I'm getting following error: -[__NSArrayI componentsSeparatedByString:]: unrecognized selector sent to instance 0x174224060'
fair enough, i try to invoke "stringValue" method on string (as showed in code snippet) and get the following instead:
-[__NSArrayI stringValue:]: unrecognized selector sent to instance 0x174224060'
The ladder makes me think I'm already receiving a string as stringValue is not a method of that class.... but why won't the first work then. Better yet, what am I doing wrong here?
[NSArray unrecognized selectorstringis really an array with one element. (See the parentheses around the string.) That matches the errors you're getting when you attempt to treat an array as a string.stringValuethat only worked out okay bc the method- valueForKey:returns an typeidtherefore allowing you to usestringValueas you an tell there is no stringValue for the NSArray class. I'd suggest to you to print your elements after each line. Either save your array locally so you can see it better, or use the debugger to focus with break points, bc it looks like you haven't "gotten to the string value" you're still pointing to an array