I'm trying to incorporate the GIPHY API into my project.
In my AppDelegate, I set the API Key to the public beta key (just to test it out):
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
SwiftyGiphyAPI.shared.apiKey = "dc6zaTOxFJmzC"
// Override point for customization after application launch.
return true
}
And this is from a public class SwiftyGiphyAPI
:
public static let publicBetaKey = "dc6zaTOxFJmzC"
/// Access the Giphy API through the shared singleton.
public static let shared: SwiftyGiphyAPI = SwiftyGiphyAPI()
/// Before you can use SwiftyGiphy, you need to set your API key.
public var apiKey: String? {
didSet {
if apiKey == SwiftyGiphyAPI.publicBetaKey
{
print("****************************************************************************************************************************")
print("* *")
print("* IMPORTANT: You seem to be using Giphy's public beta key. Please change this to a production key before shipping. *")
print("* Apply for one here: http://api.giphy.com/submit *")
print("* *")
print("****************************************************************************************************************************")
print("")
}
}
}
And when the Controller opens, the trending section is supposed to show the trending GIFs, this is the beginning of that function:
func getTrending(limit: Int = 25, rating: SwiftyGiphyAPIContentRating = .pg13, offset: Int? = nil, completion: GiphyMultipleGIFResponseBlock?)
{
guard apiKey != nil || !isUsingDefaultAPIBase else {
print("ATTENTION: You need to set your Giphy API key before using SwiftyGiphy.")
completion?(networkError(description: NSLocalizedString("You need to set your Giphy API key before using SwiftyGiphy.", comment: "You need to set your Giphy API key before using SwiftyGiphy.")), nil)
return
}
I'm getting the print statement that You need to set your Giphy API key before using SwiftyGiphy.
I think it's because SwiftyGiphyAPI.shared.apiKey
is still an optional, so it's being read by SwiftyGiphyAPI
as nil. I've tried some optional chaining, but maybe I did it wrong.
I'm sure there's a simple fix I'm missing.
Also, here's a link to the GIPHY docs if that helps: GIPHY Docs
Thanks in advance for your help!