richardtop / CalendarKit

📅 Calendar for Apple platforms in Swift
https://www.youtube.com/watch?v=cJ63-_z1qg8
MIT License
2.52k stars 340 forks source link

Fails to build when accessed via notification content extension #278

Closed grosch closed 3 years ago

grosch commented 3 years ago

New Issue Checklist

Issue Description

I'm using a new SwiftUI app to update my existing project. The only place I use CalendarKit is in the notification content extension, which is still UIKit. I added your library via SPM and made sure to point at the master branch. I'm using the exact same code as the original version used. The only difference is that one was done via CocoaPods and this one is of course using Swift Package Manager.

As soon as I use something like TimelineView I'm getting tons of errors.

Code I'm using with CalendarKit
let timeline = TimelineView()

That line, for example, will result in these errors:

Undefined symbol: type metadata accessor for CalendarKit.TimelineView Undefined symbol: CalendarKit.TimelineView.__allocating_init() -> CalendarKit.TimelineView

NotificationViewController.txt

grosch commented 3 years ago

Here's a minimal example showing it.

I create a new app, added a content extension, added your package, and it builds fine. Then edit NotificationViewController.swift to create a TimelineView and the errors appear.

example.zip

richardtop commented 3 years ago

Thanks for reporting it, I'll look into it. Does it work well when used with CocoaPods?

grosch commented 3 years ago

Another data point as I keep playing. If I access it from the primary app target it's fine. So it appears to be something to do with accessing it from the other target specifically. I've seen issues reported where SPM fails when new targets are added later, and I explicitly made sure that all the targets were created before I added your package.

I would assume it would still work OK with cocoapods as that's how it was originally done. This seems to be specific to SPM, which I definitely want to use, as I'm updating the Push Notifications book from raywenderlich.com to be current.

richardtop commented 3 years ago

What's the Xcode version you're using? Are there going to be some CalendarKit Ray Wenderlich tutorials?

grosch commented 3 years ago

Version 12.2 beta 2 (12B5025f)

Tutorials, no. But in my Push Notifications book, in chapter 12 where I show a "real world" full example, it uses CalendarKit to handle showing the calendar in the push notification itself.

richardtop commented 3 years ago

Thanks for the info. I was able to find the sample, looks good! Never thought this is mentioned in a book. I'd appreciate a copy if possible just to keep it.

Also, if you wish I might review the way CK is used in the book to see if something could be improved.

Overall, could you please triangulate the root cause of this problem, more precisely, is it an Xcode BETA issue or a CK issue?

grosch commented 3 years ago

Chuckle, you just don't remember. I bugged the crap out of you a few years ago figuring out how to make this work. It only does cause you pointed me at the timeline stuff :) I'd love to have you review how it works though. Might be better ways now. The complete code is in the NotificationViewController.txt attachment I did when opening the issue.

It's seems to be explicitly a bug with how SPM is working with CK. I found a bunch of articles saying if you remove the dead code stripping it'll work, but that's not fixing it, and is also bad for SwiftUI projects as it depends on that for removing all the preview related code.

richardtop commented 3 years ago

I do remember. On the surface, your code looks correct, without any significant issues.

This might be related to referencing DateTools, although I'm not sure about it. Are you including the library into the project?

richardtop commented 3 years ago

Also, build fails for me in the attached example

grosch commented 3 years ago

When I include CK it automatically adds DateToolsSwift as a dependency as well. I did try and explicitly add that one as an import but it made no difference.

grosch commented 3 years ago

Oh, and I asked the publisher about getting you a copy of the book.

richardtop commented 3 years ago

Thank you. Okay, could this be related to the latest pull request? #277 We could just wait for the Xcode 12.2 to go out of beta and use CocoaPods right now. The problem is likely to resolve itself.

grosch commented 3 years ago

Nope. However, I found a workaround. I realized I'm only using your package in the other target, so I delete and re-added your package but this time noticed that I can pick which target to add as a dependency, so I picked the content extension and now I'm good.

As to the book...If you give me your email address the publisher will get you hooked up with a book.

richardtop commented 3 years ago

Ok, so just to be clear: the issue is resolved now and everything works as expected. My email is topchiy@protonmail.ch

grosch commented 3 years ago

Yes, the issue is resolved and had nothing to do with your package.