【发布时间】:2011-05-16 03:29:21
【问题描述】:
我知道您一定已经看到此警告并经常给出解决方案,但我的情况有点特殊。
我只收到一个类的警告,但所有内容(导入、实现、头文件等)都设置正确。我在 XCode 中编写 Objective-C 代码已经有一段时间了,我会为自己说,我已经获得了相当多的 iPhone 编程经验。我完全确定,一切都很好。
看来,XCode 不知何故无法识别我对课程所做的更改。它甚至建议了一些不再属于此类的方法。我在另一台 Mac 上检查了该项目并在那里构建它,一切都很好,根本没有任何警告。
我不想重新安装 XCode 以摆脱这些不应该出现的恼人警告。关于如何告诉 XCode 它必须给自己买些眼镜有什么建议吗?
非常感谢您的帮助 =)
编辑:好的,只是为了没人能说,我疯了或其他什么,这是代码和最后的小解释:
#import <Foundation/Foundation.h>
@interface URLConnection : NSObject {
NSString *theURL;
NSMutableData *receivedData;
id delegate; // delegate needed for handling response
}
@property (nonatomic, retain) NSMutableData *receivedData;
@property (retain) id delegate;
- (NSData*) sendSynchronousRequest:(NSData*)_postData;
- (void) sendRequest:(NSData*)_postData;
- (void)setDelegate:(id)val;
- (id)delegate;
@end
#import "URLConnection.h"
@implementation URLConnection
@synthesize receivedData, delegate;
- (id) init
{
if (self = [super init]) {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![[defaults stringForKey:@"bankurl"] isEqualToString:@"<Custom URL>"]) {
theURL = [[defaults stringForKey:@"bankurl"] retain];
} else {
theURL = [[defaults stringForKey:@"bankurl_list"] retain];
}
receivedData = [[NSMutableData alloc] init];
}
return self;
}
- (void)setDelegate:(id)val
{
delegate = val;
}
- (id)delegate
{
return delegate;
}
/* send a synchronous request (specified for xml documents) */
- (NSData*) sendSynchronousRequest:(NSData*)_postData
{
NSString *_urlString = theURL;
NSMutableURLRequest *_urlRequest = [[NSMutableURLRequest alloc] init];
[_urlRequest setURL:[NSURL URLWithString:_urlString]];
[_urlRequest setHTTPMethod:@"POST"];
[_urlRequest setValue:@"text/xml"
forHTTPHeaderField:@"Content-Type"];
[_urlRequest setHTTPBody:_postData];
// response
NSHTTPURLResponse *_urlResponse = nil;
NSError *_error = [[NSError alloc] init];
NSData *_responseData = [NSURLConnection sendSynchronousRequest:_urlRequest
returningResponse:&_urlResponse
error:&_error];
[_urlRequest release];
NSString *_result = [[NSString alloc] initWithData:_responseData
encoding:NSUTF8StringEncoding];
NSLog(@"Response code: %d", [_urlResponse statusCode]);
if ([_urlResponse statusCode] >= 200 && [_urlResponse statusCode] < 300) {
NSLog(@"Response: %@", _result);
}
return _responseData;
}
/* send an asynchronous request (specified for xml documents) */
- (void) sendRequest:(NSData*)_postData
{
NSMutableURLRequest *_urlRequest = [[NSMutableURLRequest alloc] init];
[_urlRequest setURL:[NSURL URLWithString:theURL]];
[_urlRequest setHTTPMethod:@"POST"];
[_urlRequest setValue:@"text/xml"
forHTTPHeaderField:@"Content-Type"];
[_urlRequest setHTTPBody:_postData];
[[NSURLConnection alloc] initWithRequest:_urlRequest delegate:self];
[_urlRequest release];
}
/*
* NSURLRequest Delegate
* if a response comes back, clear receivedData to make room for the response data
*/
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
[receivedData setLength:0];
}
/*
* NSURLRequest Delegate
* if data is received, append the chunk of data to receivedData
*/
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
/*
* NSURLRequest Delegate
* when all response data has been stored, call didFinishDownload() in the class
* which set itself as the delegate
*/
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[delegate didFinishDownload:receivedData];
[connection release];
//[receivedData release];
}
- (void) dealloc
{
[theURL release];
theURL = nil;
[super dealloc];
}
@end
首先,是的,我知道“[delegate didFinishDownload:receivedData];”这一行会发出警告,但这不是我要写的问题。当我按 alt+esc 键查看方法建议时,上述所有内容都在列表中,还有“sendRequest:theURL:”和“sendMail:”,它们早就被删除了。
【问题讨论】:
-
我不知道为什么,但是今天启动 XCode 后警告已被删除。打败我...问题解决了,我想...
标签: iphone objective-c xcode warnings