私のアプリでは、レルムを使用してデータを保存および取得しています。ここに私のAPIの結果です。この値を領域データベースに格納する必要があります。iOS Swift 3値をレルムに保存
{
"cc": [
{
"id": 142,
"firm": 2,
"specialization_id": 2,
"specialization_name": "Alternative",
"number": "234",
"title": "Push test",
"ear": "2012",
"description": "",
"status": "Open",
"open_date": "2017-05-22",
"close_date": null,
"closing_comments": null,
"type_id": 99,
"type_name": "Tax Reference",
"record_id": 57,
"record_name": "Court of India",
"type": "Court",
"other_party": [],
"billing_type": "Retainer",
"applicants": [
{
"type": "Contact",
"id": 31816,
"name": "1.Mrs V.Dhanalakshmi & Another",
"email": null,
"firm_id": 2,
"company_id": null,
"has_portal_access": false,
"mobile_number": null,
"street_address": null,
"locality": null,
"city": null,
"state": null,
"postal_code": null,
"landmark": null
}
],
}
]
}
問題は、私はできid,firm, specialisation_id,etc,.
のように親の値を格納することができます。しかし、私はできませんapplicants
細部のような値を格納することです。ここに私の試したコードです:
import UIKit
import RealmSwift
import Realm
import ObjectMapper
class CaseResponseData: Mappable
{
var data:[CaseAreaEntity]?
//Impl. of Mappable protocol
required convenience init?(map: Map)
{
self.init()
}
func mapping(map: Map)
{
data <- map["court_case"]
}
}
//Case Details
class CaseAreaEntity:Object, Mappable
{
dynamic var id = 0
dynamic var firm_id = 0
dynamic var specialization_id = 0
dynamic var specialization_name = ""
dynamic var number = ""
dynamic var title = ""
dynamic var case_year = ""
dynamic var description2 = ""
dynamic var status = ""
dynamic var open_date = ""
dynamic var close_date = ""
dynamic var closing_comments = ""
dynamic var case_type_id = 0
dynamic var case_type_name = ""
dynamic var court_record_id = 0
dynamic var court_record_name = ""
dynamic var court_type = ""
dynamic var client_type = ""
dynamic var billing_type = ""
dynamic var referred_by = ""
var applicants = List<ApplicantsEntity>()
//Impl. of Mappable protocol
required convenience init?(map: Map)
{
self.init()
}
override static func primaryKey() -> String?
{
return "id"
}
func mapping(map: Map)
{
id <- map["id"]
firm_id <- map["firm_id"]
specialization_id <- map["specialization_id"]
specialization_name <- map["specialization_name"]
number <- map["number"]
title <- map["title"]
case_year <- map["case_year"]
description2 <- map["description"]
status <- map["status"]
open_date <- map["open_date"]
close_date <- map["close_date"]
closing_comments <- map["closing_comments"]
case_type_id <- map["case_type_id"]
case_type_name <- map["case_type_name"]
court_record_id <- map["court_record_id"]
court_record_name <- map["court_record_name"]
court_type <- map["court_type"]
client_type <- map["client_type"]
billing_type <- map["billing_type"]
referred_by <- map["referred_by"]
applicants <- map["applicants"]
}
}
//Applicants Details
class ApplicantsEntity: Object,Mappable
{
dynamic var applicant_id = 0
dynamic var applicantable_type = ""
dynamic var id = 0
dynamic var name = ""
dynamic var first_name = ""
dynamic var last_name = ""
dynamic var email = ""
dynamic var firm_id = 0
dynamic var company_id = 0
dynamic var has_portal_access = Bool()
dynamic var mobile_number = ""
dynamic var phone_number = ""
dynamic var fax = ""
dynamic var website = ""
dynamic var street_address = ""
dynamic var locality = ""
dynamic var city = ""
dynamic var state = ""
dynamic var postal_code = ""
dynamic var landmark = ""
//Impl. of Mappable protocol
required convenience init?(map: Map)
{
self.init()
}
override static func primaryKey() -> String?
{
return "id"
}
func mapping(map: Map)
{
applicant_id <- map["applicant_id"]
applicantable_type <- map["applicantable_type"]
id <- map["id"]
name <- map["name"]
first_name <- map["first_name"]
last_name <- map["last_name"]
email <- map["email"]
firm_id <- map["firm_id"]
company_id <- map["company_id"]
has_portal_access <- map["has_portal_access"]
mobile_number <- map["mobile_number"]
phone_number <- map["phone_number"]
fax <- map["fax"]
website <- map["website"]
street_address <- map["street_address"]
locality <- map["locality"]
city <- map["city"]
state <- map["state"]
postal_code <- map["postal_code"]
landmark <- map["landmark"]
}
}
これらの値が格納されていないためapplicant
値が表示されない値をRetriving。ここでレルムを作成するための私の試したコードは次のとおりです。
let JSON = response.result.value
let realm:Realm = try! Realm()
let resData = Mapper<CaseResponseData>().map(JSONObject: JSON)
try! realm.write
{
realm.delete(realm.objects(CaseAreaEntity.self))
realm.add((resData?.data!)!, update: true)
//realm.create(CaseAreaEntity.self, value: (resData?.data!)!, update: true)
}
表示されているエラー、または発生している問題はなんですか?あなたが正確な問題が何であるかを精緻化すれば、それは役に立ちます。 – Aaron
@Aaron私はそこに何かエラーが出ていませんが、応募者の値は保存されていません –