Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. init() {
  2. // Get a reference to the file path
  3. let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
  4. let documentDirectory = paths.first!
  5.  
  6. filePath = "\(documentDirectory)/flashcards.plist"
  7.  
  8. if let flashcardDictionaries = NSArray(contentsOfFile: filePath) as? [[String: String]]{
  9. // Converting an array of dictionaries to an array of Quotes
  10. flashcards = [Flashcard]()
  11.  
  12. for flashcardDictionary in flashcardDictionaries {
  13. let flashcard = Flashcard(question: flashcardDictionary[kQuestionKey]!, answer: flashcardDictionary[kAnswerKey]!)
  14. flashcards.append(flashcard)
  15. }
  16. // Else pre-populate our quotes array
  17. } else {
  18. 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 :(")
  19. 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/")
  20. 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!")
  21. let flashcardFour = Flashcard(question: "Have you ever heard of an up dog?", answer: "I hope you answered 'No, what's up dog?'")
  22. let flashcardFive = Flashcard(question: "Are you tired?", answer: "Well you've been running through my mind all day!")
  23. flashcards = Array()
  24. flashcards.append(flashcardOne)
  25. flashcards.append(flashcardTwo)
  26. flashcards.append(flashcardThree)
  27. flashcards.append(flashcardFour)
  28. flashcards.append(flashcardFive)
  29. }
  30. currentIndex = 0
  31. }
  32.  
  33.  
  34.  
  35. func save() {
  36. (flashcardsDictionary as NSArray).write(toFile: filePath, atomically: true)
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement