Ame*_*chi 6 ios tastypie swift
我们正在尝试为我们的IOS应用程序构建一个简单的关注功能.我们有两个API,我们Brand API的对象数组包含每个对象中我们品牌的独特品牌ID.我们Firebase API在哪里存储用户.在Firebase API它内部有一个名为unique brand ids from ourfollowBrands的键,其中的对象数组由Brand API` 组成,键为值为true.一旦用户按照品牌喜欢我们的应用程序上的品牌,就会创建对象.
当应用程序加载时,我们会检查Firebase API品牌ID 是否与品牌ID相匹配,Brand API然后显示一个星标,表示用户已经关注该品牌.
我们的问题是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"
}
Run Code Online (Sandbox Code Playgroud)
品牌API
{
"labels": [
{
"id": "unique_brand_id"
}
],
"meta": {
"limit": 10,
"next": "/api/?limit=10&offset=10",
"offset": 0,
"previous": null,
"total_count": 33
}
}
Run Code Online (Sandbox Code Playgroud)
你可以做一个技巧,只要有一个brandID等于你的fireBase下面的Brands键就显示星星。您不需要在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")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
145 次 |
| 最近记录: |