我的类将所有属性都设置为动态但仍然从领域中检索它时我得到一个空对象的集合,并使用领域浏览器检查领域数据库并且数据在那里,这是我的类:
class ProjectEntity: Object {
/**
Property: All properties of the ProjectEntity
**/
dynamic var ProjectId = 0
dynamic var ProjectTitle = ""
dynamic var ProjectSubtitle = ""
dynamic var ProjectType = ""
dynamic var ProjectClass = ""
dynamic var ProjectCoordinates = ""
dynamic var ProjectGraphType = ""
dynamic var ProjectModifiedOn = NSDate(timeIntervalSince1970: 0)
dynamic var ProjectCity = ""
dynamic var ProjectCounty = ""
dynamic var ProjectZip = ""
override static func primaryKey() -> String? {
return "ProjectId"
}
func getShape() -> MapShape{
let adapter = ProjectsJSONAdapter()
let shape: MapShape = adapter.parseShape(id: self.ProjectId, type: self.ProjectGraphType, jsonStr: self.ProjectCoordinates)
return shape
}
}
以下是我如何阅读数据:
let projectsList = realm.objects(ProjectEntity)
for project in projectsList {
projects.append(project)//The properties in project have all their default/empty values
}
任何想法?
答案 0 :(得分:0)
首先你的类需要继承RLMObject:
class ProjectEntity: RLMObject {
...
}
如果您想要所有ProjectEntity对象,请尝试以下操作:
let allProjectEntityObjects: RLMResults = ProjectEntity.allObjects()
如果您需要一些额外的帮助,可以按照Realm的本教程进行操作: