The main object containing the nutritional information is called PassioFoodItem. This object is fetched from Passio's backend using one of several fetchFoodItemFor... functions.
PassioFoodItem
The PassioFoodItem is a top level object that can represent a single food like a banana, or a complex recipe like caesar salad.
The name attribute is used to display the name of the food, while the details contains additional information like the brand of the food or the name of the food which was used to populate the nutritional data
iconId is used with the SDK function fetchIconFor to fetch a small image of the food
refCode is a parameter that can be used later on to retrieve the full food item again
amount details the available serving size as well as the currently selected serving quantity and unit, used when calculating nutrients
There are three functions that can be used to fetch nutrient information for the PassioFoodItem:
PassioNutritionAI.shared.fetchFoodItemFor(passioID:"VEG0025") { (foodItem) iniflet foodItem {// Getting nutrients for the referent 100 gramslet nutrientsRef = foodItem.nutrientsReference()// Getting nutrients for a specific weightlet nutrients250g = foodItem.nutrients(weight: Measurement<UnitMass>(value:250.0, unit: .grams))// Getting nutrients using the amount->selectedQuantity and// amount->selectedUnitlet nutrientsServing = foodItem.nutrientsSelectedSize()// Weight of the ingredientslet weight = foodItem.weight() }}
PassioSDK.instance.("VEG0025") { foodItem ->// Getting nutrients for the referent 100 gramsval nutrientsRef = foodItem!!.nutrientsReference()// Getting nutrients for a specific weightval nutrients250g = foodItem.nutrients(UnitMass(Grams, 250.0))// Getting nutrients using the amount->selectedQuantity and// amount->selectedUnitval nutrientsServing = foodItem.nutrientsSelectedSize()// Weight of the ingredientsval weight = foodItem.weight()}
constpassioFoodItem=awaitPassioSDK.fetchFoodItemForPassioID("VEG0025")// Getting nutrients for the referent 100 gramsconstnutrients=PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)// Getting nutrients for a specific weightconstnutrients=PassioSDK.getNutrientsOfPassioFoodItem(passioFoodItem,{unit:'g',value:250})// Getting nutrients using the amount->selectedQuantity and// amount->selectedUnitconstnutrients=PassioSDK.getNutrientsSelectedSizeOfPassioFoodItem(passioFoodItem)// Weight of the ingredientsconstval weight =passioFoodItem.weight()
final foodItem =awaitNutritionAI.instance.fetchFoodItemForPassioID('VEG0025');// Getting nutrients for the referent 100 gramsfinal nutrientsRef = foodItem!.nutrientsReference();// Getting nutrients for a specific weightfinal nutrients250g = foodItem.nutrients(UnitMass(250.0, UnitMassType.grams));// Getting nutrients using the amount->selectedQuantity and// amount->selectedUnitfinal nutrientsServing = foodItem.nutrientsSelectedSize();// Weight of the ingredientsfinal weight = foodItem.weight();
The weight function is used to fetch the sum mass of all of the ingredients.
PassioFoodAmount
This class holds the information about possible serving sizes and serving units, as well as the currently selected unit and quantity. Example of values for food item "apples"
serving units: small (2-3/4" dia), medium, large (3-1/4" dia), cup, oz, gram, ...
Serving units holds the list of all of the units that the system has the correct weight for.
Serving sizes holds the list of predefines matches of a quantity and a serving unit.
The selected quantity and unit are used to calculate nutrients on the PassioFoodItem level. While these values can be changed, the initial values are set by the SDK as a default portion.
PassioIngredient
Every PassioFoodItem has a list of ingredients. A food ingredient holds the nutritional information along with the portion size of each ingredient.
Similarly to PassioFoodItem, the ingredient also has a name, iconId, refCode, and amount.
But, the most important part of the ingredient class is the PassioNutrients and it's methods. The referenceNutrients attribute holds the referent (in most cases 100 grams) macronutrients and micronutrients, and are used to calculate the resulting nutrient values when changing serving sizes of the whole PassioFoodItem.
Also, an ingredient has PassioMetadata field, storing the information on the origin of the nutritional data, barcode value, possible ingredients (if the PassioFoodItem is a packaged food), and a list of tags.
Fetching nutrients
PassioNutritionAI.shared.fetchFoodItemFor(passioID:"VEG0025") { (foodItem) iniflet foodItem {let nutrients = foodItem.nutrientsReference()// Calories for 100 grams, values is in kCallet calories = nutrients.calories()?.value// Carbs for 100 grams, value is in gramslet carbs = nutrients.carbs()?.value// Potassium for 100 grams, value is in milligramslet potassiumMilli = nutrients.potassium()?.value// Potassium for 100 grams, value is in gramslet potassiumGrams = nutrients.potassium()?.gramsValue }}
PassioSDK.instance.fetchFoodItemForPassioID("VEG0025") { foodItem ->val nutrients = foodItem!!.nutrientsReference()// Calories for 100 grams, values is in kCalval calories = nutrients.calories()?.value// Carbs for 100 grams, value is in gramsval carbs = nutrients.carbs()?.value// Potassium for 100 grams, value is in milligramsval potassiumMilli = nutrients.potassium()?.value// Potassium for 100 grams, value is in gramsval potassiumGrams = nutrients.potassium()?.gramsValue()}
constpassioFoodItem=awaitPassioSDKBridge.fetchFoodItemForPassioID("VEG0025")constnutrients=PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)// Calories for 100 grams, values is in kCallet calories =passioNutrients.calories?.value// Carbs for 100 grams, value is in gramslet carbs =passioNutrients.carbs?.value// Potassium for 100 grams, value is in milligramslet potassiumMilli =passioNutrients.potassium?.value
final foodItem =awaitNutritionAI.instance.fetchFoodItemForPassioID('VEG0025');final nutrients = foodItem!.nutrientsReference();// Calories for 100 grams, values is in kCalfinal calories = nutrients.calories?.value;// Carbs for 100 grams, value is in gramsfinal carbs = nutrients.carbs?.value;// Potassium for 100 grams, value is in milligramsfinal potassiumMilli = nutrients.potassium?.value;// Potassium for 100 grams, value is in gramsfinal potassiumGrams = nutrients.potassium?.gramsValue();
Single food item vs recipe
The PassioFoodItem class encompasses both single food items like an avocado as well as items with multiple ingredients such as homemade caprese salad. The difference between these two items is how is the PassioFoodAmount calculated from the top-level PassioFoodItem.
Invoking the function foodItem.nutrientsServingSize() will fetch the nutrients for the whole recipe, calculated by the weight of the serving size "1 serving".
A single food item will always have only one ingredient. Also, the amount object of the PassioFoodItem will be the same as the amount of the first ingredient. The ingredient is the item in the database used for nutritional data. For example, If the SDK recognises "milk" during the visual detection process, the default food item for "milk" is "milk, whole, 3.25% milkfat, without added vitamin a and vitamin d".
UI Example
Fetch the PassioFoodItem
Use the name, details and iconId to create the food header view
Use the nutrientsSelectedSize->calories, carbs, protein and fat to show the marcos
Use the amount class to create the serving size view