Skip to content

Commit

Permalink
Create Meal data model
Browse files Browse the repository at this point in the history
  • Loading branch information
DipanshKhandelwal committed Oct 20, 2019
1 parent eaf1d0f commit 52b0c9b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions food-tracker-app.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
0B04A69F235B7233006E556A /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0B04A69E235B7233006E556A /* Assets.xcassets */; };
0B04A6A2235B7233006E556A /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0B04A6A0235B7233006E556A /* LaunchScreen.storyboard */; };
0B99E20A235C23FA00EAD6EA /* RatingControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B99E209235C23FA00EAD6EA /* RatingControl.swift */; };
0B99E20C235C326200EAD6EA /* Meal.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B99E20B235C326200EAD6EA /* Meal.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -26,6 +27,7 @@
0B04A6A1235B7233006E556A /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
0B04A6A3235B7233006E556A /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0B99E209235C23FA00EAD6EA /* RatingControl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RatingControl.swift; sourceTree = "<group>"; };
0B99E20B235C326200EAD6EA /* Meal.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Meal.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -62,6 +64,7 @@
0B04A697235B7232006E556A /* SceneDelegate.swift */,
0B04A699235B7232006E556A /* ViewController.swift */,
0B04A69B235B7232006E556A /* Main.storyboard */,
0B99E20B235C326200EAD6EA /* Meal.swift */,
0B04A69E235B7233006E556A /* Assets.xcassets */,
0B99E209235C23FA00EAD6EA /* RatingControl.swift */,
0B04A6A0235B7233006E556A /* LaunchScreen.storyboard */,
Expand Down Expand Up @@ -141,6 +144,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
0B99E20C235C326200EAD6EA /* Meal.swift in Sources */,
0B99E20A235C23FA00EAD6EA /* RatingControl.swift in Sources */,
0B04A69A235B7232006E556A /* ViewController.swift in Sources */,
0B04A696235B7232006E556A /* AppDelegate.swift in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions food-tracker-app/Meal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// Meal.swift
// food-tracker-app
//
// Created by Dipansh Khandelwal on 20/10/19.
// Copyright © 2019 DipanshKhandelwal. All rights reserved.
//

import UIKit

class Meal {
//MARK: Initialization
init?(name: String, photo: UIImage?, rating: Int) {
// Initialization should fail if there is no name or if the rating is negative.
// The name must not be empty
guard !name.isEmpty else {
return nil
}

// The rating must be between 0 and 5 inclusively
guard (rating >= 0) && (rating <= 5) else {
return nil
}

// Initialize stored properties.
self.name = name
self.photo = photo
self.rating = rating
}

//MARK: Properties
var name: String
var photo: UIImage?
var rating: Int
}

0 comments on commit 52b0c9b

Please sign in to comment.