对于使用ThreadSafeReference,如何从对象数组中构造Result

时间:2017-09-11 11:04:02

标签: swift multithreading realm

以下是db模型设计;

class Routing: Object {

    dynamic var channelCode: String = ""
    dynamic var storeCode: String = ""
    dynamic var userId = 0


    dynamic var startDate: Date = Date()
    dynamic var endDate: Date = Date()  
}
// primary keys:  channelCode + storeCode + userId + startDate + endDate

class StoreDB: Object {
    dynamic var storeCode: String = ""
    dynamic var channelCode: String = ""

    dynamic var areaCode: String = ""  
}
// primary keys: storeCode + channelCode
|

例如:

Routing(channelCode: "Waston", storeCode: "AL", userId = 18, startDate 
 = "2017-01-01", endDate = "2018-01-01")
Routing(channelCode: "Manning", storeCode: "AL", userId = 18, startDate 
 = "2017-07-01", endDate = "2018-01-01")

StoreDB(storeCode: "AL", channelCode = "Waston", areaCode = "hk")
StoreDB(storeCode: "AL", channelCode = "Manning", areaCode = "hk")

使用userId查询Routing表,获取Result<Routing>;然后

Result<Routing>.forEach({  routing in
    let channelCode = routing.channelCode
    let storeCode = routing.storeCode
    // using channelCode, storeCode to query Store
})

然后得到

Result<Routing>.forEach({  routing in
        Result<Store>
})

我的最终目标是获取Result<Store>,然后可以使用ThreadSafeReference(to: Result<Store>)Result<Store>传递给主线程

但是这里结果无法使用追加功能,并且无法将Array转换为Result。那么当我必须将Result传递给主线程时,我怎么能解决这个问题?

0 个答案:

没有答案