Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- init() {
- // Get a reference to the file path
- let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
- let documentDirectory = paths.first!
- filePath = "\(documentDirectory)/flashcards.plist"
- if let flashcardDictionaries = NSArray(contentsOfFile: filePath) as? [[String: String]]{
- // Converting an array of dictionaries to an array of Quotes
- flashcards = [Flashcard]()
- for flashcardDictionary in flashcardDictionaries {
- let flashcard = Flashcard(question: flashcardDictionary[kQuestionKey]!, answer: flashcardDictionary[kAnswerKey]!)
- flashcards.append(flashcard)
- }
- // Else pre-populate our quotes array
- } else {
- let flashcardOne = Flashcard(question: "Is a hot dog a sandwich?", answer: "Yes it is and anyone who thinks otherwise is not a true hot dog lover :(")
- let flashcardTwo = Flashcard(question: "Does a straw have one or two holes?", answer: "One! If you're having problems wrapping your head around this one, check out https://mindyourdecisions.com/blog/2018/02/19/how-many-holes-does-a-straw-have-the-correct-answer-explained-mathematically/")
- let flashcardThree = Flashcard(question: "How does global warming benefit us?", answer: "We already know that the earth is flat. But if it were truly flat, then all the water would just fall off the sides. So it has to be a bowl! Now global warming raises sea levels and melts the polar ice caps. This makes the water fall off the sides of the bowl. Now think about this: when's the last time space has ever had a drop of water? NEVER! So global warming solves space dehydration!")
- let flashcardFour = Flashcard(question: "Have you ever heard of an up dog?", answer: "I hope you answered 'No, what's up dog?'")
- let flashcardFive = Flashcard(question: "Are you tired?", answer: "Well you've been running through my mind all day!")
- flashcards = Array()
- flashcards.append(flashcardOne)
- flashcards.append(flashcardTwo)
- flashcards.append(flashcardThree)
- flashcards.append(flashcardFour)
- flashcards.append(flashcardFive)
- }
- currentIndex = 0
- }
- func save() {
- (flashcardsDictionary as NSArray).write(toFile: filePath, atomically: true)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement