Hi,
I am new to the programming language SWIFT. During our school project at school we would like to create an Apple Watch app which allows you to create an calendar event. I have search many Google pages, but I can't find the correct answer. Does anybody know if this implementation is possible through WatchKit? On Google I found a few solutions, but these are developed with Objective C.
I would like to thank you in advance!
Jelle
OK, so, to confirm, you’re getting an “Extra argument error in call” error on line 17? If so, that’s likely a Swift 1 vs Swift 2 thing. Swift 2 has a new error handling model that translates Objective-C methods that return an NSError into Swift methods that throw. This code was written for the Swift 1 model so you’ll have to update it to the Swift 2 model.
In this case you need code like this:
do {
try eventStore.saveCalendar(yourReminderCalendar, commit: true)
print("reminder cal saved")
} catch {
// … handle the error …
}You can learn more about Swift error handling in the standard Swift docs.
Notwithstanding the above, I should also point out that saving an event store is specifically not allowed on watchOS. If you open the Objective-C header
<EventKit/EKEventStore.h>, you’ll see the method is decorated with
__WATCHOS_PROHIBITED.
- (BOOL)saveCalendar:(EKCalendar *)calendar commit:(BOOL)commit error:(NSError **)error NS_AVAILABLE(10_8, 5_0) __WATCHOS_PROHIBITED;So if you put the Swift code above into a watchOS extension it fails to compile with a different error message, namely, “'saveCalendar(_:commit:)' has been explicitly marked unavailable here”.
One option here is to use WatchKit Connectivity to request that your iOS app make this change on behalf of the watchOS extension.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"