gpt4 book ai didi

iphone - NSinteger 的地址通过递增来改变

转载 作者:行者123 更新时间:2023-11-30 18:32:42 26 4
gpt4 key购买 nike

我正在我的应用程序中创建一个计数器。我想在发生特定更改时增加它。计数器将其值从 0 增加到 1。然后它会固定为 1,并且不再增加。这是我的代码。在 .h 中我已经做到了这一点。

@interface URLCacheConnection : NSObject {
int counter;

}

在 .m 中它有

-(void) connection:(NSURLConnection *)conn didReceiveResponse:(NSURLResponse *)response {
if ([response isKindOfClass:[NSHTTPURLResponse self]]) {

printf("[(NSHTTPURLResponse *)response allHeaderFields] = %s\n", [[(NSHTTPURLResponse *)response suggestedFilename] cStringUsingEncoding: 1]);
NSDictionary *dict = [(NSHTTPURLResponse *)response allHeaderFields];
NSLog(@"allHeaderFields = %@\n", [dict description]);

if(downloadItem.downloadStatus != DownloadStatus_resumed)
{
if([[NSFileManager defaultManager] fileExistsAtPath: downloadItem.fileItem.filePath]) {
counter = counter + 1;
NSLog(@"the value of counter is %d", counter);

NSString * fileExtension = [downloadItem.fileItem.fileName pathExtension];

NSString *fileName = [downloadItem.fileItem.fileName stringByDeletingPathExtension];

fileName = [fileName stringByAppendingFormat:@"-(%d)", counter];
fileName = [fileName stringByAppendingString:[NSString stringWithFormat:@".%@",fileExtension]];

downloadItem.fileItem.fileName = fileName;

downloadItem.fileItem.filePath = [NSString stringWithFormat:@"%@/%@", downloadItem.fileItem.folderPath, downloadItem.fileItem.fileName];
}
else {
counter = 0;
}
BOOL fileCreatedFlag = [[NSFileManager defaultManager] createFileAtPath: downloadItem.fileItem.filePath contents:nil attributes:nil];
downloadItem.fileItem.fileHandle = [NSFileHandle fileHandleForWritingAtPath: downloadItem.fileItem.filePath];
fileCreatedFlag = fileCreatedFlag;

}

}

}

最佳答案

James 这是因为 self.counter 将返回一个值而不是变量,因此它将打印不同的地址。
请提供准确的日志并按照上述评论中Keety的建议使用日志。

关于iphone - NSinteger 的地址通过递增来改变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10527819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com