0

I'm working on a SRS-based Flashcard program in swift. My problem (other than being new at programming, haha) is... once I alter the values of due date, score, etc; how do I add them back to the wordBank array keeping the new property values?

I started out creating a class for other flashcards to inherit properties like word, translation, sentence 1 & 2, audio URL, score (1-100 for scheduling purposes), etc; etc;

class Flashcard {
    var id: Int = 0
    var score: Int = 0
    var word: String = ""
    var sentence1: String = ""
// etc; etc;

From here, I created a new file and class called words, inheriting the Flashcard properties.

class Words: Flashcard {

    // Example word 1
    let you = Flashcard()
    you.id = 0
    you.score = 2
    you.word = "khun"
    you.sentence1 = "khun blah blah"

    // Example word 2
    let me = Flashcard()
    you.id = 1
    you.score = 1
    you.word = "pohm"
    you.translation = "Me or I"

    // Create an array of all the words that will be in the program
    var wordBank: [Flashcard] = [you, me, him, her, them, it] // etc;

Now, from here I can sort

// Sort array by lowest
wordBank.sort({ $1.score > $0.score })

// Create a new array for testing Session
var SessionArray: [Flashcard] = []

// Add the lowest scores to the SessionArray for testing
SessionArray += WordArray[0...6]

For the sake of remembering, My problem is once I alter the values of due date, score, etc; how do I add them back to the wordBank array keeping the new property values? I won't bother asking about how to persist this data right now, lol. I'm still reading about core data.

Thanks for any help you can give me!

  • It depends on how you alter the value. Include the code that alters the value. – Joe Smith Jun 17 '15 at 15:49
  • I took the code from the playground and put it into a project, but the code broke. Says that I cannot declare variables in top-level code. So I took the wordBank array and put it inside the AppDelegate.swift file but when I try to assign a value to (e.g. you.word = "khun") it says 'Expected Declaration'. I'll add code that will alter the values, but I have to fix this strange problem first. – Jeremy Mize Jun 18 '15 at 06:46

0 Answers0