jftuga
jftuga

Reputation: 1963

undeclared identifier when trying to use my own class

I am new to Xcode & Objective C. I am trying to create and use my own class.

//NSObject+Bridge.h
@interface NSObject (Bridge)
- (void)modify_coredata:(NSString *)table rows:(NSString *)rows;
@end

// NSObject+Bridge.m
#import "NSObject+Bridge.h"
@implementation NSObject (Bridge)
- (void)modify_coredata:(NSString *)table rows:(NSString *)rows {
    NSLog(@"table: %@", table);
    NSLog(@"rows : %@", rows);
}

In my ViewController.m file, I have #import "NSObject+Bridge.h" near the top of the file.

Inside the viewDidLoad method of ViewController.m, I tried both of these lines of code. They both fail with this error: Use of undeclared identifier 'Bridge'.

Bridge *b1; = [[Bridge alloc] init];
Bridge *b2;

What am I doing wrong?

Upvotes: 0

Views: 488

Answers (2)

Hussain Shabbir
Hussain Shabbir

Reputation: 15015

You have declared the category. So directly you can use category method to the existing class without initializing it.

Upvotes: 0

rmaddy
rmaddy

Reputation: 318814

You don't declare a class named Bridge. All you have done is create a category on NSObject named Bridge. Two completely different and unrelated things.

A class named Bridge would be in files named Bridge.h and Bridge.m and be declared as:

@interface Bridge : NSObject

Perhaps you want:

Bridge.h

@interface Bridge : NSObject

- (void)modify_coredata:(NSString *)table rows:(NSString *)rows;

@end

Bridge.m

#import "Bridge.h"

@implementation Bridge

- (void)modify_coredata:(NSString *)table rows:(NSString *)rows {
    NSLog(@"table: %@", table);
    NSLog(@"rows : %@", rows);
}

BTW - typical naming conventions for methods mean your method should really be named:

modifyCoreData:rows:

Note the use of camel case instead of using underscores.

Upvotes: 2

Related Questions