Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
铸造';长';至';id';不允许使用ARC-iOS开发_Ios_Objective C_Memory Management - Fatal编程技术网

铸造';长';至';id';不允许使用ARC-iOS开发

铸造';长';至';id';不允许使用ARC-iOS开发,ios,objective-c,memory-management,Ios,Objective C,Memory Management,将我的项目转换为ARC,但需要以下两位代码的帮助才能上载和下载文件: - (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{ [delegate perfo

将我的项目转换为ARC,但需要以下两位代码的帮助才能上载和下载文件:

- (void)connection:(NSURLConnection *)connection didSendBodyData:(NSInteger)bytesWritten totalBytesWritten:(NSInteger)totalBytesWritten totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite{
[delegate performSelector:progressSelector withObject:(id)(100*totalBytesWritten /totalBytesExpectedToWrite)];
然后是下面的代码,特别是最后一行:

- (void)connection:(NSURLConnection *)con // IN
didReceiveData:(NSData *)data                // IN
{
NSLog(@"%s: self:0x%p\n", __func__, self);
NSInteger       dataLength;
const uint8_t * dataBytes;
NSInteger       bytesWritten;
NSInteger       bytesWrittenSoFar;

dataLength = data.length;
dataBytes  = (const uint8_t * )data.bytes;

bytesWrittenSoFar = 0;
if(fileStream!=NULL)
{
do {
    NSLog(@"%d",(int)bytesWrittenSoFar);
    bytesWritten = [fileStream write:&dataBytes[bytesWrittenSoFar] maxLength:dataLength - bytesWrittenSoFar];
    assert(bytesWritten != 0);
    if (bytesWritten == -1)
    {
         [self downloadSucceeded:NO];
        break;
    }
    else
    {
        bytesWrittenSoFar += bytesWritten;
    }
}
    while (bytesWrittenSoFar != dataLength);
}
dataSize+=data.length;
if(dataSize==downloadSize)
{
    downloadDidSucceed=TRUE;
}
[delegate performSelector:progressSelector withObject:(id)(long)(100*dataSize/downloadSize)];
}
非常感谢您的帮助

您的问题就在这里

 [delegate performSelector:progressSelector withObject:(id)(long)(100*dataSize/downloadSize)];
试试这个

[delegate performSelector:progressSelector withObject:[NSnumber numberWithLong:(100*dataSize/downloadSize)]];
你的问题就在这里

 [delegate performSelector:progressSelector withObject:(id)(long)(100*dataSize/downloadSize)];
试试这个

[delegate performSelector:progressSelector withObject:[NSnumber numberWithLong:(100*dataSize/downloadSize)]];

在Objective-C中,int/long/float/double等标量值与对象类型之间存在区别

id类型是匿名对象类型。你不知道它是什么,但你知道它是一个物体

long
不是也不能是对象。它是一个简单的标量值。这就是为什么编译器不允许您将long转换为ID类型


Sh_Khan的答案是将你的长值包装在一个
NSNumber
中,通过创建一个包含你的值的对象来解决这个问题。您也可以使用
NSValue
来获得相同的效果,但是
NSValue
可以表示不能用
NSNumbers
表示的结构。在Objective-C中,int/long/float/double等标量值与对象类型之间存在区别

id类型是匿名对象类型。你不知道它是什么,但你知道它是一个物体

long
不是也不能是对象。它是一个简单的标量值。这就是为什么编译器不允许您将long转换为ID类型


Sh_Khan的答案是将你的长值包装在一个
NSNumber
中,通过创建一个包含你的值的对象来解决这个问题。您也可以使用
NSValue
来获得相同的效果,但是
NSValue
可以表示像结构这样的东西,您不能用
NSNumbers

表示欢迎使用堆栈溢出!你能详细说明你的代码是如何“不工作”的吗?你在期待什么,到底发生了什么?如果您遇到异常/错误,请发布发生该异常/错误的行以及异常/错误详细信息。请输入这些详细信息,否则我们可能无法提供帮助。欢迎使用堆栈溢出!你能详细说明你的代码是如何“不工作”的吗?你在期待什么,到底发生了什么?如果您遇到异常/错误,请发布发生该异常/错误的行以及异常/错误详细信息。请输入这些详细信息,否则我们可能无法提供帮助。更好的解决方案-不要使用
性能选择器:withObject:
。没有理由在这里使用它。我会用什么来代替呢?更好的解决方案-不要使用
performSelector:withObject:
。没有理由在这里用它。我会用什么来代替呢?