- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 AFIncrementalStore从网络服务获取数据并通过应用程序启动将其保存在 SQLite 数据库中。
Web 服务不遵循 REST 标准,所以我不能使用 AFRestClient
但有一个 AFHTTPClient
的子类实现了 AFIncrementalStoreHTTPClient
。
所有数据都适用于第一级数据,但我正在处理的响应还包含具有其他对象的数组:
[
{
"PID": 6,
"Actors": [
{
"PID": 0,
"Name": "Kiefer Sutherland"
},
{
"PID": 0,
"Name": "Carlos Bernard"
},
{
"PID": 0,
"Name": "Mary Lynn Rajskub"
},
{
"PID": 0,
"Name": "Jude Ciccolella"
},
{
"PID": 0,
"Name": "Glenn Morshower"
},
{
"PID": 0,
"Name": "Tanya Wright"
},
{
"PID": 0,
"Name": "Alberta Watson"
},
{
"PID": 0,
"Name": "Eric Balfour"
},
{
"PID": 0,
"Name": "Regina King"
},
{
"PID": 0,
"Name": "Peter MacNicol"
},
{
"PID": 0,
"Name": "Marisol Nichols"
},
{
"PID": 0,
"Name": "Jayne Atkinson"
},
{
"PID": 0,
"Name": "Carlo Rota"
},
{
"PID": 0,
"Name": "Janeane Garofalo"
},
{
"PID": 0,
"Name": "Rhys Coiro"
},
{
"PID": 0,
"Name": "Jeffrey R. Nordling"
},
{
"PID": 0,
"Name": "Bob Gunton"
},
{
"PID": 0,
"Name": "Colm Feore"
},
{
"PID": 0,
"Name": "Annie Wersching"
},
{
"PID": 0,
"Name": "Cherry Jones"
},
{
"PID": 0,
"Name": "D.B. Woodside"
},
{
"PID": 0,
"Name": "James Morrison"
},
{
"PID": 0,
"Name": "Gregory Itzin"
},
{
"PID": 0,
"Name": "Jean Smart"
},
{
"PID": 0,
"Name": "Louis Lombardi"
},
{
"PID": 0,
"Name": "Sarah Clarke"
},
{
"PID": 0,
"Name": "Roger R. Cross"
},
{
"PID": 0,
"Name": "Reiko Aylesworth"
},
{
"PID": 0,
"Name": "Elisha Cuthbert"
},
{
"PID": 0,
"Name": "Lana Parrilla"
},
{
"PID": 0,
"Name": "Kim Raver"
},
{
"PID": 0,
"Name": "Dennis Haysbert"
},
{
"PID": 0,
"Name": "Leslie Hope"
},
{
"PID": 0,
"Name": "Xander Berkeley"
},
{
"PID": 0,
"Name": "James Badge Dale"
},
{
"PID": 0,
"Name": "Penny Johnson Jerald"
},
{
"PID": 0,
"Name": "Sarah Wynter"
},
{
"PID": 0,
"Name": "Shohreh Aghdashloo"
},
{
"PID": 0,
"Name": "Laura Harris"
},
{
"PID": 0,
"Name": "David Anders"
},
{
"PID": 0,
"Name": "Katee Sackhoff"
},
{
"PID": 0,
"Name": "Mykelti Williamson"
},
{
"PID": 0,
"Name": "Anil Kapoor"
},
{
"PID": 0,
"Name": "Chris Diamantopoulos"
},
{
"PID": 0,
"Name": "John Boyd"
},
{
"PID": 0,
"Name": "Freddie Prinze Jr."
}
],
"Artwork": [
{
"Filetype": "jpg",
"Id": "291317649",
"Offset": 0,
"Rating": 1,
"Type": 2
},
{
"Filetype": "jpg",
"Id": "-419936433",
"Offset": 1,
"Rating": 1,
"Type": 2
},
{
"Filetype": "jpg",
"Id": "-431274161",
"Offset": 2,
"Rating": 1,
"Type": 2
},
{
"Filetype": "jpg",
"Id": "117154410",
"Offset": 0,
"Rating": 1,
"Type": 3
},
{
"Filetype": "jpg",
"Id": "1179197275",
"Offset": 1,
"Rating": 1,
"Type": 3
},
{
"Filetype": "jpg",
"Id": "-1912564655",
"Offset": 2,
"Rating": 1,
"Type": 3
},
{
"Filetype": "jpg",
"Id": "885093068",
"Offset": 0,
"Rating": 1,
"Type": 1
}
],
"ContentRating": "TV-14",
"DateAdded": "/Date(-3600000+0100)/",
"EpisodeCount": 192,
"ExternalId": [
{
"Id": "76290",
"Site": "TVDB"
},
{
"Id": "tt0285331",
"Site": "IMDB"
}
],
"Genres": [
"Action and Adventure",
"Drama"
],
"Id": "76290",
"IsProtected": false,
"Rating": 8.9,
"Title": "24",
"UnwatchedEpisodeCount": 0,
"Year": 2001
}
]
在我的数据模型中,我有一个实体 TVShow
,它具有 id、评级、标题、未观看的剧集、剧集计数和年份的属性。我将那些映射到我的 HTTPClient
中attributesForRepresentation:ofEntity:fromResponse:
像这样:
if ([entity.name isEqualToString:@"TVShow"]) {
[mutableAttributes setValue:[representation valueForKey:@"Id"] forKey:@"showId"];
[mutableAttributes setValue:[representation valueForKey:@"Title"] forKey:@"title"];
[mutableAttributes setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"Year"] integerValue]] forKey:@"year"];
[mutableAttributes setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"EpisodeCount"] integerValue]] forKey:@"episodeCount"];
[mutableAttributes setValue:[NSNumber numberWithInteger:[[representation valueForKey:@"UnwatchedEpisodeCount"] integerValue]] forKey:@"unwatchedEpisodeCount"];
}
我的想法是,我可以添加另一个实体 Artwork
,在 TVShow
和 Artwork
之间具有一对多关系,但我没有'知道如何映射和定义它。我最近几天的所有尝试都导致了崩溃(可能是因为对 CoreData 缺乏了解)。
如能提供任何帮助,我将不胜感激,因为我真的很想在我的应用中使用 AFIS。
谢谢!
最佳答案
(第一部分不是真正的答案)
除非您非常了解 Core Data,否则我不鼓励使用 NSIncrementalStore
。使用例如简单地通过网络拉取 JSON 更容易,也更不容易出错。 AFNetwork,然后将这些对象插入到由 SQLite 存储支持的普通核心数据堆栈中。您可能会发现这是一个更可行的解决方案。
(第二部分)
也就是说,您可以让它工作,但您必须采取一些技巧,因为您没有任何 id
或 Artwork 对象的其他唯一标识符。您必须将其放入缓存(AFIncrementalStore 使用的第二个核心数据堆栈),然后将这些对象的 NSManagedObjectID 放入该关系的 TVShow 值中。
关于iphone - AFIncrementalStore 处理具有关系的非休息响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13035815/
假设我有两个集合资源: /persons /organizations 一个 GET至 /persons/id/返回一个特定的人。同样,一个 GET至 /organizations/id返回一个特定的
这个问题在这里已经有了答案: Rest best practice: when to return 404 not found (1 个回答) 关闭 7 年前。 我有以下 API: api/gues
背景: 我正在尝试创建一个系统,允许用户对其他用户撰写的评论进行投票(类似于 Reddit)。用户可以选择三个投票值:-1、0 或 1。我创建了一个 POST API(使用 django Rest-f
我正在尝试使用休息调用,该调用获取操作系统中文件的位置。作为返回,其余调用模拟文件的下载。 下面是代码 Welcome to CoinPay Click on bel
我正在向后端发送一个文件,这是上传代码: export class FileUploadComponent { @Input() multiple: boolean = false; @Vie
字符串用户年龄; while(true){ System.out.println("Enter user Age"); userAge = scInput.ne
我正在使用堆栈进行括号检查。包含 break; 语句的 if else 语句之一导致段错误。 我尝试删除 break 程序运行正常但打印错误答案,因为需要 break 才能打印正确的输出。这种段错误的
我是新手,正在学习编程,但无法正确“中断”它。如果硬币不是 0、5、10 或 25,它应该“打破”(最后一个 if)。该程序应该像自动售货机一样工作,只使用 10 美分、5 分硬币、25 美分硬币,当
每次“打破”for-each 结构(PHP/Javascript)时,我都觉得很脏 所以像这样: //Javascript 示例 for (object in objectList) { if
对于这段代码: type Callback = (err: Error | null, result: String) => void; let apiThatAcceptsCallback = (c
如何获取 teamcity build 的变化?我得到以下 URL,其中列出了所有构建更改并提供了一个 URL,我们可以使用该 URL 查看更改 http://teamcityserver/httpA
社区 我正在寻找有关富文本的一些建议。目前的问题是:在后端(在数据库中)存储和管理富文本内容的最佳方式是什么。为什么这看起来像个问题,因为我们可以有多个平台:桌面、移动、网络,这会带来问题。 据我所知
我在向 html 返回错误时遇到问题。所以,我有带有“sql解释器”的网络应用程序。 HTML 在解释器中输入查询后,我在 javascript 中运行 POST 并拍摄到 sprin
我正在尝试为 Rest Controller 进行单元测试。我为经理对数据库访问做了一个 stub (~mock),它运行良好。我唯一的问题是,当我开始单元测试时,它不会启动应用程序。 如何从我的单元
我想使用 azure blob Rest api 创建文件夹,并且还想检查文件夹是否存在。 Hierarchy: arjun/images/ arjun/Videos/001.avi arjun/Vi
我正在寻找使用 django Rest 和 Angular 处理用户登录的最佳方法。目前我正在 Controller 中执行此操作, $http.post('accounts/login/', $sc
我想设计一个允许客户端上传图像的 API,然后应用程序创建图像的不同变体,例如调整大小或更改图像格式,最后应用程序将每个变体的图像信息存储在数据库中。当我尝试确定实现此任务的正确策略时出现问题,这里有
我无法使用 Angular Ajax 连接我的服务器 web2py Restful,但如果我在浏览器中设置 url,它就可以工作,但我不能在 Angular ajax =( Angular 链接
我想在我的项目中添加一个 rest api,因此我需要一个选择性的 mysql 语句 bt 我总是回来 { “错误”:“(1054,你\“'where子句'中的未知列'无'\”)” 代码有什么问题?我
我想为自己创建一个启动/停止 Azure VM 机器人。我想做的是拥有一个 slack/telegram 机器人,它可以监听消息并通过命令/start/stop 启动/停止我的虚拟机。我应该使用什么
我是一名优秀的程序员,十分优秀!