CalendarLib

repository·master·Indexed 20 days ago

https://github.com/jumartin/calendar

An iOS library providing views and controllers for displaying and scheduling events, including day planner, month planner, and year views. It features built-in support for EventKit and allows for custom event providers and event cells. The library depends on OSCache and OrderedDictionary.

Tokens
1.4K
Snippets
4
Records
14
Agent score
72%

What's inside CalendarLib

  1. What is OSCache and how does it behave?

    master

    OSCache is an open-source re-implementation of NSCache designed to be predictable and debuggable. It functions as an LRU (Least-Recently-Used) cache, meaning objects are discarded oldest-first based on their last access time.

    Key behaviors:

    • Automatic Eviction: It automatically empties itself when a memory warning occurs.
    • NSCache Compatibility: It inherits from NSCache for easy drop-in replacement and implements all NSCache methods.
    • Limitations: It does not support NSDiscardableContent; evictsObjectsWithDiscardedContent will always return NO regardless of its setting.
  2. Understand OSCache performance characteristics

    master

    OSCache performance depends on the cache capacity:

    • When space is available: Reading, writing, and removing entries are constant time (O(1)).
    • When the cache is full: Insertion time degrades to linear (O(n)), while reading and removal remain constant (O(1)).

    Best Practice: Size your cache so it does not get full. If you must use a full cache, prefer a smaller size to avoid significant performance degradation during insertions.

  3. Configure ARC for non-ARC projects

    master

    OSCache requires ARC (Automatic Reference Counting). If your project does not use ARC, you must enable it specifically for the OSCache.m file:

    1. Go to the Build Phases tab in your target settings.
    2. Open the Compile Sources group.
    3. Double-click OSCache.m.
    4. Type -fobjc-arc into the popover.

    If you are converting an entire project to ARC, comment out the #error line in OSCache.m before using Xcode's 'Convert to Objective-C ARC...' refactoring tool.

  4. Use a custom event provider

    master
    If you are not using EventKit, you can use your own data source by subclassing MGCDayPlannerViewController or MGCMonthPlannerViewController and implementing the required data source protocol methods.
  5. Get started with EventKit data source

    master

    To use Apple's EventKit as your data source, instantiate or subclass MGCDayPlannerEKViewController or MGCMonthPlannerEKViewController.

    Important: You must add the following frameworks to your Xcode project:

    • EventKit.framework
    • EventKitUI.framework
    // Example: Using the EventKit Day Planner
    let ekViewController = MGCDayPlannerEKViewController()
    // Add to your view hierarchy
  6. Use OSCacheDelegate to veto object eviction

    master

    OSCache provides an OSCacheDelegate protocol, which is a superset of NSCacheDelegate. You can implement this protocol to gain control over the eviction process.

    The optional method - (BOOL)cache:(OSCache *)cache shouldEvictObject:(id)entry; is called before an object is evicted (due to adding a new item or a memory warning). If you return NO, you can veto the eviction.

    Note: This method is NOT called if you manually remove an object using -removeObjectForKey: or -removeAllObjects.

    // Implementation example
    - (BOOL)cache:(OSCache *)cache shouldEvictObject:(id)entry {
        // Return NO to prevent eviction of a specific object
        return YES;
    }