SwifterSwift / SwifterSwift

A handy collection of more than 500 native Swift extensions to boost your productivity.
https://swifterswift.com
MIT License
13.91k stars 1.62k forks source link

SwifterSwift compilation error when used in an app extension target #915

Closed tospery closed 3 years ago

tospery commented 3 years ago

Because SwifterSwift contains UIApplication, so it can't use in Network Extension.Hope to do a compatibility.

LucianoPAlmeida commented 3 years ago

Sorry, I didn't really understand the issue... can you provide a more detailed description and if possible an example?

tospery commented 3 years ago
  1. When I integrate SwifterSwift into the extension application (Network Extension -> Packet Tunnel) image
  2. Compile project will error: image
LucianoPAlmeida commented 3 years ago

Ah thanks, we'll take a look ASAP :)

LucianoPAlmeida commented 3 years ago

Here is a reference https://davedelong.com/blog/2019/04/09/conditional-compilation-part-3/ But we actually need a simpler solution to conditionally not compiling for app extensions, I was looking to see if we can mark the whole show function as unavailable for app extensions. But still couldn't found how to use or if it is possible to use NS_EXTENSION_UNAVAILABLE_IOS on Swift.

But to be really honest to me personally, this extension should be changed to take the viewController as a parameter. But not sure if we could do that because it will be an breaking change and I suspect people use this.

LucianoPAlmeida commented 3 years ago

@tospery Can you verify if changing the function show to having the following attribute fixes the issue?

@available(iOSApplicationExtension, unavailable)
func show(...) ...
LucianoPAlmeida commented 3 years ago

Fixed on master, feel free to reopen if this still an issue :)