-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eaf1d0f
commit 52b0c9b
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |