我们正在尝试为我们的 IOS 应用构建一个简单的跟随功能。我们有两个 API,我们的 Brand API
有一个对象数组,每个对象中包含我们品牌的唯一品牌 ID。以及我们存储用户的 Firebase API
。在 Firebase API
中,它有一个名为 followingBrands 的键和一个对象数组,该对象数组由 来 self 们的
Brand API` 的唯一品牌 ID 作为键,值为 true。一旦用户在我们的应用程序上喜欢该品牌并关注了该品牌,就会创建这些对象。
当应用加载时,我们会检查 Firebase API
的品牌 ID 键是否与 Brand API
的品牌 ID 匹配,然后显示星号以表明用户是已经关注该品牌。
我们的问题是 Brand API
是通过分页(即偏移量)实现的,所以如果不是所有唯一的品牌 ID 都可用于与我们的比较,我们将如何验证他们关注的所有品牌 Firebase API
?
我们在IOS端使用swift。 Brand API
是使用 django-tastypie 构建的
Firebase API
"user_id" : {
"currentFollowingCount" : 0,
"displayName" : "",
"email" : "",
"followingBrands" : {
"unique_brand_id" : true
},
"provider" : "Facebook",
"userID" : "user_id"
}
品牌 API
{
"labels": [
{
"id": "unique_brand_id"
}
],
"meta": {
"limit": 10,
"next": "/api/?limit=10&offset=10",
"offset": 0,
"previous": null,
"total_count": 33
}
}
最佳答案
你可以做一个技巧,只要有一个 brandID 等于你的 fireBase followingBrands 键就显示星星。你不需要在 brandAPI 中检查它,因为我认为你已经在 fireBaseAPI 中插入了每个品牌,然后是用户,所以这对你有用。
let fireBaseResponse:[String:AnyObject?] = [
"followingBrands":["unique_brand_id":true]
]
let customObject = ["customObjectBrandID":"unique_brand_id"]//yourObject
let followingBrandsArr = (fireBaseResponse["followingBrands"] as! [String:Bool]).keys
//now do a check for Star
let myObjectBrandID = customObject["customObjectBrandID"]
if followingBrandsArr.contains(myObjectBrandID!) == true{
print("user is following this brand so show the follow star")
}else{
print("don't show or hide it")
}
关于ios - 喜欢通过客户端使用两个 API 作为 IOS 应用程序(Swift)的功能实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39058110/