Peter-Schorn/SpotifyAPI

Question: using this library on older XCode/Swift

Closed this issue · 16 comments

Hello! This library looks amazing, and i'm keen to use it for a little (non-commercial, hobby) project i'm doing in Swift. However, i'm a bit of a noob at macOS programming and the Swift package ecosystem.

My question is, would it be easy for me to make it possible to include this library in a Swift 5.1 project? If the answer is that it'd be difficult, that's fine, i can search for another approach – i don't want to cause you work. I'd be happy to maintain a modification on my fork, or perhaps do something else like build a standalone library that can be included in XCode.

I don't yet want to upgrade my macOS from 10.14.6/Mojave because my MacBook is quite old, but that blocks me on XCode version 11.3.1 (11C505) and Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15). I might be wrong! If there's a way to use Swift 5.3 (which it appears your project uses) i am open to trying that, too.

Please feel free to close this issue if you think it's going to be difficult or laborious or if you think it's completely off-topic. Thanks!

I'm happy to help you out. I want people to use this library; I've spent a lot of time developing it! Try out the "swift-tools-5-1" branch. Unlike master, It should be compatible with Swift 5.1 and 5.2. Let me know if you have any issues.

I will give it a try and report back!

I have been able to add the library to my project – thank you very much for your help. I consider this issue solved, i'll see if i can figure out the rest of it with the very decent-looking documentation you have provided 🙌

Cheers!

You can use newer versions of swift with any version of Xcode. See this article.

You can use newer versions of swift with any version of Xcode. See this article.

Ah, i tried searching the web for something similar, but failed! Thanks for that pointer.

Unfortunately since my computer is on macOS 10.14.6, my project has a deployment target of 10.14. However, it seems SpotifyAPI requires 10.15. I will try building the library for 10.14, and see what happens.

I will try building the library for 10.14, and see what happens.

It won't build on 10.14 because one of the dependencies, swift-crypto requires 10.15. I will look into ways of fixing this.

Hm, it seems a transitive dependency, swift-crypto requires macOS 10.15 for a few reasons: apple/swift-crypto#29.

EDIT: I see you beat me to it!

The library only uses a single function from Crypto:

let hash = SHA256.hash(data: data)

See if you can find another dependency with this function. It's possible to depend on Crypto for swift 5.3 and depend on a different library for 5.1 and 5.2.

I don't yet want to upgrade my macOS from 10.14.6/Mojave because my MacBook is quite old

Is macOS 10.15 not supported by your computer? If not, you really should consider updating. It'll make your life easier.

I tried going down the path of patching swift-crypto to exclude CryptoKit, but it's a bit of a rabbit hole. I might look for alternatives to that SHA256 function, thanks!

My laptop should support Big Sur, but honestly, everything works fine and i'm hesitant to run the risk of a slow laptop for not much reason – but this library is the first good argument, haha. I'll see how i go. Thank you for your patience in the meantime!

You don't need to update to Big Sur; you just need to update to Catalina. What makes you think that this will slow down your laptop?

Unlike many other languages, the development cycle of Swift is very rapid. If you don't update, your older os very quickly becomes unsupported.

You don't need to update to Big Sur; you just need to update to Catalina.

Yep, fair enough.

What makes you think that this will slow down your laptop?

Unsubstantiated rumours and the fact that my laptop is 6+ years old.

Back on-topic though, i managed to use a suggestion from https://stackoverflow.com/a/38788437 to avoid the dependency on CryptoKit by implementing SHA256 from CommonCrypto, but subsequently it turns out all the Scheduler, Publisher etc. are only available on 10.15. I guess my hand is forced now, haha.

but subsequently it turns out all the Scheduler, Publisher etc. are only available on 10.15.

Actually we can use OpenCombine for this. I already use it for Linux because Combine is not available on this platform.

I tried my hand simply replacing all the import Combine with import OpenCombineShim, but that didn't seem to work (it says OpenCombineShim isn't available – even though i added it into Package.swift as a dependency). Also tried updating to OpenCombine 0.12.0.

I think i might give up and just upgrade my old laptop. Thanks for bearing with me though!

I just tried it, and I was able to import OpenCombineShim and successfully build the library. May it doesn't work on your version of macOS. However, even if this is the case then we can do the following instead:

#if canImport(Combine)
import Combine
#else
import OpenCombine
#if canImport(OpenCombineDispatch)
import OpenCombineDispatch
#endif
#if canImport(OpenCombineFoundation)
import OpenCombineFoundation
#endif
#endif

This is what OpenCombineShim does, anyway. It's only a convenience that prevents you from needing to add the above to each file in your project.

In the meantime i have installed latest macOS Big Sur and Xcode and i am happily using version 1.6.1 of your library – as far as i'm concerned this issue is closed, thank you! 🙌