FatSecretSwift is a Framework built to help connect to the FatSecret REST api. Currently the framework supports foods.search
and food.get
.
- iOS 12
FatSecretSwift is currently only available by adding it as a submodule to your project.
git submodule add https://github.com/NicholasBellucci/FatSecretSwift.git
First step is to initialize your personal credentials. In the demo project this is done in the App Delegate but you can do this wherever you want so long as it is done before your API request.
import FatSecretSwift
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
enum Constants {
static let apiKey = ""
static let apiSecret = ""
}
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FatSecretCredentials.setConsumerKey(Constants.apiKey)
FatSecretCredentials.setSharedSecret(Constants.apiSecret)
return true
}
}
Once this has been done requests can be made by initializing the FatSecretClient.
let fatSecretClient = FatSecretClient()
All Codable structs can be found in the Models folder.
fatSecretClient.searchFood(name: "Hotdog") { search in
print(search.foods)
}
fatSecretClient.getFood(id: "16758") { food in
print(food)
}
Nicholas Bellucci, [email protected]
FatSecretSwift is available under the MIT license.