问题标签 [github-mantle]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
1578 浏览

ios - ios Mantle - 正确覆盖默认 initWithDictionary

我面临以下问题..

我有一个类 Menu.h 和 Item.h。菜单就像餐厅的菜单,有多个类别(如开胃菜、沙拉等),每个菜单都有多个关联的项目。所以 Menu.h 有一个名为 itemList 的 NSArray 属性。我正在尝试使用 Mantle 自动加载这些对象。

我的问题如下:如果itemList为null,即来自服务器的null响应来自itemList,然后我想覆盖默认的initWithDictionary行为来做某事并从Item.h的构造函数返回一个非零对象怎么办我做吗?令我惊讶的是,代码没有到达这个构造函数,因为在形成 Menu.h 时它是空的。我确实也指定了 (NSValueTransformer)。任何线索?谢谢!

0 投票
1 回答
681 浏览

ios - 在 iOS 中使用 Mantle 将带有时间戳的 NSArray 映射到 NSDate 对象

例如,我有一个带有属性的 MTLModel 子类 Order

来自服务器的 JSON 如下所示:

mb in 是否有可能+ (NSValueTransformer *)datesJSONTransformer将 JSON 中的这两个时间戳转换为 NSDate 对象?(dateTo, dateFrom pr-s 类)

0 投票
1 回答
1593 浏览

ios - Mantle 问题 - MTLValueTransformer 不会将 NSNumber 转换为 int

我正在使用 Mantle 成功转换模型中的值 - 但是这个返回错误Incompatible block pointer types sending 'int (^)(NSNumber *__strong)' to parameter of type 'MTLValueTransformerBlock' (aka 'id (^)(__strong id)')

这种类似的转换工作正常:

不明白这里的区别。

0 投票
0 回答
105 浏览

ios - 无法用地幔映射无键 json(正确)

我正在尝试找到一种方法来正确解析我的 json 数组。我无法找到一个好的解决方案来使用 mantle 解析我的 json 对象。我能够找到有关父子对象的信息,但找不到有关持有无钥匙对象集合的信息。我的代码有效,但这不是一种理想的方式,因为视图控制器文件中有太多与数据相关的代码。如果有人能提出更好的方法,我将不胜感激(这意味着更有条理,这样我就不必使用 for 循环来遍历视图控制器中的每个项目)。

这就是我的 json 的样子(数组中的对象没有键):

这是代码

restmanager.m

模型类

abcmodel.h

abcmodel.m

视图控制器.m

//然后显示在

谢谢你。

0 投票
0 回答
80 浏览

ios - How to map an inner object that's changing based on the endpoint request with GitHub Mantle?

I have the following scenario:

  • a web service that provides responses wrapped in the same object (described later)
  • the inner object can be completely different based on the endpoint being called
  • I am using GitHub's Mantle to do the model mapping in an iOS app

The base response wrapper is like this:

The DataObject property can be anything. i.e. it could be a DTOUser class like this:

How would you map this with Mantle? I thought about creating a base response class that holds the wrapper data and then have all of my inner models inherit from that class. But then I'd have two classes for each response as the container would be a clone of the base class with the override of the transformer for the DataObject type, which is not elegant.

I thought about making a wrapper class and a separate inner model class and just map the response to the first and then map the same response to the second, but that's not elegant as well.

How would you do it?

0 投票
0 回答
175 浏览

objective-c - JSON 使用 Mantle 映射任何内部对象

如果我收到这样的回复

那么如何在响应中获取对象数组呢?

我找到的解决方案如下:

1)我可以创建一个代表上述json的模型类objectsResponse,它将有一个名为objects的NSArray属性。然后我可以使用

mtl_JSONArrayTransformerWithModelClass

使用 objects 属性映射 json 响应,然后使用 objectsResponse 的对象访问错误。

2)直接使用方法

[MTLJSONAdapter modelsOfClass: [Object fromJsonArray:[response objectForKey:@"objects"]]] error:&error]

除了这些之外,还有其他直接使用地幔对象映射的方法吗?

谢谢

0 投票
1 回答
635 浏览

ios - 实现 MTLModel 显示解析 json 字典时出错

错误消息如下所示:

这是代码:

Channel.m

User.m

使用Mantle,iOS json 解析框架

如何将我的 JSON 解析为可可对象?

0 投票
1 回答
97 浏览

objective-c - 如何根据 NSDictionary 参数制作单个变量?

来自服务器的数据

我想做的是

我的模型.h

我的模型.m

我希望变量myCardType具有基于字典参数的 NS_ENUM 值。

那是

任何帮助都会很棒。

0 投票
1 回答
339 浏览

ios - 在外衣包络响应的情况下如何自动映射到地幔模型类?

我正在使用地幔进行模型映射,并使用外衣进行网络请求。Overcoat 自动将结果映射到模型,但是当有包络响应时,我可以获得自定义 Overcoat 响应。但问题是 Overcoat 响应是 NSCFDictionary 响应,但它应该是 MantleModel 响应。

我知道如何手动将结果转换为 mantleModel:

但是对我来说应该用大衣来完成。我是古玩,无论如何都可以通过 Overcoat 来完成,而不是手动转换结果。

0 投票
1 回答
164 浏览

ios - Xcode 在注释的文本块中给出特定单词的错误

Mantle在我的项目中使用序列化对象。该库被许多人使用,我确信错误与它们无关。当我包含Mantle.h或明确MTLJSONAdapter.h包含在注释中的文本块时,它会给出一些不相关的错误MTLJSONAdapter.h

这是MTLJSONAdapter.h发生错误的屏幕截图:

文本块截图

文本块是:

我得到的错误是:

xcode 错误

#import <Mantle/Mantle.h>删除线时没有错误。BaseModel我按照图书馆的建议在我的班级中导入标题。该类是空的,但这里仅供参考:

基本模型.h 基本模型.m

据我所知,这个错误似乎源于编译器,因为编译器以某种方式解析了注释块中的文本。但是我从来没有遇到过这种情况,可能是什么原因造成的?

我在使用 Xcode 6.3 的优胜美地。我正在与 集成MantleCocoapods并且过去一直这样做并且从未遇到过问题。尽管如此,我尝试擦除所有内容并pod install再次运行无济于事。