使用arc不允许隐式转换指向'nsstring *'的objective-c指针的间接指针

时间:2013-12-11 05:57:36

标签: ios iphone objective-c cocoa-touch automatic-ref-counting

我一直在下面给出这个错误。但我无法理解如何解决它。请指导我有什么问题。我知道这是ARC的过渡指南,但我无法理解如何解决它。  返回[self isUnique:ioValue forKey:@“serverId”];

- (BOOL)validateServerId:(id *)ioValue error:(NSError **)outError {
//   DLog(@"%@",__strong ioValue);
//  NSString *__strong a=ioValue;
return [self isUnique:ioValue forKey:@"serverId"];
}

- (BOOL)isUnique:(NSString *)value forKey:(NSString *)key{

if([key isEqualToString:@"serverId"])
{
    NSFetchRequest * fetch = [[NSFetchRequest alloc] init];
    [fetch setEntity:[NSEntityDescription entityForName:[self.entity name]
                                 inManagedObjectContext:self.managedObjectContext]];

    NSPredicate *predicate = [NSPredicate
                              predicateWithFormat:@"serverId = %@",value];

    fetch.predicate = predicate;

    NSError *error = nil;
    NSUInteger count = [self.managedObjectContext
                        countForFetchRequest:fetch error:&error];

    if (count > 1) {
        // Produce error message...

        // Failed validation:
        return NO;
    }


}


return YES;
}

3 个答案:

答案 0 :(得分:2)

但是id类型用于通用对象(当你不确定它的类型时)将参数类型从 id替换为NSString

**** From ****
- (BOOL)validateServerId:(id *)ioValue error:(NSError **)outError;

**** To ****
- (BOOL)validateServerId:(NSString *)ioValue error:(NSError **)outError;

希望这可能有所帮助!

答案 1 :(得分:1)

在此*移除(id *)ioValue或将其替换为(NSString *)ioValue

答案 2 :(得分:0)

解决方案是在值之前添加*因为有地址而我通过添加*传递地址现在我在该地址传递值

return [self isUnique:* ioValue forKey:@“serverId”];