Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the EKEventStore instance a Singleton #552

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ios/Classes/SwiftDeviceCalendarPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ extension String {
}
}

fileprivate class SingleEventStore {
public let eventStore: EKEventStore

public static let shared = SingleEventStore()

private init() {
eventStore = EKEventStore()
}
Comment on lines +27 to +33

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this initialise two instances of EKEventStore?

1: eventStore which doesn't appear to be used, and 2: shared

Copy link
Author

@AlexisChoupault AlexisChoupault Nov 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. The whole point of the Singleton pattern is that the class and its attributes are instantiated only once at runtime.
In my code the only way to instantiate a SingleEventStore is through its static instance shared, which calls the constructor where eventStore is instantiated (only once)

}

public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDelegate, UINavigationControllerDelegate {
struct DeviceCalendar: Codable {
let id: String
Expand Down Expand Up @@ -102,7 +112,7 @@ public class SwiftDeviceCalendarPlugin: NSObject, FlutterPlugin, EKEventViewDele
let calendarNotFoundErrorMessageFormat = "The calendar with the ID %@ could not be found"
let calendarReadOnlyErrorMessageFormat = "Calendar with ID %@ is read-only"
let eventNotFoundErrorMessageFormat = "The event with the ID %@ could not be found"
let eventStore = EKEventStore()
let eventStore = SingleEventStore.shared.eventStore
let requestPermissionsMethod = "requestPermissions"
let hasPermissionsMethod = "hasPermissions"
let retrieveCalendarsMethod = "retrieveCalendars"
Expand Down
Loading