始终保存最后一个对象

时间:2017-06-16 13:08:16

标签: ios swift object for-loop core-data

我希望将对象数组保存到coreData中,但是当我使用storeWord()方法时,它总是只存放在最后一个对象的数组中,而我想把对象数组存入,但是我不知道有什么问题,有人可以帮帮我吗?谢谢

这是我的objectArray:

{
  "type": "Feature",
  "geometry": {
    "type": "LineString",
    "coordinates": [[10 thousand points]...]
  },
  "properties": {
    "name": "Dinagat Islands"
  }
}

空的CoreData数组:

var wordArray:[Word] = [
    Word(word: "abacus", pronounce: "ˋæbəkəs", translate: "算盤", image: "abacus.jpg", visited: false),
    Word(word: "abbey", pronounce: "ˋæbɪ", translate: "修道院", image: "abbey.jpg", visited: false),
    Word(word: "ache", pronounce: "ek", translate: "痛", image: "ache.jpg", visited: false)
]

选择并存储功能:

var words:[WordMO] = []

1 个答案:

答案 0 :(得分:1)

移动

var word:WordMO!
word = WordMO(context: getContext())

进入你的for循环