Bridget Cay
Bridget Cay

Reputation: 31

"No visible interface" for existing method

This is my .h file:

@interface test1ViewController : UIViewController{}

    -(void)function1:(NSString *)param1:(NSString *)param2 ;
@end

Here is my .m file:

- (void)viewDidLoad{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    [self function1:@"333" param2:@"sadfas"];
}


-(void)function1:(NSString *)param1:(NSString *)param2 { }

This line of code gives me an error, stating: no visible @interface .... declares the selector 'function1:param2:

[self function1:@"333" param2:@"sadfas" ];

I tried to modify this a bit, but could not get it to work. How do I fix this

Upvotes: 0

Views: 102

Answers (4)

John Riselvato
John Riselvato

Reputation: 12924

The function should be

- (void)functionWithFirstParam:(NSString *)param1 andSecondParam:(NSString *)param2;

param1 and param2 are the variables you are sending.

Thus you'll have access to the passed string as such:

- (void)functionWithFirstParam:(NSString *)param1 andSecondParam:(NSString *)param2 {
    NSLog(@"Param1: %@, Param2: %@",param1, param2);
}

and you'll call this function like this:

[self functionWithFirstParam:@"Hello" andSecondParam:@"World"];

Upvotes: 4

iPatel
iPatel

Reputation: 47099

You have mistake in Syntax of creation of method

create method such like

-(void)function1:(NSString *)param1 andAlsoWriteParam2:(NSString *)param2;

Add method in your .m file such like

-(void)function1:(NSString *)param1 andAlsoWriteParam2:(NSString *)param2 
{
  // your stuff;
}

And call method like

[self function1:@"333" andAlsoWriteParam2:@"ssdaf"]

Upvotes: 1

thatzprem
thatzprem

Reputation: 4767

-(void)function1:(NSString *)param1 secondParam:(NSString *)param2;

Upvotes: 0

Sorin Cioban
Sorin Cioban

Reputation: 2225

The correct syntax is:

-(void)function1:(NSString *)param1 andParam2:(NSString *)param2;

And then when you call it's

[self function1:@"333" andParam2:@"sadfas"];

Upvotes: 2

Related Questions