Reset value by UITableView sections - ios

I am building a personal budget app that tracks my purchases. I have an NSDictionary of NSArray that looks like this:
{
46 = (
{
DATE = "11/14/2019";
ID = 21;
PLACE = Kroger;
PRICE = "23.32";
},
{
DATE = "11/14/2019";
ID = 22;
PLACE = Walmart;
PRICE = "12.54";
}
);
47 = (
{
DATE = "11/18/2019";
ID = 23;
PLACE = Cinco;
PRICE = "65.32";
}
);
}
The keys in the NSDictionary are determined by strftime using %W. Basically I have a set limit I can spend per week (i.e. 190) and I want in each titleForHeaderInSection: to have a total value that is determined by each field's PRICE in each key.
I currently have the following on the app:
The following calculate the NSDictionary listed above along with the total value:
Note: arrFoodInfo is a NSDictionary of just the entries without the week numbers
for (NSDictionary *dict in self.arrFoodInfo) {
NSString *date = [dict objectForKey:#"DATE"];
[totalPrices addObject:[dict objectForKey:#"PRICE"]];
for (NSString *price in totalPrices) {
if ([totalPrices containsObject:price]) {
_sumPrices += [price floatValue]; // Calculates total value
[totalPrices removeObject:price];
}
}
NSDateFormatter *SDF = [[NSDateFormatter alloc]
init];
[SDF setDateStyle:NSDateFormatterMediumStyle];
[SDF setDateFormat:#"MM/dd/yyyy"];
NSDate *convertedDate = [SDF dateFromString:date];
NSDateComponents *dateComponents = [calendar components:NSCalendarUnitYear | NSCalendarUnitWeekOfYear fromDate:convertedDate];
NSInteger week = dateComponents.weekOfYear;
NSInteger index = week;
NSNumber *key = #(index);
NSMutableArray *weekArray = weeksDictionary[key];
if (!weekArray) {
weekArray = [NSMutableArray array];
weeksDictionary[key] = weekArray;
}
[weekArray addObject:dict];
}
At the moment, I am getting the total of each PRICE but the total value should be different per section. What is the best option to determine this?

Related

Group and sum values of NSDictionary by month where key is NSDate

I have a dictionary with the following structure,
arrayOne = {
"2015-11-09T00:00:00.000Z" = 1;
"2015-11-16T00:00:00.000Z" = 2;
"2015-11-23T00:00:00.000Z" = 3;
"2015-11-30T00:00:00.000Z" = 4;
"2015-12-07T00:00:00.000Z" = 5;
"2015-12-14T00:00:00.000Z" = 6;
"2015-12-21T00:00:00.000Z" = 7;
"2015-12-28T00:00:00.000Z" = 8;
"2016-01-04T00:00:00.000Z" = 9;
"2016-01-11T00:00:00.000Z" = 1;
"2016-01-18T00:00:00.000Z" = 2;
"2016-01-25T00:00:00.000Z" = 3;
}
I'd like to create another dictionary with values like,
arrayTWo = {
"November" = 10;
"December" = 26;
"January" = 15;
}
I tried by getting month values of dates in a separate array and values in a separate array and then tried to get those in a nsmutabledictionary, but it does not assign value for duplicate keys and got a solution like
arrayTWo = {
"November" = 4;
"December" = 8;
"January" = 3;
}
I couldn't find a better way, Any options are appreciated. Thanks.
Try this, it uses NSDateFormatter to get the month name from the date, it's localized depending on the current locale. If your locale is not english and you need to get the english month names uncomment the line to set the locale explicitly.
The logic is simple:
Enumerate the dictionary, If the key (month) exists, add the value, if it doesn't create the key
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = #"MMMM";
// formatter.locale = [NSLocale localeWithLocaleIdentifier:#"en_US_POSIX"];
NSMutableDictionary *result = [NSMutableDictionary dictionary];
for (NSDate *key in arrayOne.allKeys) {
NSString *month = [formatter stringFromDate:key];
if (result[month] == nil) {
result[month] = arrayOne[key];
} else {
NSInteger value = [result[month] integerValue];
result[month] = #(value + [arrayOne[key] integerValue]);
}
}
NSLog(#"%#", result);

Q - iOS - Search and use specific part of parsed JSON array

This is my first time using JSON. In my app I am fetching some data from "Open Weather API". I get back some array, with way to many entries, and I need to search ones that are on specific day and return temp.day and weather.icon from them. So far I managed to fetch data propely. As far I know i should use some FOR loop with IF inside it, but I am pulling my hairs out how to do it in Objective C.
There is my fetch method:
- (void)fetchedData:(NSData *)responseData {
//parse out the json data
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData //1
options:kNilOptions
error:&error];
NSArray* weatherList = [json objectForKey:#"list"];
NSLog(#"everything %#", weatherList ); //3
}
And part array from NSLog:
{
clouds = 92;
deg = 265;
dt = 1456221600;
humidity = 100;
pressure = "1007.96";
rain = "0.24";
speed = "5.12";
temp = {
day = "4.11";
eve = "4.62";
max = "4.87";
min = "2.78";
morn = "4.11";
night = "2.78";
};
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
},
{
clouds = 88;
deg = 268;
dt = 1456308000;
humidity = 98;
pressure = "1012.04";
rain = "1.31";
speed = "6.35";
temp = {
day = "3.57";
eve = "3.74";
max = "3.74";
min = "2.38";
morn = "2.53";
night = "2.38";
};
weather = (
{
description = "light rain";
icon = 10d;
id = 500;
main = Rain;
}
);
},
{
clouds = 20;
deg = 243;
dt = 1456394400;
humidity = 100;
pressure = "1015.42";
snow = "0.25";
speed = "5.08";
temp = {
day = "2.95";
eve = "4.09";
max = "4.54";
min = "-0.65";
morn = "1.74";
night = "-0.65";
};
weather = (
{
description = "light snow";
icon = 13d;
id = 600;
main = Snow;
}
);
},
{
clouds = 80;
deg = 273;
dt = 1456480800;
humidity = 100;
pressure = "1016.63";
snow = "0.04";
speed = "2.79";
temp = {
day = "0.2";
eve = "2.79";
max = "2.79";
min = "-3.33";
morn = "-2.7";
night = "-2.42";
};
weather = (
{
description = "light snow";
icon = 13d;
id = 600;
main = Snow;
}
);
},
{
clouds = 87;
deg = 132;
dt = 1456567200;
humidity = 0;
pressure = "1007.07";
rain = "0.22";
snow = "0.03";
speed = 5;
temp = {
day = "3.96";
eve = "1.48";
max = "3.96";
min = "-3.12";
morn = "-3.12";
night = "-1.59";
};
weather = (
{
description = "clear sky";
icon = 01d;
id = 800;
main = Clear;
}
);
}
What are good practices? Do I fetch proper enough big part of JSON?
Should I use dome NSDictionary too? Any ideas are welcome!
Thanks
1) As per documentation given the time is in GMT format so you need to convert the time in IST to compare
here is code to convert the time . I dont know your time zone I converted it in Indian Standard Time
for ( NSDictionary *obj in weatherList) {
NSDateFormatter *inDateFormatter = [[NSDateFormatter alloc] init];
inDateFormatter.dateFormat = #"dd-MM-yyyy";
inDateFormatter.timeZone = [NSTimeZone timeZoneWithAbbreviation:#"IST"];
NSDate *inDate = [inDateFormatter dateFromString:[obj objectForKey:#"dt"]];
if ([self isItToday:inDate]) {
NSDictionary * tempDict = [obj objectForKey:#"temp"];
NSDictionary * weatherDict = [[obj objectForKey:#"weather"]objectForKey:0];
NSString * dayTemp = [tempDict objectForKey:#"day"];//only storing for time being you can use where you needed
NSString * icon = [weatherDict objectForKey:#"icon"];//only storing for time being you can use where you needed
}
}
2) Now you need to compare it with todays date
+ (BOOL)isItToday:(NSDate *)date {
if (date != nil) {
NSString *givenDateString = [self stringFromDate:date inDateFormat:#"dd-MM-yyyy"];
NSString *toDayString = [self stringFromDate:[NSDate date] inDateFormat:#"dd-MM-yyyy"];
NSDate *givenDate = [self dateFromString:givenDateString inDateFormat:#"dd-MM-yyyy"];
NSDate *toDay = [self dateFromString:toDayString inDateFormat:#"dd-MM-yyyy"];
if ([givenDate isEqualToDate:toDay]) {
return YES;
} else {
return NO;
}
} else {
return NO;
}
}
+ (NSString *)stringFromDate:(NSDate *)date inDateFormat:(NSString *)inDateformat
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:kLocaleIdentifierEN_US_POSIX];
[dateFormatter setDateFormat:inDateformat];//#"dd/MM/yyyy"
return [dateFormatter stringFromDate:date];
}
+ (NSDate *)dateFromString:(NSString *)stringDate inDateFormat:(NSString *)inDateformat
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setLocale:kLocaleIdentifierEN_US_POSIX];
[dateFormatter setDateFormat:inDateformat];//#"dd/MM/yyyy"
return [dateFormatter dateFromString:stringDate];
}
also add this line
#define kLocaleIdentifierEN_US_POSIX [NSLocale localeWithLocaleIdentifier:#"en_US_POSIX"]
Use following code,
double comparingdt = 1456308000;
__block NSString *tempday, *weathericon;
[weatherList enumerateObjectsWithOptions:NSEnumerationConcurrent usingBlock:^(NSDictionary *weather, NSUInteger idx, BOOL * _Nonnull stop) {
*stop = ([weather[#"dt"] doubleValue] == comparingdt);
if (*stop)
{
tempday = weather[#"temp"][#"day"];
weathericon = [weather[#"weather"] firstObject][#"icon"];
}
}];

Handle Foursquare hours API to find out if the venue is opened or closed

I have a foursquare hours array (Foursquare API) that stores segments of hours when a specific venue is open. It looks something like this:
[{
"days":[1,2,3,4,7],
"includesToday":true,
"open":[
{"end":"+0200","start":"1000"}],
"segments":[]},
{
"days":[5,6]
,"open":[
{"end":"+0300","start":"1000"}],
"segments":[]}
]
How do I find out if the venue is opened or closed at current time?
I handle it like this: 4sq hours API gist
-(NSDictionary*)isVenueOpenDictionaryForHours:(NSArray*)hours{
// defaults and inits
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDictionary *lastSegmentYesterday = [[NSDictionary alloc] init];
NSDate *dateNow = [NSDate date];
NSString *venueOpenText = [[NSString alloc] init];
NSString *venueOpen = #"no";
// get components for today
NSDateComponents *compsNow = [gregorian components:NSWeekdayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSDayCalendarUnit|NSMonthCalendarUnit|NSYearCalendarUnit fromDate:dateNow];
// get weekday for today and yesterday so we can lookup 4sq API
NSInteger weekday = [compsNow weekday];
NSInteger weekdayYesterday = (weekday>1)?weekday-1:7;
// look for todays' segment
NSMutableArray *venueOpenSegments = [[NSMutableArray alloc] init]; // stores all the segments when the venue is open
for (NSDictionary *segment in hours){
// get today's segment (if it exists)
if ([segment[#"days"] containsObject:[NSNumber numberWithInteger:weekday]]){
for (NSDictionary *dictOpen in segment[#"open"])
[venueOpenSegments insertObject:#{#"end": [dictOpen[#"end"] mutableCopy], #"start":[dictOpen[#"start"] mutableCopy]}.mutableCopy atIndex:venueOpenSegments.count];
}
// check the day before if the venue is open past midnight
if (([segment[#"days"] containsObject:[NSNumber numberWithInteger:weekdayYesterday]] && [segment[#"open"] count])){
// get the last segment (that should be the one passing midnight)
NSDictionary *tempSegment = [segment[#"open"] lastObject];
// if it has more than 4 characters it's after midnight ("+02:00"), also, ignore if it closes at midnight
if ([tempSegment[#"end"] length] > 4 && ![tempSegment[#"end"]isEqualToString:#"+0000"]){
// create a new segment that starts at midnight and lasts till the time it closes (early AMs usually)
lastSegmentYesterday = #{#"start":#"0000", #"end":[tempSegment[#"end"] substringFromIndex:1]};
}
}
}
// add last night segment that passes midnight as the first segment of today
if (lastSegmentYesterday.count){
[venueOpenSegments insertObject:lastSegmentYesterday atIndex:0];
}
// go through all the segments and find out if the venue is closed or open
if (venueOpenSegments.count){
NSDateComponents *comps = [[NSDateComponents alloc] init];
NSDateFormatter *timeFormatter = [[NSDateFormatter alloc]init];
timeFormatter.dateFormat = #"HH:mm"; // set time output format
int segmentNumber = 0;
for (NSMutableDictionary *segment in venueOpenSegments){
segmentNumber++;
// confing start date
[comps setDay:compsNow.day];
[comps setMonth:compsNow.month];
[comps setYear:compsNow.year];
[comps setHour:[[segment[#"start"] substringToIndex:2] intValue]];
[comps setMinute:[[segment[#"start"] substringFromIndex:2] intValue]];
NSDate *dateStart = [[[NSCalendar currentCalendar] dateFromComponents:comps] copy];
// config end date
// check if the segment goes to next day
BOOL closesTomorrow = NO;
if ( [segment[#"end"] length]==5 ){
segment[#"end"] = [segment[#"end"] substringFromIndex:1];
closesTomorrow = YES;
}
[comps setHour:[[segment[#"end"] substringToIndex:2] intValue]];
[comps setMinute:[[segment[#"end"] substringFromIndex:2] intValue]];
NSDate *dateEnd = [[[NSCalendar currentCalendar] dateFromComponents:comps] copy];
// add a day if it closes tomorrow
if (closesTomorrow){
NSDateComponents *nextDayComponent = [[NSDateComponents alloc] init];
nextDayComponent.day = 1;
dateEnd = [gregorian dateByAddingComponents:nextDayComponent toDate:dateEnd options:0];
}
// start checking if it's open or closed
// now < segment start
if ([dateNow compare:dateStart] == NSOrderedAscending){
venueOpenText = [NSString stringWithFormat:#"opens at %#",[timeFormatter stringFromDate: dateStart]];
venueOpen = #"later";
break;
}
// segment end < now
else if ([dateEnd compare:dateNow] == NSOrderedAscending){
if (segmentNumber == venueOpenSegments.count){
venueOpenText = [NSString stringWithFormat:#"closed since %#",[timeFormatter stringFromDate: dateEnd]];
break;
}
continue;
}
// segment start < now < segment end
else if ([dateStart compare:dateNow] == NSOrderedAscending && [dateNow compare:dateEnd] == NSOrderedAscending){
venueOpenText = [NSString stringWithFormat:#"open till %#",[timeFormatter stringFromDate: dateEnd]];
venueOpen = #"yes";
break;
}
// rare but possible... last minute of the venue being open (I treat it as closed)
else {
venueOpenText = #"closing right now";
}
}
}
else venueOpen = #"closed today"; // no segments for today, so it's closed for the dayæ
// return results
return #{#"open":venueOpen, #"string":venueOpenText};
}
and I update my UILabel like this:
NSDictionary *venueOpen = [self isVenueOpenDictionaryForHours:_arrayVenues[indexPath.row][#"hours"]];
label.text = venueOpen[#"string"];
if ([venueOpen[#"open"] isEqualToString:#"no"]){
label.textColor = [UIColor colorWithHexString:#"b91d47" alpha:1]; // red
} else if ([venueOpen[#"open"] isEqualToString:#"yes"]) {
label.textColor = [UIColor colorWithHexString:#"1e7145" alpha:1]; // green
} else if ([venueOpen[#"open"] isEqualToString:#"later"]) {
label.textColor = [UIColor colorWithHexString:#"e3a21a" alpha:1]; // yellow
}
BTW, I use pod 'HexColors' for colorWithHexString methods

Chronologically organize Cells in TableView

I have two UITableViewCell's that each correspond to a Twitter Tweet or a Instagram Pic. As of now I have set it so that It will alternate between the two cells and have It go from an Twitter Tweet to an Instagram Pic. However I want to organize the UITableView so that it organizes both the Twitter Tweets and Instagram Pics chronologically in the TableView. Both the date keys for the Instagram API and the Twitter API are different. The Twitter API has a time key of created_at and Instagram's key is created_time. How would I organize both these Arrays? P.S. Both the arrays which the Tweets and Pics are in are NSMutableArray's.
Here is the Code that I have tried thus far:
// Setup for Cells
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *twitterCell = [self createTwitterCell:indexPath];
UITableViewCell *instagramCell = [self createInstagramCell:indexPath];
if (indexPath.row % 2 == 0) {
return twitterCell;
}else{
return instagramCell;
}
}
// Array Updater
- (void)updateArrays {
instaPics = self.timelineResponse[#"data"];
totalFeed = [tweets arrayByAddingObjectsFromArray:instaPics];
[self sortArrayBasedOndate:totalFeed];
}
// Current flawed method to organize by date
- (void)sortArrayBasedOndate {
NSDateFormatter *fmtDate = [[NSDateFormatter alloc] init];
[fmtDate setDateFormat:#"yyyy-MM-dd"];
NSDateFormatter *fmtTime = [[NSDateFormatter alloc] init];
[fmtTime setDateFormat:#"HH:mm"];
NSComparator compareDates = ^(id string1, id string2)
{
// Instagram Date Retrieval
NSDictionary *instagram = self.instaPics;
NSString *createdAt = instagram[#"created_time"];
int createdAtN = [createdAt intValue];
NSTimeInterval timestamp = (NSTimeInterval)createdAtN;
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timestamp];
// Twitter Date Retrieval
NSDictionary *twitter = self.tweets;
NSDate *date2 = twitter[#"created_at"];
return [date1 compare:date2];
};
NSSortDescriptor * sortDesc1 = [[NSSortDescriptor alloc] initWithKey:#"start_date" ascending:YES comparator:compareDates];
[totalFeed sortUsingDescriptors:#[sortDesc1]];
}
If you guys need any more code excerpts feel free to ask :)
It seems like you're on the right track. Why don't you also format Twitter's time to match your formatting for Instagram's time?
NSComparator compareDates = ^(id string1, id string2)
{
// Instagram Date Retrieval
NSDictionary *instagram = self.instaPics;
NSString *createdAt = instagram[#"created_time"];
int createdAtN = [createdAt intValue];
NSTimeInterval timestamp = (NSTimeInterval)createdAtN;
NSDate *date1 = [NSDate dateWithTimeIntervalSince1970:timestamp];
// Twitter Date Retrieval
NSDictionary *twitter = self.tweets;
NSString *twitterCreated = twitter[#"created_at"];
int createdAtTwitter = [twitterCreated intValue];
NSTimeInterval timestampTwitter = (NSTimeInterval)createdAtTwitter;
NSDate *date2 = [NSDate dateWithTimeIntervalSince1970:timestampTwitter];
return [date1 compare:date2];
};

EKEvent is not added according to given EKRecurrenceRule

I'm trying to add an event into calendar with recurrence rule RRULE:FREQ=YEARLY;BYMONTH=6,7;BYDAY=1TH
So according to this rule the event should be added yearly, each 1st thursday of june and july until expire date, which I've set in my project.
In my project, events are created but not according to the recurrence rule. With the following code the events added only on each 1st thursday of june. Why the events are not added on 1st thursday of each july also?
Here is .m file code
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self createEvent];
}
- (void)createEvent
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"testRecurrenceRule";
event.location = #"Dhaka";
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
event.startDate = [self dateFromString:#"2013-06-18T21:00:00+06:00"];
event.endDate = [self dateFromString:#"2013-06-18T22:00:00+06:00"];
id recurrenceRule = [self recurrenceRuleForEvent];
if(recurrenceRule != nil)
[event addRecurrenceRule:recurrenceRule];
if ([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted)
{
dispatch_async(dispatch_get_main_queue(), ^{
[self saveTheEvent:event eventStore:eventStore];
//[eventStore saveEvent:event span:EKSpanThisEvent error:error];
});
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
//do nothing
});
}
}];
}
else
{
[self saveTheEvent:event eventStore:eventStore];
}
textView.text = [NSString stringWithFormat:#"Event has been added with recurrence rule %#",recurrenceRule];
}
- (void)saveTheEvent:(EKEvent *)aEvent eventStore:(EKEventStore *)aStore
{
[aStore saveEvent:aEvent span:EKSpanThisEvent error:NULL];
}
- (EKRecurrenceRule *)recurrenceRuleForEvent
{
//just creating a recurrence rule for RRULE:FREQ=YEARLY;BYMONTH=6,7;BYDAY=1TH
// setting the values directly for testing purpose.
//FREQ=YEARLY
EKRecurrenceFrequency recurrenceFrequency = EKRecurrenceFrequencyYearly;
NSInteger recurrenceInterval = 1;
EKRecurrenceEnd *endRecurrence = nil;
NSMutableArray *monthsOfTheYearArray = [NSMutableArray array];
NSMutableArray *daysOfTheWeekArray = [NSMutableArray array];
NSMutableArray *daysOfTheMonthArray = [NSMutableArray array];
NSMutableArray *weeksOfTheYearArray = [NSMutableArray array];
NSMutableArray *daysOfTheYearArray = [NSMutableArray array];
NSMutableArray *setPositionsArray = [NSMutableArray array];
//BYMONTH=6,7
[monthsOfTheYearArray addObject:[NSNumber numberWithInt:6]];
[monthsOfTheYearArray addObject:[NSNumber numberWithInt:7]];
//BYDAY=1TH
[daysOfTheWeekArray addObject:[EKRecurrenceDayOfWeek dayOfWeek:5 weekNumber:1]];
endRecurrence = [EKRecurrenceEnd recurrenceEndWithEndDate:[self dateFromString:#"2018-12-15T22:30+06:00"]];
EKRecurrenceRule *recurrence = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:recurrenceFrequency
interval:recurrenceInterval
daysOfTheWeek:daysOfTheWeekArray
daysOfTheMonth:daysOfTheMonthArray
monthsOfTheYear:monthsOfTheYearArray
weeksOfTheYear:weeksOfTheYearArray
daysOfTheYear:daysOfTheYearArray
setPositions:setPositionsArray
end:endRecurrence];
return recurrence;
}
- (NSDate *)dateFromString:(NSString *)string
{
//check if the date string in null
if ([string length] == 0)
return nil;
NSString *dateString = nil;
NSString *modifiedString = nil;
BOOL secSpotMissing = false;
NSRange range = [string rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:#"T"]];
if (range.location != NSNotFound)
{
dateString = [string substringFromIndex:range.location];
range = [dateString rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:#"+-Z"]];
if (range.location != NSNotFound)
{
//seperate the time portion of date string and checking second field is missing or not. like is it HH:mm or HH:mm:ss?
if ([[[dateString substringToIndex:range.location] componentsSeparatedByString:#":"] count] < 3)
secSpotMissing = true;
//seperate the time zone portion and checking is there any extra ':' on it. It should like -0600 not -06:00. If it has that extra ':', just replacing it here.
dateString = [dateString substringFromIndex:range.location];
if([dateString hasSuffix:#"Z"])
modifiedString = [dateString stringByReplacingOccurrencesOfString:#"Z" withString:#"+0000"];
else
modifiedString = [dateString stringByReplacingOccurrencesOfString:#":" withString:#""];
string = [string stringByReplacingOccurrencesOfString:dateString withString:modifiedString];
}
}
else
return nil;
// converting the date string according to it's format.
NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
if (secSpotMissing)
[dateFormatter setDateFormat:#"yyyy-MM-dd'T'HH:mmZZZ"];
else
[dateFormatter setDateFormat:#"yyyy-MM-dd'T'HH:mm:ssZZZ"];
return [dateFormatter dateFromString:string];
}
Can somebody please help me regarding this?
This seems a repeat of another question. Basically, according to "BYDAY" rule, the 1st for YEARLY frequency means the first week in the year - instead of 1st week each month.
#Shuvo, I did not read rfc. But here is Apple document EKRecurrenceDayOfWeek.
The EKRecurrenceDayOfWeek class represents a day of the week for use with an EKRecurrenceRule object. A day of the week can optionally have a week number, indicating a specific day in the recurrence rule’s frequency. For example, a day of the week with a day value of Tuesday and a week number of 2 would represent the second Tuesday of every month in a monthly recurrence rule, and the second Tuesday of every year in a yearly recurrence rule.
When you say "1st Thursday", that is correct - except in the context of yearly, it is 1st thursday of the year.
The bug was confirmed by Apple, at least until iOS 7.1.3 (which is the latest available version at this moment).

Resources