I’m doing an app to track livestock and I’m using more or less the same type of model as the Journal app. I just referenced the video and I see where I have to create a new Note (or in this case a new Animal) by saying: let n = animal(animalID = UUID, animalName = animalNameText.text, etc…
My question is - in lessons past it seems like the format for setting properties is like I have laid out below. So I am confused as to what the practical difference is in the code above versus the code below. The code below doesn’t work - the Animal object still is nil afterward.
@IBAction func saveNoteButton(_ sender: Any) {
print ("Button pushed")
//need an if statement in here if animal.indexpath.row is nil... then set a value to a
//also create the unique identifier field
if animal == nil {
print ("This is a blank animal record. need to save what's in the fields.")
animal?.animalName = animalNameText.text!
animal?.animalType = animalTypeText.text!
animal?.dateBirth = dobText.text!
animal?.animalDescription = descriptionText.text!
animal?.dateAquired = dateAquiredText.text!
animal?.dam = damText.text!
animal?.sire = sireText.text!
animal?.sex = sexText.text!
animal?.notes = notesText.text!
animal?.weenDate = weenDateText.text!
animal?.animalBreed = breedText.text!
animal?.animalID = "123445"
}
print (animal!)
saveNote(a: animal!)
}