Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7513727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:16:28+00:00 2026-05-30T00:16:28+00:00

I’m new to iOS programming and I am working on a easy project that

  • 0

I’m new to iOS programming and I am working on a easy project that lists holidays from a given city and gives users the ability to add those events to the iCal default calendar.

The issue is: how to check if there is already an event with same properties (title and start date for example) in the user’s calendar. This could happen if the action button (used to add an event to iCal) is pressed more than once. In such a situation, I don’t want two or more identical events being created in iCal.

I have tried to use NSPredicate but I am totally lost on how to get it sorted.

Any help would come be appreciated!
Thanks in advance.

Bellow is my event-adding code just to make things clear. In this case a user is adding multiple events from a list (all local holidays for example).

for (int i = 0; i<[allHolidayNames count]; ++i) {

    // ------ EVENT MANIPULATION ------

    EKEventStore *eventStore = [[EKEventStore alloc] init];
    EKEvent *addEvent = [EKEvent eventWithEventStore:eventStore];
    addEvent.title = [allHolidayNames objectAtIndex:i];
    addEvent.startDate = [allHolidayDates objectAtIndex:i];
    addEvent.allDay = YES;
    [addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
    [eventStore saveEvent:addEvent span:EKSpanThisEvent commit:YES error:nil];
}   
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T00:16:30+00:00Added an answer on May 30, 2026 at 12:16 am

    Summary

    At some point in your instance method (probably during the for loop) you will want to create an NSPredicate based on [allHolidayDates objectAtIndex:i] to return an array that you loop through to check if [allHolidayNames objectAtIndex:i] is present in the returned events.

    Example code

    for (int i = 0; i<[allHolidayNames count]; ++i) {
    
        // ------ EVENT MANIPULATION ------
    
        EKEventStore *eventStore = [[EKEventStore alloc] init];
    
        NSPredicate *predicateForEventsOnHolidayDate = [eventStore predicateForEventsWithStartDate:[allHolidayDates objectAtIndex:i] endDate:[allHolidayDates objectAtIndex:i] calendars:nil]; // nil will search through all calendars
    
        NSArray *eventsOnHolidayDate = [eventStore eventsMatchingPredicate:predicateForEventsOnHolidayDate]
    
        BOOL eventExists = NO;
    
        for (EKEvent *eventToCheck in eventsOnHolidayDate) {
            if ([eventToCheck.title isEqualToString:[allHolidayNames objectAtIndex:i]]) {
                eventExists = YES;
            }
        }
    
        if (eventExists == NO) {
            EKEvent *addEvent = [EKEvent eventWithEventStore:eventStore];
            addEvent.title = [allHolidayNames objectAtIndex:i];
            addEvent.startDate = [allHolidayDates objectAtIndex:i];
            addEvent.allDay = YES;
            [addEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
            [eventStore saveEvent:addEvent span:EKSpanThisEvent commit:YES error:nil];
        }
    }
    

    Tips

    • To help visualise the data, especially the contents of arrays and objects, try using NSLog. This will output the contents of an object to the console to help you understand the data structures a bit better.

      NSLog(“eventsOnHolidayDate = %@”,eventsOnHolidayDate);

    • Note that eventsMatchingPredicate will block the main thread whilst retrieving events. If your doing this multiple times in a row it could impact on the user experience. You should consider using enumerateEventsMatchingPredicate:usingBlock: (outside the scope of this question).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.