Kevin Kevin - 1 year ago 178
iOS Question

Objective C incompatible

I'm new to Objective C, and am getting a little confused by the behavior of my code.


@interface MEDTNetworkAuthentication()

@property (nonatomic,retain) NSString *certificate;

@implementation MEDTNetworkAuthentication

-(void)setCertificate:(NSData*) certificateData
self.certificate=[self getCarelinkCertificateUsingData:certificateData];



#import <Foundation/Foundation.h>

@protocol NetworkAuthenticationDelegate;

@interface MEDTNetworkAuthentication : NSObject<NSURLSessionDelegate>

-(void)authenticate:(NSData*) certificateData andAuthData:(NSString*) authorization andURLSession:(NSURLSession*) careLinkAuthenticationSession;
-(void)setCertificate:(NSData*) certificateData;


Now, the
was existing functionality in the code before. Previously, I changed put
after setting
, and it functions as expected. But since I want that previous functionality and don't want to get rid of it all, I wanted to create a new function (
). But when I add that function to the
files, now BOTH lines setting
are giving me an error saying
Assigning to 'NSData *__strong' from incompatible type 'NSString *'
. When I delete the line for
from the
file, the error goes away, but I can't access that function outside the m file now (obviously). What's going on?

Answer Source

Now that you've posted real code with real property names and real method names, the problem is obvious.

As I guessed, your property is named certificate, not cert. So your setCertificate: method is hiding the setter method for your certificate property.

Since the certificate property is of type NSString and your setCertificate: method takes a parameter of type NSData, you have a conflict.

The proper solution is to renamed your setCertificate: method so it doesn't conflict with your property.

Maybe change it to setCertificateData:.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download