NSInteger 错误的隐式转换 [英] Implicit conversion of NSInteger error

查看:82
本文介绍了NSInteger 错误的隐式转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 MagicalRecord,我尝试使用特定的 clientNumber 获取记录,该记录是一个 NSInteger(定义为 int16 作为数据类型).

Using MagicalRecord, I am trying to get the record with a particular clientNumber which is a NSInteger (defined as int16 as the data type).

这是我收到错误的代码行:

This is my line of code where I'm getting the error:

ClientInfo *clientSelected = [ClientInfo MR_findFirstByAttribute:@"aClientNumber" withValue: clientNumber inContext:localContext];

更新:这是 MR_findFirstByAtytribute 的定义:

UPDATE: This is the definition of MR_findFirstByAtytribute:

MR_findFirstByAttribute:(NSString *) withValue:(id)

这是我得到的错误:

Implicit conversion of NSInteger (aka int) is disallowed with ARC

就我的一生而言,我看不出有什么问题.ClientInfo 定义为

For the life of me, I don't see what's wrong. ClientInfo is defined as

@interface ClientInfo : NSManagedObject

推荐答案

withValue 的参数类型是一个 id(一个指针).NSInteger 是标量值(不是对象),不能隐式转换为指针值.

The parameter type for withValue is an id (a pointer). NSInteger is a scalar value (not an object) and cannot be converted to a pointer value implicitly.

这纯粹是一个猜测,但从 NSInteger 创建一个 NSNumber 可能会起作用:

This is purely a guess, but creating an NSNumber from the NSInteger might work:

NSNumber *val = [NSNumber numberWithInteger:clienNumber]
ClientInfo *clientSelected = [ClientInfo MR_findFirstByAttribute:@"aClientNumber" withValue:val inContext:localContext];

这篇关于NSInteger 错误的隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆