以下代码是否适合这样做?它必须适用于tableView,虽然我想确保这不是使用Realm.framework的糟糕实现。我将以下列方式访问数据(作为示例):
var goalList = Goals()
self.textField.text = goalList.goals[indexPath.row]
Goal.swift
import UIKit
import Realm
class Goal: RLMObject {
dynamic var title = ""
dynamic var checkmarked = false
dynamic var disabled = false
dynamic var isLastInList = false
}
Goals.swift
import UIKit
import Realm
class Goals: RLMObject {
dynamic var goals = RLMArray(objectClassName: Goal.className())
}
答案 0 :(得分:1)
Goal.swift很完美。但是你不需要Goals.swift。 如果您看一下下载包中提供的简单示例,该示例应该向您展示您需要的内容。
答案 1 :(得分:1)
let goalList = Goal.allObjects() //This returns an array of goals
let goal = goalList[indexPath.row] // Returns a goal object
self.textField.text = goal.title