开发者

'NSDictionary' may not respond to '+dictionaryWithJSONString'... when using TouchJSON

I'm really new to Cocoa development, so please be kind. Anyway, I'm trying to deserialize a JSON string I'm sending from my server through TouchJSON, but I'm getting a compiler warning of 'NSDictionary' may not respond to '+dictionaryWithJSONString:error:'.

I understand what the error is saying, but I have all the TouchJSON files in the project, and I have a reference to NSDictionary_JSONExtensions.h in the app_Prefix.pch file. When I type the command I do see it show up in the code sense, so why is it failing in the compiler?

Here's the code where it's failing, I'd appreciate any suggestions:

- (IBAction)authorizeUser:(id)sender {
 ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://192.168.0.5/iOS"]];

 [request setRequestMethod:@"POST"];
 [request setPostValue:credentialsName.text forKey:@"Credentials.Name"];
 [request setPostValue:credentialsPassword.text forKey:@"Credentials.Password"];
 [request setPostValue:credentialsPIN.text forKey:@"Credentials.PIN"];
 [request startSynchronous];
开发者_高级运维
 NSError *requestError = [request error];

 if (!requestError) {
  NSError *jsonError = NULL;
  NSDictionary *responseDictionary = [NSDictionary dictionaryWithJSONString:[request responseString] error:&jsonError]; /* <- ERROR... */

  status.text = [responseDictionary objectForKey:@"Success"];
 }
}

Thanks in advance!

UPDATE

#ifdef __OBJC__
    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import "ASIFormDataRequest.h"
    #import "CJSONDeserializer.h"
    #import "NSDictionary_JSONExtensions.h"
#endif

UPDATE 2

This is what shows up in the Preprocess, and the files are there as well as the method, so it should be working?

# 10 "/Users/Alex/Documents/iPad/Classes/SignInViewController.m" 2
# 1 "/Users/Alex/Documents/iPad/TouchJSON/Extensions/NSDictionary_JSONExtensions.h" 1
# 32 "/Users/Alex/Documents/iPad/TouchJSON/Extensions/NSDictionary_JSONExtensions.h"
@interface NSDictionary (NSDictionary_JSONExtensions)

+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;


The problem is that

+ (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;

is defined in the implementation file (NSDictionary_JSONExtensions.m) but hasn't been declared in the header file (NSDictionary_JSONExtensions.h):

@interface NSDictionary (NSDictionary_JSONExtensions)
+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;
@end

'NSDictionary' may not respond to '+dictionaryWithJSONString'... when using TouchJSON

You can patch the header file and add the declaration of the method you're using:

@interface NSDictionary (NSDictionary_JSONExtensions)
+ (id)dictionaryWithJSONData:(NSData *)inData error:(NSError **)outError;
+ (id)dictionaryWithJSONString:(NSString *)inJSON error:(NSError **)outError;
@end

until the developers fix this. I've just alerted TouchJSON's maintainer of this problem.


Ignore the code sense. It always suggest stuff that may not be available. Importing NSDictionary_JSONExtensions.h on your .m should fix the problem. The question is why is not fixed if it's on your .pch.

Reading the prefix restrictions, you may want to check this:

  * Use one and only one prefix header per target.
  * Set the Prefix Header and Precompile Prefix Header build settings for every target that uses precompiled headers.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜