├── Nutrition.doccarchive ├── favicon.ico ├── index │ ├── data.mdb │ ├── navigator.index │ └── availability.index ├── developer-og.jpg ├── developer-og-twitter.jpg ├── metadata.json ├── images │ └── macrofactor-automations.Nutrition │ │ └── mf_transparent_white.png ├── img │ ├── deprecated-icon.7bf1740a.svg │ ├── added-icon.832a5d2c.svg │ └── modified-icon.efb2697d.svg ├── js │ ├── highlight-js-shell-js.0ad5b20f.js │ ├── highlight-js-json-js.2a1856ba.js │ ├── highlight-js-diff-js.4db9a783.js │ └── highlight-js-http-js.f78e83c2.js ├── favicon.svg ├── index.html └── documentation │ └── nutrition │ ├── index.html │ ├── beverage │ └── index.html │ ├── icon │ ├── egg │ │ └── index.html │ ├── fig │ │ └── index.html │ ├── index.html │ ├── jar │ │ └── index.html │ ├── nut │ │ └── index.html │ ├── oil │ │ └── index.html │ ├── pie │ │ └── index.html │ ├── tea │ │ └── index.html │ ├── !=(_:_:) │ │ └── index.html │ ├── acorn │ │ └── index.html │ ├── almond │ │ └── index.html │ ├── apple │ │ └── index.html │ ├── applered │ │ └── index.html │ ├── avocado │ │ └── index.html │ ├── babymilk │ │ └── index.html │ ├── bacon │ │ └── index.html │ ├── bagel │ │ └── index.html │ ├── bananas │ │ └── index.html │ ├── beanspan │ │ └── index.html │ ├── biryani │ │ └── index.html │ ├── biscotti │ │ └── index.html │ ├── biscuit │ │ └── index.html │ ├── broccoli │ │ └── index.html │ ├── butter │ │ └── index.html │ ├── cabbage │ │ └── index.html │ ├── calzone │ │ └── index.html │ ├── candy │ │ └── index.html │ ├── candybar │ │ └── index.html │ ├── carrot │ │ └── index.html │ ├── cashews │ │ └── index.html │ ├── celery │ │ └── index.html │ ├── chard │ │ └── index.html │ ├── cherries │ │ └── index.html │ ├── chestnut │ │ └── index.html │ ├── chicken │ │ └── index.html │ ├── cinnamon │ │ └── index.html │ ├── cocoa │ │ └── index.html │ ├── coconut │ │ └── index.html │ ├── coffee │ │ └── index.html │ ├── congee │ │ └── index.html │ ├── corn │ │ └── index.html │ ├── crab │ │ └── index.html │ ├── creamer │ │ └── index.html │ ├── croutons │ │ └── index.html │ ├── cucumber │ │ └── index.html │ ├── daikon │ │ └── index.html │ ├── date │ │ └── index.html │ ├── deer │ │ └── index.html │ ├── dill │ │ └── index.html │ ├── doughnut │ │ └── index.html │ ├── duck │ │ └── index.html │ ├── eggplant │ │ └── index.html │ ├── eggs │ │ └── index.html │ ├── falafel │ │ └── index.html │ ├── fish │ │ └── index.html │ ├── garlic │ │ └── index.html │ ├── ginger │ │ └── index.html │ ├── gravy │ │ └── index.html │ ├── guava │ │ └── index.html │ ├── honey │ │ └── index.html │ ├── hotdogs │ │ └── index.html │ ├── hummus │ │ └── index.html │ ├── jamred │ │ └── index.html │ ├── jello │ │ └── index.html │ ├── kefir │ │ └── index.html │ ├── ketchup │ │ └── index.html │ ├── kiwi │ │ └── index.html │ ├── lasagne │ │ └── index.html │ ├── lemon │ │ └── index.html │ ├── lentils │ │ └── index.html │ ├── lettuce │ │ └── index.html │ ├── lime │ │ └── index.html │ ├── lobster │ │ └── index.html │ ├── lychee │ │ └── index.html │ ├── mango │ │ └── index.html │ ├── mayo │ │ └── index.html │ ├── meatloaf │ │ └── index.html │ ├── milk │ │ └── index.html │ ├── milkrice │ │ └── index.html │ ├── milksoy │ │ └── index.html │ ├── mintgum │ │ └── index.html │ ├── muffin │ │ └── index.html │ ├── mushroom │ │ └── index.html │ ├── mustard │ │ └── index.html │ ├── oatmeal │ │ └── index.html │ ├── octopus │ │ └── index.html │ ├── omelette │ │ └── index.html │ ├── onion │ │ └── index.html │ ├── onionred │ │ └── index.html │ ├── orange │ │ └── index.html │ ├── oreos │ │ └── index.html │ ├── oyster │ │ └── index.html │ ├── pancake │ │ └── index.html │ ├── parsley │ │ └── index.html │ ├── peach │ │ └── index.html │ ├── peanut │ │ └── index.html │ ├── pear │ │ └── index.html │ ├── pearbosc │ │ └── index.html │ ├── pecan │ │ └── index.html │ ├── pinenut │ │ └── index.html │ ├── plum │ │ └── index.html │ ├── popcorn │ │ └── index.html │ ├── poptarts │ │ └── index.html │ ├── porkloin │ │ └── index.html │ ├── potato │ │ └── index.html │ ├── potpie │ │ └── index.html │ ├── pretzel │ │ └── index.html │ ├── prune │ │ └── index.html │ ├── pumpkin │ │ └── index.html │ ├── radishes │ │ └── index.html │ ├── raisins │ │ └── index.html │ ├── ravioli │ │ └── index.html │ ├── rhubarb │ │ └── index.html │ ├── ribs │ │ └── index.html │ ├── ricecake │ │ └── index.html │ ├── salami │ │ └── index.html │ ├── salsa │ │ └── index.html │ ├── sausage │ │ └── index.html │ └── scallops │ │ └── index.html │ ├── nutrient │ └── index.html │ └── serving │ └── index.html ├── CommunityShortcuts ├── LogAPint.shortcut ├── LogWater.shortcut ├── LogMyGymWaterBottle.shortcut └── README.md ├── .gitignore ├── Sources └── Nutrition │ ├── Documentation.docc │ ├── Resources │ │ └── images │ │ │ └── mf_transparent_white.png │ ├── MacroFactorTodaySummary.md │ └── Nutrition.md │ ├── Properties │ ├── Beverage.swift │ ├── GoalConsumptionRemaining.swift │ └── NutritionalContent.swift │ └── MacroFactorTodaySummary.swift ├── Tests └── NutritionTests │ └── Other │ └── StableJSONEncoder.swift └── Package.swift /Nutrition.doccarchive/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/favicon.ico -------------------------------------------------------------------------------- /CommunityShortcuts/LogAPint.shortcut: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/CommunityShortcuts/LogAPint.shortcut -------------------------------------------------------------------------------- /CommunityShortcuts/LogWater.shortcut: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/CommunityShortcuts/LogWater.shortcut -------------------------------------------------------------------------------- /Nutrition.doccarchive/index/data.mdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/index/data.mdb -------------------------------------------------------------------------------- /Nutrition.doccarchive/developer-og.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/developer-og.jpg -------------------------------------------------------------------------------- /Nutrition.doccarchive/index/navigator.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/index/navigator.index -------------------------------------------------------------------------------- /CommunityShortcuts/LogMyGymWaterBottle.shortcut: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/CommunityShortcuts/LogMyGymWaterBottle.shortcut -------------------------------------------------------------------------------- /Nutrition.doccarchive/developer-og-twitter.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/developer-og-twitter.jpg -------------------------------------------------------------------------------- /Nutrition.doccarchive/index/availability.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/index/availability.index -------------------------------------------------------------------------------- /Nutrition.doccarchive/metadata.json: -------------------------------------------------------------------------------- 1 | {"schemaVersion":{"major":0,"patch":0,"minor":1},"bundleDisplayName":"Nutrition","bundleIdentifier":"macrofactor-automations.Nutrition"} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | /.build 3 | /Packages 4 | xcuserdata/ 5 | DerivedData/ 6 | .swiftpm/configuration/registries.json 7 | .swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata 8 | .netrc 9 | -------------------------------------------------------------------------------- /Sources/Nutrition/Documentation.docc/Resources/images/mf_transparent_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Sources/Nutrition/Documentation.docc/Resources/images/mf_transparent_white.png -------------------------------------------------------------------------------- /Nutrition.doccarchive/images/macrofactor-automations.Nutrition/mf_transparent_white.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MacroFactor/apple-shortcuts/HEAD/Nutrition.doccarchive/images/macrofactor-automations.Nutrition/mf_transparent_white.png -------------------------------------------------------------------------------- /Tests/NutritionTests/Other/StableJSONEncoder.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | extension JSONEncoder { 4 | static func stable() -> JSONEncoder { 5 | let encoder = JSONEncoder() 6 | encoder.outputFormatting = [.prettyPrinted, .sortedKeys] 7 | return encoder 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /Sources/Nutrition/Properties/Beverage.swift: -------------------------------------------------------------------------------- 1 | /// Flag beverages for hydration tracker and alcoholic beverage counter features in MacroFactor and integrations, such as Apple Health. 2 | public enum Beverage: String, Codable, Equatable, CaseIterable, Sendable{ 3 | /// An alcoholic beverage for tracking consumption counts in Apple Health. 4 | case alcohol 5 | /// A non-alcoholic drink. 6 | case beverage 7 | } 8 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version: 5.11 2 | 3 | import PackageDescription 4 | 5 | let package = Package( 6 | name: "macrofactor-apple-shortcuts", 7 | defaultLocalization: "en", 8 | platforms: [ 9 | .iOS(.v15), .macOS(.v14), .watchOS(.v10), .tvOS(.v17) 10 | ], 11 | products: [ 12 | .library(name: "Nutrition", targets: ["Nutrition"]) 13 | ], 14 | targets: [ 15 | .target(name: "Nutrition"), 16 | .testTarget(name: "NutritionTests", dependencies: ["Nutrition"]) 17 | ] 18 | ) 19 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/img/deprecated-icon.7bf1740a.svg: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /Sources/Nutrition/Properties/GoalConsumptionRemaining.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// Remaining consumption today relative to any goal(s). Values are in grams, unless [otherwise specified](). If a goal is surpassed, values will be negative. 4 | public struct GoalConsumptionRemaining: Codable, Equatable, Sendable { 5 | public let minimum: Decimal? 6 | public let target: Decimal? 7 | public let maximum: Decimal? 8 | 9 | @_documentation(visibility: internal) 10 | public init(minimum: Decimal?, target: Decimal?, maximum: Decimal?) { 11 | self.minimum = minimum 12 | self.target = target 13 | self.maximum = maximum 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/img/added-icon.832a5d2c.svg: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/js/highlight-js-shell-js.0ad5b20f.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * This source file is part of the Swift.org open source project 3 | * 4 | * Copyright (c) 2021 Apple Inc. and the Swift project authors 5 | * Licensed under Apache License v2.0 with Runtime Library Exception 6 | * 7 | * See https://swift.org/LICENSE.txt for license information 8 | * See https://swift.org/CONTRIBUTORS.txt for Swift project authors 9 | */ 10 | (self["webpackChunkswift_docc_render"]=self["webpackChunkswift_docc_render"]||[]).push([[176],{7874:function(s){function e(s){return{name:"Shell Session",aliases:["console","shellsession"],contains:[{className:"meta",begin:/^\s{0,3}[/~\w\d[\]()@-]*[>%$#][ ]?/,starts:{end:/[^\\](?=\s*$)/,subLanguage:"bash"}}]}}s.exports=e}}]); -------------------------------------------------------------------------------- /Nutrition.doccarchive/js/highlight-js-json-js.2a1856ba.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * This source file is part of the Swift.org open source project 3 | * 4 | * Copyright (c) 2021 Apple Inc. and the Swift project authors 5 | * Licensed under Apache License v2.0 with Runtime Library Exception 6 | * 7 | * See https://swift.org/LICENSE.txt for license information 8 | * See https://swift.org/CONTRIBUTORS.txt for Swift project authors 9 | */ 10 | (self["webpackChunkswift_docc_render"]=self["webpackChunkswift_docc_render"]||[]).push([[82],{14:function(e){function n(e){const n={className:"attr",begin:/"(\\.|[^\\"\r\n])*"(?=\s*:)/,relevance:1.01},c={match:/[{}[\],:]/,className:"punctuation",relevance:0},a={beginKeywords:["true","false","null"].join(" ")};return{name:"JSON",contains:[n,c,e.QUOTE_STRING_MODE,a,e.C_NUMBER_MODE,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:"\\S"}}e.exports=n}}]); -------------------------------------------------------------------------------- /Sources/Nutrition/Documentation.docc/MacroFactorTodaySummary.md: -------------------------------------------------------------------------------- 1 | # ``MacroFactorTodaySummary`` 2 | 3 | ## JSON Examples 4 | 5 | #### No logging today, water goal unmet 6 | ```json 7 | { 8 | "consumed" : {}, 9 | "remaining" : { 10 | "water" : { 11 | "minimum" : 2000, 12 | "target" : 2500, 13 | "maximum" : 3500 14 | } 15 | } 16 | } 17 | ``` 18 | 19 | #### Logged 2.5 liters water, meeting or exceeding some goals 20 | ```json 21 | { 22 | "consumed" : { 23 | "water" : 2500 24 | }, 25 | "remaining" : { 26 | "water" : { 27 | "minimum" : -500, 28 | "target" : 0, 29 | "maximum" : 1000 30 | } 31 | } 32 | } 33 | ``` 34 | 35 | ## Topics 36 | 37 | ### Consumption Total Today 38 | 39 | - ``MacroFactorTodaySummary/consumed`` 40 | 41 | ### Remaining Consumption for Goal(s) 42 | 43 | - ``MacroFactorTodaySummary/remaining`` 44 | - ``GoalConsumptionRemaining`` 45 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/js/highlight-js-diff-js.4db9a783.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * This source file is part of the Swift.org open source project 3 | * 4 | * Copyright (c) 2021 Apple Inc. and the Swift project authors 5 | * Licensed under Apache License v2.0 with Runtime Library Exception 6 | * 7 | * See https://swift.org/LICENSE.txt for license information 8 | * See https://swift.org/CONTRIBUTORS.txt for Swift project authors 9 | */ 10 | (self["webpackChunkswift_docc_render"]=self["webpackChunkswift_docc_render"]||[]).push([[213],{7731:function(e){function n(e){const n=e.regex;return{name:"Diff",aliases:["patch"],contains:[{className:"meta",relevance:10,match:n.either(/^@@ +-\d+,\d+ +\+\d+,\d+ +@@/,/^\*\*\* +\d+,\d+ +\*\*\*\*$/,/^--- +\d+,\d+ +----$/)},{className:"comment",variants:[{begin:n.either(/Index: /,/^index/,/={3,}/,/^-{3}/,/^\*{3} /,/^\+{3}/,/^diff --git/),end:/$/},{match:/^\*{15}$/}]},{className:"addition",begin:/^\+/,end:/$/},{className:"deletion",begin:/^-/,end:/$/},{className:"addition",begin:/^!/,end:/$/}]}}e.exports=n}}]); -------------------------------------------------------------------------------- /Sources/Nutrition/Documentation.docc/Nutrition.md: -------------------------------------------------------------------------------- 1 | # ``Nutrition`` 2 | 3 | @Metadata { 4 | @TitleHeading("MacroFactor") 5 | @PageColor(purple) 6 | @PageImage(purpose: icon, source: mf_transparent_white.png, alt: "MacroFactor Logo") 7 | } 8 | 9 | ## Overview 10 | 11 | On iOS, you can use Apple's Shortcuts app to log food to MacroFactor via Siri and custom automations. 12 | 13 | Our *Log Food by JSON* intent uses ``MacroFactorFood`` to parse your input. All of our Shortcuts return a ``MacroFactorTodaySummary``. 14 | 15 | 16 | ## Topics 17 | 18 | ### JSON Schema 19 | 20 | - ``MacroFactorFood`` 21 | - ``MacroFactorTodaySummary`` 22 | 23 | ### Properties 24 | 25 | - ``Beverage`` 26 | - ``GoalConsumptionRemaining`` 27 | - ``Icon`` 28 | - ``Nutrient`` 29 | - ``Serving`` 30 | 31 | ### Encoding Containers 32 | 33 | These simply wrap a [Nutrient: Value] dictionary for encoding. (Swift's Codable implementation otherwise encodes these dictionaries as an array of alternating key value pairs.) 34 | 35 | - ``GoalConsumptionRemainingByNutrientDictionary`` 36 | - ``NutritionalContent`` 37 | -------------------------------------------------------------------------------- /Sources/Nutrition/MacroFactorTodaySummary.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// JSON schema for the output of Shortcuts that log food or report progress toward today's goals. 4 | public struct MacroFactorTodaySummary: Codable, Equatable, Sendable { 5 | 6 | /// Sum of nutrients in all logged food and drink today. All units are grams unless specified otherwise in ``Nutrition/Nutrient`` documentation. 7 | public let consumed: NutritionalContent 8 | 9 | /// Remaining consumption today relative to any goal(s) set for a ``Nutrient``. In the ``GoalConsumptionRemaining`` object, all units are grams unless specified otherwise in ``Nutrition/Nutrient`` documentation. A negative value indicates the goal has been exceeded. 10 | public let remaining: GoalConsumptionRemainingByNutrientDictionary 11 | 12 | @_documentation(visibility: internal) 13 | public init( 14 | consumed: [Nutrient : Decimal], 15 | remaining: [Nutrient : GoalConsumptionRemaining] 16 | ) { 17 | self.consumed = NutritionalContent(consumed) 18 | self.remaining = GoalConsumptionRemainingByNutrientDictionary(remaining) 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CommunityShortcuts/README.md: -------------------------------------------------------------------------------- 1 | # Sample MacroFactor Shortcuts 2 | 3 | | MacroFactor iCloud Link | Screenshot | Notes | 4 | | -- | -- | -- | 5 | | [Log yesterday's breakfast again](https://www.icloud.com/shortcuts/f2363fff4cfb4b7b98a59f2a62af02fb) | ![Log yesterdays breakfast](https://github.com/user-attachments/assets/90829198-2a35-4027-98d3-e2b2c0c5b109) | Uses `Find Recent Food` to filter anything logged yesterday between hours you can adjust | 6 | | [Log my water bottle](https://www.icloud.com/shortcuts/bd18321f460f4f7ea85dee8449b797a1) | ![Log water](https://github.com/user-attachments/assets/64cc84f1-d46d-4368-955f-64d46268b463) | Pre-fill size, unit, and/or name | 7 | | [Log a pint](https://www.icloud.com/shortcuts/37ddee2611d14931aa184953ac5f3606) | ![Log a pint](https://github.com/user-attachments/assets/d7df8925-edae-4fbb-b5f4-9269fe7ea9b9) | Partially fills in beer size for logging estimating macros by ABV | 8 | | [Log with ChatGPT](https://www.icloud.com/shortcuts/eda27d4da317499288de5815f26314c4) | ![Log with ChatGPT](https://github.com/user-attachments/assets/dff7268e-cb03-4f44-b541-9ee8c1cb7809) | Adds output formatting instructions for ChatGPT's shortcut | 9 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/img/modified-icon.efb2697d.svg: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/js/highlight-js-http-js.f78e83c2.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * This source file is part of the Swift.org open source project 3 | * 4 | * Copyright (c) 2021 Apple Inc. and the Swift project authors 5 | * Licensed under Apache License v2.0 with Runtime Library Exception 6 | * 7 | * See https://swift.org/LICENSE.txt for license information 8 | * See https://swift.org/CONTRIBUTORS.txt for Swift project authors 9 | */ 10 | (self["webpackChunkswift_docc_render"]=self["webpackChunkswift_docc_render"]||[]).push([[878],{8937:function(e){function n(e){const n=e.regex,a="HTTP/(2|1\\.[01])",s=/[A-Za-z][A-Za-z0-9-]*/,t={className:"attribute",begin:n.concat("^",s,"(?=\\:\\s)"),starts:{contains:[{className:"punctuation",begin:/: /,relevance:0,starts:{end:"$",relevance:0}}]}},i=[t,{begin:"\\n\\n",starts:{subLanguage:[],endsWithParent:!0}}];return{name:"HTTP",aliases:["https"],illegal:/\S/,contains:[{begin:"^(?="+a+" \\d{3})",end:/$/,contains:[{className:"meta",begin:a},{className:"number",begin:"\\b\\d{3}\\b"}],starts:{end:/\b\B/,illegal:/\S/,contains:i}},{begin:"(?=^[A-Z]+ (.*?) "+a+"$)",end:/$/,contains:[{className:"string",begin:" ",end:" ",excludeBegin:!0,excludeEnd:!0},{className:"meta",begin:a},{className:"keyword",begin:"[A-Z]+"}],starts:{end:/\b\B/,illegal:/\S/,contains:i}},e.inherit(t,{relevance:0})]}}e.exports=n}}]); -------------------------------------------------------------------------------- /Nutrition.doccarchive/favicon.svg: -------------------------------------------------------------------------------- 1 | 10 | 11 | -------------------------------------------------------------------------------- /Sources/Nutrition/Properties/NutritionalContent.swift: -------------------------------------------------------------------------------- 1 | import Foundation 2 | 3 | /// Encoding container for a JSON dictionary `[String: Decimal]`. Keys are the String raw value of ``Nutrition/Nutrient``. Values are in grams, unless [otherwise specified]() 4 | public struct NutritionalContent: Equatable, Sendable { 5 | 6 | @_documentation(visibility: internal) 7 | public var nutrients: [Nutrient: Decimal] 8 | 9 | @_documentation(visibility: internal) 10 | public init(_ nutrients: [Nutrient: Decimal]) { 11 | self.nutrients = nutrients 12 | } 13 | } 14 | 15 | extension NutritionalContent: Codable { 16 | 17 | /// Overrides Swift's default encoding (which would be key value pair tuples). 18 | public func encode(to encoder: Encoder) throws { 19 | var container = encoder.singleValueContainer() 20 | let nutrients = self.nutrients.reduce(into: [String: Decimal]()) { dict, element in 21 | dict[element.key.rawValue] = element.value 22 | } 23 | try container.encode(nutrients) 24 | } 25 | 26 | /// Decodes from Dictionary 27 | public init(from decoder: Decoder) throws { 28 | let container = try decoder.singleValueContainer() 29 | let rawValues = try container.decode([String: Decimal].self) 30 | self.nutrients = rawValues.reduce(into: [Nutrient: Decimal](), { dict, element in 31 | guard let nutrient = Nutrient(rawValue: element.key) else { return } 32 | dict[nutrient] = element.value 33 | }) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Nutrition.doccarchive/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/beverage/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/egg/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/fig/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/jar/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/nut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/oil/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pie/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/tea/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/nutrient/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/serving/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/!=(_:_:)/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/acorn/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/almond/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/apple/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/applered/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/avocado/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/babymilk/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/bacon/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/bagel/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/bananas/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/beanspan/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/biryani/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/biscotti/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/biscuit/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/broccoli/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/butter/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cabbage/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/calzone/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/candy/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/candybar/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/carrot/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cashews/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/celery/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/chard/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cherries/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/chestnut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/chicken/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cinnamon/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cocoa/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/coconut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/coffee/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/congee/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/corn/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/crab/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/creamer/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/croutons/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/cucumber/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/daikon/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/date/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/deer/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/dill/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/doughnut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/duck/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/eggplant/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/eggs/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/falafel/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/fish/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/garlic/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/ginger/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/gravy/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/guava/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/honey/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/hotdogs/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/hummus/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/jamred/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/jello/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/kefir/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/ketchup/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/kiwi/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lasagne/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lemon/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lentils/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lettuce/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lime/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lobster/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/lychee/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/mango/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/mayo/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/meatloaf/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/milk/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/milkrice/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/milksoy/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/mintgum/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/muffin/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/mushroom/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/mustard/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/oatmeal/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/octopus/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/omelette/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/onion/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/onionred/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/orange/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/oreos/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/oyster/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pancake/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/parsley/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/peach/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/peanut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pear/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pearbosc/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pecan/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pinenut/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/plum/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/popcorn/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/poptarts/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/porkloin/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/potato/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/potpie/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pretzel/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/prune/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/pumpkin/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/radishes/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/raisins/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/ravioli/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/rhubarb/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/ribs/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/ricecake/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/salami/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/salsa/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/sausage/index.html: -------------------------------------------------------------------------------- 1 | Documentation
-------------------------------------------------------------------------------- /Nutrition.doccarchive/documentation/nutrition/icon/scallops/index.html: -------------------------------------------------------------------------------- 1 | Documentation
--------------------------------------------------------------------------------