<file_sep>//
//  adicionarCell.swift
//  iRemedy
//
//  Created by <NAME> on 13/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import Foundation
<file_sep>//
//  SobreACompraTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 17/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class SobreACompraTableViewCell: UITableViewCell {

    private var dataDeValidadeSelected: Date = Date()

    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    @IBOutlet weak var dataDeValidadeDatePicker: UIDatePicker!
    @IBAction func dataDeValidadeDatePicker(_ sender: Any) {
        dataDeValidadeSelected = dataDeValidadeDatePicker.date
    }
    
    @IBOutlet weak var precoTextField: UITextField!
    @IBAction func precoTextField(_ sender: Any) {

    }
    
    public func getDataDeValidadeSelected() -> Date{
        return dataDeValidadeSelected
    }
    
    public func getPrecoSelected() -> String{
        if let preco = precoTextField.text{
            return preco
        }
        return ""
    }
    
}
<file_sep>//
//  Remedio.swift
//  iRemedy
//
//  Created by <NAME> on 09/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import Foundation
import UIKit

class Remedio{
    
    internal init() {
        nome = ""
        photo = nil
        dosagem = ""
        comprimidos = ""
        horario = nil
        frequencia = nil
        contraindicacao = ""
        dataDeValidade = nil
        preco = ""
        sintomas = ""
        medida = ""
        hasPhoto = false
    }
    
    var nome : String
    var photo: UIImage?
    var dosagem: String
    var comprimidos: String
    var horario: Date?
    var frequencia: Date?
    var contraindicacao: String
    var dataDeValidade: Date?
    var preco: String
    var sintomas: String
    var medida: String
    var hasPhoto: Bool
}
<file_sep>//
//  HorarioTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 17/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class PeriodoTableViewCell: UITableViewCell  {

    private var horarioSelected: Date = Date()
    private var frequenciaSelected: Date = Date()

    @IBOutlet weak var horarioPickerView: UIDatePicker!
    @IBOutlet weak var frequenciaDatePicker: UIDatePicker!
    
    @IBAction func frequenciaDatePicker(_ sender: Any) {
        
        frequenciaSelected = frequenciaDatePicker.date
    }
    
    @IBAction func horarioPicker(_ sender: Any) {
        horarioSelected = horarioPickerView.date
    }  
    
    public func getFrequenciaSelected() -> Date{
        return frequenciaSelected
    }
    public func getHorarioSelected() -> Date{
        return horarioSelected
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    
    func periodoToString(){
        let formatter = DateFormatter()
        // initially set the format based on your datepicker date / server String
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let myString = formatter.string(from: frequenciaSelected) // string purpose I add here
        // convert your string to date
        let yourDate = formatter.date(from: myString)
        //then again set the date format whhich type of output you need
        formatter.dateFormat = "HH:mm"
        // again convert your date to string
        let myStringafd = formatter.string(from: yourDate!)
        
        print(myStringafd)
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }

    
}
<file_sep>//
//  CaixaDeRemediosViewController.swift
//  iRemedy
//
//  Created by <NAME> on 27/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class CaixaDeRemediosViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return Model.instance.allRemedios.count
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "RemedioTableViewCell", for: indexPath) as! RemedioTableViewCell
        let remedio = Model.instance.allRemedios[indexPath.row]
        let dosagemText = " " + remedio.dosagem + " " + remedio.medida
        cell.nomeDoRemedioLabel.text = remedio.nome
        cell.contraindicacoesLabel.text = cell.contraindicacoesLabel.text! + " " + remedio.contraindicacao
        cell.precoPagoLabel.text = cell.precoPagoLabel.text! + " " + remedio.preco
        cell.contraindicacoesLabel.text = cell.contraindicacoesLabel.text! + " " + remedio.contraindicacao
        cell.dosagemLabel.text = cell.dosagemLabel.text! + dosagemText
        cell.sintomasLabel.text = cell.sintomasLabel.text! + " " + remedio.sintomas
        if remedio.hasPhoto{
            cell.photoImageView.image = remedio.photo
        }
        if let dataDeValidade = remedio.dataDeValidade {
            cell.dataDeValidadeLabel.text = " " + Model.instance.dateToHHmmString(date: dataDeValidade)
        }
        return cell
    }
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    override func viewDidAppear(_ animated: Bool) {
        tableView.reloadData()
    }
    
    override func viewWillAppear(_ animated: Bool) {

    }
    @IBOutlet weak var tableView: UITableView!
}
<file_sep>//
//  AdicionarViewController.swift
//  iRemedy
//
//  Created by <NAME> on 09/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit
import UserNotifications

class AdicionarViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource{
    
    var appDelegate = UIApplication.shared.delegate as? AppDelegate
    
 
    var cell0: NameTableViewCell = NameTableViewCell()
    var cell1: DosagemTableViewCell = DosagemTableViewCell()
    var cell2: PeriodoTableViewCell = PeriodoTableViewCell()
    var cell3: SobreACompraTableViewCell = SobreACompraTableViewCell()
    var cell4: ObservacoesTableViewCell = ObservacoesTableViewCell()
    
    var nameTextField = UITextField()
    var cellIsOpened: [Bool] = []
    
    var keyboardIsShown: Bool = false
    
    var medidaValue: String = "mg"
    var dosagemValue: String = ""
    var comprimidosValue: Int = 0
    var frequenciaValue: Date = Date()
    var horarioValue: Date = Date()
    var dataDeValidadeValue: Date = Date()
    var precoValue: String = ""
    var sintomasValue: String = ""
    var contraindicacaoValue: String = ""
    
    var userSettedPhoto: Bool = false
    var photoButton: UIButton = UIButton.init()
    
    @IBOutlet weak var bottomConstraint: NSLayoutConstraint!
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if cellIsOpened[section] == true && section != 0{
            return 2;
        }else{
            return 1;
        }
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 5
    }
    
    @IBAction func adicionarRemedioButton(_ sender: Any) {
        let remedio: Remedio = Remedio()
        if let nome = cell0.nameTextField.text{
            remedio.nome = nome
            if userSettedPhoto == true{
                let cell = cell0
                remedio.photo = cell.cameraButton.imageView?.image
                remedio.hasPhoto = true
            }else{
                remedio.photo = nil
            }
            if cellIsOpened[1] == true{
                let cell = cell1
                if let dosagem = cell.dosagemTextField.text{
                    dosagemValue =  dosagem
                }
                remedio.dosagem = dosagemValue
                remedio.comprimidos = String(cell.comprimidosStepper.value)
                remedio.medida = cell.getMedidaEscolhida()
            }
            if cellIsOpened[2] == true{
                let cell = cell2
                
                remedio.frequencia = cell.getFrequenciaSelected()
                remedio.horario = cell.getHorarioSelected()
                
                cell.periodoToString()
                
                let homeRemedio = HomeRemedio(nome: remedio.nome, photo: remedio.photo, comprimidos: remedio.comprimidos, dosagem: remedio.dosagem, horario: remedio.horario, frequencia: remedio.frequencia)

                print(homeRemedio.dateToSeconds(date: remedio.frequencia!))
                
                homeRemedio.setHomeRemedio()
                Model.instance.savesHomeRemedioData()
            }
            if cellIsOpened[3] == true{
                let cell = cell3
                remedio.dataDeValidade = cell.getDataDeValidadeSelected()
                remedio.preco = cell.precoTextField.text!
            }
            
            if cellIsOpened[4] == true{
                let cell = cell4
                remedio.sintomas = cell.sintomasTextField.text!
                remedio.contraindicacao = cell.contraindicacaoTextField.text!
            }
            Model.instance.allRemedios.append(remedio)
            Model.instance.savesRemedioData()
        }
    }
    
    private func callFillDetails(){
        print("fill the details")
    }
    
    @IBAction func cameraButton(_ sender: Any) {
        if UIImagePickerController.isSourceTypeAvailable(.camera) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = .camera;
            imagePicker.allowsEditing = false
            self.present(imagePicker, animated: true, completion: nil)
        }
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if indexPath.section == 0{
            let cell = tableView.dequeueReusableCell(withIdentifier: "nameCell", for: indexPath) as! NameTableViewCell
            cell.transform = CGAffineTransform(rotationAngle: (-.pi))
            cell.nameTextField.text = nil

            cell0 = cell
            return cell
        }
        
        if cellIsOpened[indexPath.section] == true{
            if indexPath.row == 0{
                if  indexPath.section == 1 && indexPath.row == 0 {
                    let cell = tableView.dequeueReusableCell(withIdentifier: "DosagemTableViewCell", for: indexPath) as! DosagemTableViewCell
                    cell.transform = CGAffineTransform(rotationAngle: (-.pi))
                    
                    cell1 = cell
                    return cell
                }
                if   indexPath.section == 2 && indexPath.row == 0{
                    let cell = tableView.dequeueReusableCell(withIdentifier: "PeriodoTableViewCell", for: indexPath) as! PeriodoTableViewCell
                    cell.transform = CGAffineTransform(rotationAngle: (-.pi))
                    
                    cell2 = cell
                    return cell
                }
                if  indexPath.section == 3 && indexPath.row == 0{
                    let cell = tableView.dequeueReusableCell(withIdentifier: "SobreACompraTableViewCell", for: indexPath) as! SobreACompraTableViewCell
                    cell.transform = CGAffineTransform(rotationAngle: (-.pi))
                    
                    cell3 = cell
                    return cell
                }
                if  indexPath.section == 4 && indexPath.row == 0{
                    let cell = tableView.dequeueReusableCell(withIdentifier: "ObservacoesTableViewCell", for: indexPath) as! ObservacoesTableViewCell
                    cell.transform = CGAffineTransform(rotationAngle: (-.pi))
                    
                    cell4 = cell
                    return cell
                }
            }
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "expansibleCell", for: indexPath) as! TableViewCell
        let newImage = UIImage(named: "expansible\(indexPath.section)")
        cell.backgroundImageView?.image = newImage
        cell.backgroundImageView?.contentMode = .topLeft
        cell.backgroundImageView?.clipsToBounds = true
        cell.transform = CGAffineTransform(rotationAngle: (-.pi))
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if indexPath.section == 0{
            return 260
        }
        if cellIsOpened[indexPath.section] == true{
            if indexPath.row == 0{
                if indexPath.section == 1 || indexPath.section == 2{
                    return 123
                }
                if indexPath.section == 3{
                    return 203
                }
                if indexPath.section == 4{
                    return 214
                }
            }else{
                return 80;
            }
        } else if indexPath.row == 0{
            return 80
        }
        return 0;
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return CGFloat.leastNonzeroMagnitude
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return CGFloat.leastNonzeroMagnitude
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
        if keyboardIsShown {
            view.endEditing(true)
            keyboardIsShown = false
            return
        }
        if indexPath.section != 0{
            cellIsOpened[indexPath.section] = !cellIsOpened[indexPath.section]
            let section = IndexSet.init(integer: indexPath.section)
            tableView.reloadSections(section, with: .none)
        }
    }

    @IBOutlet weak var tableView: UITableView!
    
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
        let image = info[UIImagePickerController.InfoKey.originalImage] as! UIImage
        cell0.cameraButton.setImage(image, for: .normal)
        userSettedPhoto = true
        dismiss(animated:true, completion: nil)
    }
    
    
    public func callHomeViewController(){
        let vc = storyboard?.instantiateViewController(withIdentifier: "homeViewController")
        present(vc!, animated: true)
        self.navigationController?.pushViewController(vc!, animated: true)
    }
    
    private func checkIfHasUso(dosagem: String, comprimidos: String, horario: String, durante: String) -> Bool{
        if !(dosagem.isEmpty && comprimidos.isEmpty && horario.isEmpty && durante.isEmpty){
            return true
        }
        return false
    }
    
    override func viewDidLoad(){
        super.viewDidLoad()
        tableView.transform = CGAffineTransform(rotationAngle: (-.pi))

        cellIsOpened.append(true)
        for _ in 0...4{
            cellIsOpened.append(false)
        }
    }
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillDisappear), name: UIResponder.keyboardWillHideNotification, object: nil)
        NotificationCenter.default.addObserver(self, selector: #selector(keyboardWillAppear), name: UIResponder.keyboardWillShowNotification, object: nil)
    }
    
    @objc func keyboardWillAppear(notification: NSNotification) {
        guard let keyboardRect = (notification.userInfo?[UIResponder.keyboardFrameEndUserInfoKey] as? NSValue)?.cgRectValue else{
            return
        }
        
        keyboardIsShown = true
        bottomConstraint.constant = keyboardRect.height + 45
        view.layoutIfNeeded()
        print(keyboardIsShown)
    }
    
    @objc func keyboardWillDisappear() {
        keyboardIsShown = false
        bottomConstraint.constant = 45
        view.layoutIfNeeded()
        print(keyboardIsShown)
    }
    
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        NotificationCenter.default.removeObserver(self)
    }
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        view.endEditing(true)
        return false
    }
}
<file_sep>//
//  ViewController.swift
//  iRemedy
//
//  Created by <NAME> on 08/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit
import UserNotifications

class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
    let notifications = ["Local Notification",
                         "Local Notification with Action",
                         "Local Notification with Content",
                         "Push Notification with  APNs",
                         "Push Notification with Firebase",
                         "Push Notification with Content"]
    
    var appDelegate = UIApplication.shared.delegate as? AppDelegate
    @IBOutlet weak var homeCollectionView: UICollectionView!
    
    let DOSAGEM_SIZE_IN_LABELS = 3;
    let USO_SIZE_IN_LABELS = 2;
    let DETALHES_SIZE_IN_LABELS = 3;
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return Model.instance.homeRemedios.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let homeRemedio = Model.instance.homeRemedios[indexPath.row]
        let cell = homeCollectionView.dequeueReusableCell(withReuseIdentifier: "homeCell", for: indexPath) as! HomeCollectionViewCell
        cell.horarioLabel.text = homeRemedio.dateToHHmmString(date: homeRemedio.horario!)
        cell.nameLabel.text = homeRemedio.nome
        cell.quantidadeLabel.text = homeRemedio.comprimidos
        if homeRemedio.hasPhoto() == true{
            cell.remImageView.image = homeRemedio.photo
        }else{
            let image = UIImage(named: "Icon.png")
            cell.remImageView.image = image
        }
        return cell
    }
    
    func generatesArrayOfExistingData(remedio: Remedio) -> [String]{
        var numberOfProperValues: Int = 0;
        var arrayOfExistingData: [String] = []
        if !(remedio.dosagem == "") {
            arrayOfExistingData.append(remedio.dosagem)
            arrayOfExistingData.append(remedio.comprimidos)
            numberOfProperValues += DOSAGEM_SIZE_IN_LABELS
        }
        if !(remedio.contraindicacao == ""){
            arrayOfExistingData.append(remedio.contraindicacao);
            numberOfProperValues += DETALHES_SIZE_IN_LABELS;
        }
        if numberOfProperValues != 0{
            return arrayOfExistingData
        }else{
            return []
        }
    }
    override func viewDidLoad() {
        super.viewDidLoad()
        homeCollectionView.delegate = self
        homeCollectionView.delegate = self
        Model.instance.homeRemediosFromUserDefaults()
        Model.instance.allRemediosFromUserDefaults()
    }
    override func viewWillAppear(_ animated: Bool) {
        homeCollectionView.reloadData()
    }
    
    override func viewDidAppear(_ animated: Bool) {

        
    }
}

<file_sep>//
//  Model.swift
//  iRemedy
//
//  Created by <NAME> on 09/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import Foundation
import UIKit

class Model{
    
    private init(){}
    
    public static var instance = Model()
    
    public var allRemedios: [Remedio] = []
    
    public var homeRemedios: [HomeRemedio] = []
    

    
    
    public func savesHomeRemedioData(){
        var nomeArray: [String?] = []
        var photoArray: [String] = []
        var dosagemArray: [String?] = []
        var comprimidosArray: [String?] = []
        var horarioArray: [String] = []
        var frequenciaArray: [String] = []
        
        for remedio in homeRemedios{
            nomeArray.append(remedio.nome)
            dosagemArray.append(remedio.dosagem)
            comprimidosArray.append(remedio.comprimidos)
            if remedio.photo == nil{
                photoArray.append("")
            }else{
                photoArray.append(convertImageToBase64(image: remedio.photo!))
            }
            if remedio.frequencia == nil{
                frequenciaArray.append("")
            }else{
                frequenciaArray.append(remedio.dateToHHmmString(date: remedio.frequencia!))
            }
            if remedio.horario == nil{
                horarioArray.append("")
            }else{
                horarioArray.append(remedio.dateToHHmmString(date: remedio.horario!))
            }
            
        }
        let defaults = UserDefaults.standard
        defaults.set(nomeArray, forKey: "homeRemedioNomeArray")
        defaults.set(dosagemArray, forKey: "homeRemedioDosagemArray")
        defaults.set(comprimidosArray, forKey: "homeRemedioComprimidosArray")
        defaults.set(horarioArray, forKey: "homeRemedioHorarioArray")
        defaults.set(frequenciaArray, forKey: "homeRemedioFrequenciaArray")
        defaults.set(photoArray, forKey: "homeRemedioPhotoArray")
    }
    
    public func homeRemediosFromUserDefaults(){
        let defaults = UserDefaults.standard
        let nomeArray = defaults.stringArray(forKey: "homeRemedioNomeArray") ?? [String]()
        let dosagemArray = defaults.stringArray(forKey: "homeRemedioDosagemArray") ?? [String]()
        let comprimidosArray = defaults.stringArray(forKey: "homeRemedioComprimidosArray") ?? [String]()
        let horarioArray = defaults.stringArray(forKey: "homeRemedioHorarioArray") ?? [String]()
        let frequenciaArray = defaults.stringArray(forKey: "homeRemedioFrequenciaArray") ?? [String]()
        let photosArray = defaults.stringArray(forKey: "homeRemedioPhotoArray") ?? [String]()
        
        
        if nomeArray.count > 0{
            for i in 0..<nomeArray.count{
                let image = convertBase64ToImage(imageString: photosArray[0])
                let remedio: HomeRemedio = HomeRemedio(nome: nomeArray[i], photo: image, comprimidos: comprimidosArray[i], dosagem: dosagemArray[i], horario: stringToDate(string: horarioArray[i]), frequencia: stringToDate(string: frequenciaArray[i]))
                Model.instance.homeRemedios.append(remedio)
            }
        }
    }
    public func savesRemedioData(){
        var nomeArray: [String] = []
        var photoArray: [String] = []
        var dosagemArray: [String] = []
        var comprimidosArray: [String] = []
        var horarioArray: [String] = []
        var frequenciaArray: [String] = []
        var contraindicacaoArray: [String] = []
        var dataDeValidade: [String] = []
        var precoArray: [String] = []
        var sintomasArray: [String] = []
        var medidaArray: [String] = []
        var hasPhotoArray: [Bool] = []
        
        for remedio in allRemedios{
            nomeArray.append(remedio.nome)
            dosagemArray.append(remedio.dosagem)
            comprimidosArray.append(remedio.comprimidos)
            contraindicacaoArray.append(remedio.contraindicacao)
            precoArray.append(remedio.preco)
            sintomasArray.append(remedio.sintomas)
            medidaArray.append(remedio.medida)
            hasPhotoArray.append(remedio.hasPhoto)
            
            if remedio.horario == nil{
                horarioArray.append("")
            }else{
                horarioArray.append(dateToHHmmString(date: remedio.horario!))
            }
            if remedio.frequencia == nil{
                frequenciaArray.append("")
            }else{
                frequenciaArray.append(dateToHHmmString(date: remedio.frequencia!))
            }
            if remedio.photo == nil{
                photoArray.append("")
            }else{
                photoArray.append(convertImageToBase64(image: remedio.photo!))
            }
        }
        let defaults = UserDefaults.standard
        defaults.set(nomeArray, forKey: "allRemedioNomeArray")
        defaults.set(dosagemArray, forKey: "allRemedioDosagemArray")
        defaults.set(comprimidosArray, forKey: "allRemedioComprimidosArray")
        defaults.set(horarioArray, forKey: "allRemedioHorarioArray")
        defaults.set(frequenciaArray, forKey: "allRemedioFrequenciaArray")
        defaults.set(contraindicacaoArray, forKey: "allRemedioContraindicacaoArray")
        defaults.set(precoArray, forKey: "allRemedioPrecoArray")
        defaults.set(sintomasArray, forKey: "allRemedioSintomasArray")
        defaults.set(medidaArray, forKey: "allRemedioMedidaArray")
        defaults.set(hasPhotoArray, forKey: "allRemedioHasPhotoArray")
        defaults.set(photoArray, forKey: "homeRemedioPhotoArray")
        
    }
    
    public func allRemediosFromUserDefaults(){
        let defaults = UserDefaults.standard
        let nomeArray = defaults.stringArray(forKey: "allRemedioNomeArray") ?? [String]()
        let dosagemArray = defaults.stringArray(forKey: "allRemedioDosagemArray") ?? [String]()
        let comprimidosArray = defaults.stringArray(forKey: "allRemedioComprimidosArray") ?? [String]()
        let horarioArray = defaults.stringArray(forKey: "allRemedioHorarioArray") ?? [String]()
        let frequenciaArray = defaults.stringArray(forKey: "allRemedioFrequenciaArray") ?? [String]()
        let contraindicacaoArray = defaults.stringArray(forKey: "allRemedioContraindicacaoArray") ?? [String]()
        let precoArray = defaults.stringArray(forKey: "allRemedioPrecoArray") ?? [String]()
        let sintomasArray = defaults.stringArray(forKey: "allRemedioSintomasArray") ?? [String]()
        let medidaArray = defaults.stringArray(forKey: "allRemedioMedidaArray") ?? [String]()
        let hasPhotoArray: [Bool] = defaults.array(forKey: "allRemedioHasPhotoArray") as? [Bool] ?? [Bool]()
        let photosArray = defaults.stringArray(forKey: "homeRemedioPhotoArray") ?? [String]()
        
        for i in 0..<nomeArray.count{
            let remedio: Remedio = Remedio()
            remedio.comprimidos = comprimidosArray[i]
            remedio.nome = nomeArray[i]
            remedio.dosagem = dosagemArray[i]
            remedio.horario = stringToDate(string: horarioArray[i])
            remedio.frequencia = stringToDate(string: frequenciaArray[i])
            remedio.contraindicacao = contraindicacaoArray[i]
            remedio.preco = precoArray[i]
            remedio.sintomas = sintomasArray[i]
            remedio.medida = medidaArray[i]
            remedio.hasPhoto = hasPhotoArray[i]
            remedio.photo = convertBase64ToImage(imageString: photosArray[i])
            
            allRemedios.append(remedio)
        }
    }
    
    public func stringToDate(string: String) -> Date?{
        if string == ""{
            return nil
        }
        let formatter = DateFormatter()
        formatter.dateFormat = "HH:mm"
        let yourDate = formatter.date(from: string)
        return yourDate!
    }
    func dateToHHmmString(date: Date) -> String{
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let myString = formatter.string(from: date)
        let yourDate = formatter.date(from: myString)
        formatter.dateFormat = "HH:mm"
        let myStringafd = formatter.string(from: yourDate!)
        return myStringafd
    }
    
    func convertImageToBase64(image: UIImage?) -> String {
        if image == nil{
            return ""
        }
        let imageData = image!.pngData()!
        return imageData.base64EncodedString(options: Data.Base64EncodingOptions.lineLength64Characters)
    }
    

    func convertBase64ToImage(imageString: String) -> UIImage? {
        if imageString == ""{
            return nil
        }
        let imageData = Data(base64Encoded: imageString, options: Data.Base64DecodingOptions.ignoreUnknownCharacters)!
        return UIImage(data: imageData)!
    }
}
<file_sep>//
//  TableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 13/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class TableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
    @IBOutlet weak var backgroundImageView: UIImageView!
    
}
<file_sep>//
//  HomeCollectionViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 09/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class HomeCollectionViewCell: UICollectionViewCell {
    
    @IBOutlet weak var remImageView: UIImageView!
    

    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var quantidadeLabel: UILabel!
    
    @IBOutlet weak var horarioLabel: UILabel!


}
<file_sep>//
//  NameTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 13/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class NameTableViewCell: UITableViewCell {

    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        nameQuestionTitle.text = "Nome do remédio"
        nameQuestionSubtilte.text = "(maior nome escrito na caixa)"
        
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    @IBOutlet weak var cameraButton: UIButton!
    @IBOutlet weak var nameTextField: UITextField!
    @IBOutlet weak var nameQuestionSubtilte: UILabel!
    @IBOutlet weak var nameQuestionTitle: UILabel!
}
<file_sep>//
//  ObservacoesTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 17/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class ObservacoesTableViewCell: UITableViewCell {

    
    private var sintomasSelected: String = ""
    private var contraindicacaoSelected: String = ""
    
    override func awakeFromNib() {
        super.awakeFromNib()
    }
    
    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        
        // Configure the view for the selected state
    }
    
    @IBOutlet weak var sintomasTextField: UITextField!
    @IBOutlet weak var contraindicacaoTextField: UITextField!

    @IBAction func contraindicacaoTextField(_ sender: Any) {
        print("entrou no contra")
        if let chosenText = contraindicacaoTextField.text{
            contraindicacaoSelected = chosenText
        }else{
            contraindicacaoSelected = ""
        }
    }
    @IBAction func sintomasTextField(_ sender: Any) {
        print("entrou no sint")
        if let chosenText = sintomasTextField.text{
            sintomasSelected = chosenText
        }else{
            sintomasSelected = ""
        }
    }
    
    public func getSintomasSelected() -> String{
        return sintomasSelected
    }
    public func getContraindicacoesSelected() -> String{
        return contraindicacaoSelected
    }
    

}
<file_sep>//
//  File.swift
//  iRemedy
//
//  Created by <NAME> on 09/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import Foundation
<file_sep>//
//  DosagemTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 14/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class DosagemTableViewCell: UITableViewCell, UIPickerViewDataSource, UIPickerViewDelegate {

    @IBOutlet weak var dosagemTextField: UITextField!
    @IBOutlet weak var pickerView: UIPickerView!
    @IBOutlet weak var comprimidosStepper: UIStepper!
    @IBOutlet weak var numeroDeComprimidosLabel: UILabel!
    
    let medidasOptions: [String] = ["mg", "g", "µg"]
    static var medidasSelected: String = ""
    static var dosagemSelected: String = ""
    static var comprimidosSelected: Int = 0
    
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return medidasOptions.count
    }
    
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return medidasOptions[row]
    }
    
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        DosagemTableViewCell.medidasSelected = medidasOptions[row]
    }
    
    public func getMedidaEscolhida() -> String{
        return DosagemTableViewCell.medidasSelected
    }

    @IBAction func dosagemTextField(_ sender: Any) {
        print("entrou no dosagem")
        if let dosagem = dosagemTextField.text{
            DosagemTableViewCell.dosagemSelected = dosagem
        }
    }
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
        
        
        pickerView.delegate = self
        pickerView.dataSource = self
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
    }
    
    @IBAction func stepperPressed(_ sender: Any) {
        DosagemTableViewCell.comprimidosSelected = Int(comprimidosStepper.value)
        numeroDeComprimidosLabel.text = String(DosagemTableViewCell.comprimidosSelected)
    }
    
    

}
<file_sep>//
//  remedios.swift
//  iRemedy
//
//  Created by <NAME> on 12/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import Foundation
import UIKit
class HomeRemedio{
    var appDelegate = UIApplication.shared.delegate as? AppDelegate
    
    internal init(nome: String?, photo: UIImage?, comprimidos: String?, dosagem: String?, horario: Date?, frequencia: Date?) {
        
        self.nome = nome
        self.photo = photo
        self.dosagem = dosagem
        self.comprimidos = comprimidos
        self.horario = horario
        self.frequencia = frequencia
    }
    
    var nome: String?
    var photo: UIImage?
    var dosagem: String?
    var comprimidos: String?
    var horario: Date?
    var frequencia: Date?
    
    public func hasPhoto() -> Bool{
        if photo == nil{
            return false
        }
        return true
    }
    
    func dateToHHmmString(date: Date) -> String{
        let formatter = DateFormatter()
        // initially set the format based on your datepicker date / server String
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let myString = formatter.string(from: date) // string purpose I add here
        // convert your string to date
        let yourDate = formatter.date(from: myString)
        //then again set the date format whhich type of output you need
        formatter.dateFormat = "HH:mm"
        // again convert your date to string
        let myStringafd = formatter.string(from: yourDate!)
        
        return myStringafd
    }
    
    public func dateToSeconds(date: Date) -> Int{
        let formatter = DateFormatter()
        // initially set the format based on your datepicker date / server String
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let myString = formatter.string(from: date) // string purpose I add here
        // convert your string to date
        let yourDate = formatter.date(from: myString)
        //then again set the date format whhich type of output you need
        formatter.dateFormat = "mm"
        // again convert your date to string
        let myStringafd = formatter.string(from: yourDate!)
        
        let asInt = Int(myStringafd)! * 60 + hoursToSeconds(date: date)
        
        return asInt
    }
    

    
    private func hoursToSeconds(date: Date) -> Int{
        let formatter = DateFormatter()
        // initially set the format based on your datepicker date / server String
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        
        let myString = formatter.string(from: date) // string purpose I add here
        // convert your string to date
        let yourDate = formatter.date(from: myString)
        //then again set the date format whhich type of output you need
        formatter.dateFormat = "HH"
        // again convert your date to string
        let myStringafd = formatter.string(from: yourDate!)
        
        let asInt = Int(myStringafd)! * 3600
        
        return asInt
    }
    
    public func setHomeRemedio(){
        Model.instance.homeRemedios.append(self)
        setNotifications(remedio: self)
    }
    
    private func setNotifications(remedio: HomeRemedio){
        
        var notificationDate: Date = remedio.horario!
        let notificationFrequencia: Double = Double(remedio.dateToSeconds(date: remedio.frequencia!))
        
        let iterations: Int = Int((24*60*60)/Double(notificationFrequencia))
        
        for i in 0...iterations{
            if i < 10{
                self.appDelegate?.scheduleNotification(remedio: remedio, notificationDate: notificationDate, iteration: i)
                notificationDate = Date(timeInterval: notificationFrequencia, since: notificationDate)
            }
        }
    }
}
<file_sep>//
//  RemedioTableViewCell.swift
//  iRemedy
//
//  Created by <NAME> on 27/06/19.
//  Copyright © 2019 <NAME>. All rights reserved.
//

import UIKit

class RemedioTableViewCell: UITableViewCell {

    @IBOutlet weak var nomeDoRemedioLabel: UILabel!
    @IBOutlet weak var dosagemLabel: UILabel!
    @IBOutlet weak var dataDeValidadeLabel: UILabel!
    @IBOutlet weak var precoPagoLabel: UILabel!
    @IBOutlet weak var contraindicacoesLabel: UILabel!
    @IBOutlet weak var sintomasLabel: UILabel!
    @IBOutlet weak var photoImageView: UIImageView!
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

}
