0

I have created my app, I have all my data inside a object of a class, this is the class:

class ClaseContenedora {
    var calendarios = [Calendario]()
    var seleccionados = ValoresDeSeleccionados()
    var valoresConfiguracion = OpcionesConfiguracion()

    init(cal: [Calendario], selected: ValoresDeSeleccionados, config: OpcionesConfiguracion) {
        self.calendarios = cal
        self.seleccionados = selected
        self.valoresConfiguracion = config
    }
}

as you can see, I have and array of another class and 2 objects of other classes. These are the 2 last clases:

class ValoresDeSeleccionados {
    var calendarioSeleccionado = 0
    var seccionSeleccionada = 0
    var asistenciaSeleccionada = 0
    var actividadSeleccionada = 0
    var alumnoSeleccionado = 0
}

and:

class OpcionesConfiguracion {
    var setColores = true // -> Colores de Interfaz (TRUE = GRISES, FALSE = COLORES PASTEL)

    var defaultCalificacion = 100  // -> Default al agregar una nueva Actividad o dia de clases(asistencia)
    var defaultAsistencia = true  //  ->

    var defaultCalificacionNuevoAlumno = 100 // ->  Default al agregar un alumno y que ya haya clases con asistencia o actividades realizadas
    var defaultAsistenciaNuevoAlumno = true  // ->

    var ordenarAlumnosPorOrdenAlfabetico = false

    var asistenciasPorDiaClaseUnDia = 2
    var asistenciaPorDiaClaseVariosDias = 1

    var minimoPorcentajeOrdinario = 80
    var resaltarAlumnosOrdinario = false
}

how can I save all this data 'permanently' I mean, that I could close the app, and continue later with the data I have created in the app?

I have tried some of this: http://nshipster.com/nscoding/ But every tutorial I have seen uses Int, String, Bool, not arrays or objects.

EDIT: This is the Calendario class:

class Calendario { // CLASE PRINCIPAL QUE CONTIENE 'SECCIONES'.
    var secciones = [Seccion]()

    var nombre: String
    var inicio: Date
    var fin: Date

    init?(nombre:String, inicio:Date, fin:Date) {

        //GUARD ES IGUAL A UN IF QUE SE CUMPLE, SI NO, ESTA EL ELSE.
        guard (!nombre.isEmpty) else {
           return nil
        }

        self.nombre = nombre
        self.inicio = inicio
        self.fin = fin
        }
}
  • Have you tried any database, something like https://firebase.google.com ? – xsami May 24 '17 at 18:25
  • You can try using `UserDefaults` See [this answer](https://stackoverflow.com/questions/2315948/how-to-store-custom-objects-in-nsuserdefaults) – synndicate May 24 '17 at 18:31
  • https://realm.io/docs/swift/latest/ try this its simple – Matloob Hasnain May 24 '17 at 18:32
  • U can use UserDefaults for it and u can save custom objects to UserDefaults via NSCoding protocol! – hament miglani May 24 '17 at 18:36
  • It is explained for arbitrary objects in the [official Swift tutorial](https://developer.apple.com/library/content/referencelibrary/GettingStarted/DevelopiOSAppsSwift/PersistData.html#//apple_ref/doc/uid/TP40015214-CH14-SW1). – Max May 24 '17 at 19:43
  • I have done the official Swift tutorial, and it doesn't work, I think it's because my object have an array of objects inside, but idk, I'll try the other's suggestion, Thank you :D – Martin Hernandez Perez May 24 '17 at 21:07
  • You need to show also your `Calendario` class – Leo Dabus May 25 '17 at 03:06

0 Answers0