Quick actions

cmd+k|ctrl+k

Navigation

Languages

SRP

Snippet info

Language

Swift

Visibility

public

Author

alfian

Created

2020-06-03T06:47:45Z

Updated

2020-06-03T06:48:39Z

import Foundation
 
class FoodService{
    private var _id: Int
    private var _name: String
    private var _date: String
    
    init(id: Int, name: String, date: String) {
        _id = id
        _name = name
        _date = date
    }
    
    func addToStore() {
        if (!isExpired()) {
            //Add to store
        }
    }
    
    private func isExpired() -> Bool {
        var foodDate = NSDate()
        let now = NSDate()
        let dateFormater = DateFormatter()
        dateFormater.dateFormat = "yyyy-mm-dd"
        
        foodDate = dateFormater.date(from: _date)! as NSDate
        
        return foodDate.compare(now as Date) == ComparisonResult.orderedDescending
    }
}
INFO