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.
public struct PassioFoodItem: Codable {
public let id: String
public let name: String
public let details: String
public let iconId: String
public let licenseCopy: String
public let amount: PassioNutritionAISDK.PassioFoodAmount
public let ingredients: [PassioNutritionAISDK.PassioIngredient]
public let refCode: String?
}
data class PassioFoodItem(
val id: String,
val refCode: String,
val name: String,
val details: String,
val iconId: String,
val amount: PassioFoodAmount,
val ingredients: List<PassioIngredient>,
)
class PassioFoodItem {
final PassioFoodAmount amount;
final String details;
final String iconId;
final String id;
final List<PassioIngredient> ingredients;
final String name;
final String refCode;
final PassioID? scannedId;
}
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) in
if let foodItem {
// Getting nutrients for the referent 100 grams
let nutrientsRef = foodItem.nutrientsReference()
// Getting nutrients for a specific weight
let nutrients250g = foodItem.nutrients(weight: Measurement<UnitMass>(value: 250.0, unit: .grams))
// Getting nutrients using the amount->selectedQuantity and
// amount->selectedUnit
let nutrientsServing = foodItem.nutrientsSelectedSize()
// Weight of the ingredients
let weight = foodItem.weight()
}
}
PassioSDK.instance.("VEG0025") { foodItem ->
// Getting nutrients for the referent 100 grams
val nutrientsRef = foodItem!!.nutrientsReference()
// Getting nutrients for a specific weight
val nutrients250g = foodItem.nutrients(UnitMass(Grams, 250.0))
// Getting nutrients using the amount->selectedQuantity and
// amount->selectedUnit
val nutrientsServing = foodItem.nutrientsSelectedSize()
// Weight of the ingredients
val weight = foodItem.weight()
}
const passioFoodItem = await PassioSDK.fetchFoodItemForPassioID("VEG0025")
// Getting nutrients for the referent 100 grams
const nutrients = PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
// Getting nutrients for a specific weight
const nutrients = PassioSDK.getNutrientsOfPassioFoodItem(passioFoodItem,{unit:'g',value:250})
// Getting nutrients using the amount->selectedQuantity and
// amount->selectedUnit
const nutrients = PassioSDK.getNutrientsSelectedSizeOfPassioFoodItem(passioFoodItem)
// Weight of the ingredients
const val weight = passioFoodItem.weight()
final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
// Getting nutrients for the referent 100 grams
final nutrientsRef = foodItem!.nutrientsReference();
// Getting nutrients for a specific weight
final nutrients250g =
foodItem.nutrients(UnitMass(250.0, UnitMassType.grams));
// Getting nutrients using the amount->selectedQuantity and
// amount->selectedUnit
final nutrientsServing = foodItem.nutrientsSelectedSize();
// Weight of the ingredients
final 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.
public struct PassioIngredient: Codable {
public let id: String
public let name: String
public let iconId: String
public let amount: PassioFoodAmount
public let referenceNutrients: PassioNutrients
public let metadata: PassioFoodMetadata
public let refCode: String?
}
data class PassioIngredient(
val id: String,
val refCode: String,
val name: String,
val iconId: String,
val amount: PassioFoodAmount,
val referenceNutrients: PassioNutrients,
val metadata: PassioFoodMetadata,
)
class PassioIngredient {
final PassioFoodAmount amount;
final String iconId;
final String id;
final PassioFoodMetadata metadata;
final String name;
final String refCode;
final PassioNutrients referenceNutrients;
}
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) in
if let foodItem {
let nutrients = foodItem.nutrientsReference()
// Calories for 100 grams, values is in kCal
let calories = nutrients.calories()?.value
// Carbs for 100 grams, value is in grams
let carbs = nutrients.carbs()?.value
// Potassium for 100 grams, value is in milligrams
let potassiumMilli = nutrients.potassium()?.value
// Potassium for 100 grams, value is in grams
let potassiumGrams = nutrients.potassium()?.gramsValue
}
}
PassioSDK.instance.fetchFoodItemForPassioID("VEG0025") { foodItem ->
val nutrients = foodItem!!.nutrientsReference()
// Calories for 100 grams, values is in kCal
val calories = nutrients.calories()?.value
// Carbs for 100 grams, value is in grams
val carbs = nutrients.carbs()?.value
// Potassium for 100 grams, value is in milligrams
val potassiumMilli = nutrients.potassium()?.value
// Potassium for 100 grams, value is in grams
val potassiumGrams = nutrients.potassium()?.gramsValue()
}
const passioFoodItem = await PassioSDKBridge.fetchFoodItemForPassioID("VEG0025")
const nutrients = PassioSDK.getNutrientsReferenceOfPassioFoodItem(passioFoodItem)
// Calories for 100 grams, values is in kCal
let calories = passioNutrients.calories?.value
// Carbs for 100 grams, value is in grams
let carbs = passioNutrients.carbs?.value
// Potassium for 100 grams, value is in milligrams
let potassiumMilli = passioNutrients.potassium?.value
final foodItem = await NutritionAI.instance.fetchFoodItemForPassioID('VEG0025');
final nutrients = foodItem!.nutrientsReference();
// Calories for 100 grams, values is in kCal
final calories = nutrients.calories?.value;
// Carbs for 100 grams, value is in grams
final carbs = nutrients.carbs?.value;
// Potassium for 100 grams, value is in milligrams
final potassiumMilli = nutrients.potassium?.value;
// Potassium for 100 grams, value is in grams
final 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