Objective C Method signatures problem [closed] - objective-c

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hi I have declared a method in one of my classes called HttpWorker. The method declaration is
-(void) setRequestParameters:(NSString *)parameters iRequestCode:(double)iRequestCode initialSleep:(long)initialSleep;
I am using trying to call this method from another class called NetManager. I wrote following code for this
NSString *paramStr = #"jc=2";
HttpWorker *httpWorker = [[HttpWorker alloc] init];
double requestCode = [[NSDate date] timeIntervalSince1970];
[httpWorker setRequestParameters:paramStr iReqeustCode:requestCode initialSleep:initialSleep];
But when I compile my code, xcode gives me following warning.
warning: 'HttpWorker' may not respond to '-setRequestParameters:iRequestCode:initialSleep:'
Can anyone please tell me where i am wrong?
Thanks and Best Regards

You have a typo:
iReqeustCode:
Should be:
iRequestCode:

Also you have not defined initialSleep. That should result in compile error!

Related

Blocks in Swift shows error "Missing argument for parameter #2 in call" [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm now using Jonas Gessner's JGActionSheet with Swift in my project, and the sample was written by Objective-C, when I tried to convert the block to Swift, Xcode shows the error "Missing argument for parameter #2 in call", here is the code I written and the screenshot:
Objective-C Sample
JGActionSheet *sheet = [JGActionSheet actionSheetWithSections:sections];
[sheet setButtonPressedBlock:^(JGActionSheet *sheet, NSIndexPath *indexPath)
{
[sheet dismissAnimated:YES];
}];
Code I written in Swift
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}
Error screenshot
Missing argument for parameter #2 in call
So please help me to figure this out and thanks very much!
actionSheet.buttonPressedBlock is a property. You are trying to set it. So where's your equals sign? This is how you set things in Swift:
myThing.myProperty = myValue
The fact that you are trying to set this property to a block (a function) changes nothing. So:
let actionSheet = JGActionSheet(sections: sections)
actionSheet.buttonPressedBlock = {
(sheet: JGActionSheet!, indexPath: NSIndexPath!) in
actionSheet.dismissAnimated(true)
}

Invalid Operands to binary expression (NSNumber* __strong and NSNumber*) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
nsnumber *totaldur=0;
totalDur+=(NSNumber*)[dict valueForKey:#"tracktime"];
You can't perform addition on NSnumber for this
NSNumber * totaldur =[NSNumber numberWithInteger:20];
totaldur = [NSNumber numberWithInteger:([number1 integerValue] + [[dict valueForKey:#"tracktime"] integerValue])];
//// first of all convert both numbers to same data type like (nsinteger,int,float) and then apply addition on them and in the end save sum in nsnumber object
Hope it helps

Concatenate variable IBOutlet inside a loop? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have 13 textfield and I need to modify their values ​​according to the parameters received from an array inside a loop:
IBOutlet UITextField *c1_1;
....
IBOutlet UITextField *c1_13;
int xis;
int xis2;
for(xis=0;xis<14;xis++){
xis2++;
[NSString stringWithFormat:#"c1_%d.text",xis2] = lstaInfo[xis];
}
But the command is not working, I wish you could explain to me the possible solutions to this problem
Oh lordy. You have tons of problems.
You don't initialize xis2, but then you increment it. It may contain random garbage.
You try to assign something to a call to stringWithFormat. That is not valid Objective C. Should you flip the left and right sides of that assignment?
lstaInfo[xis] = [NSString stringWithFormat:#"c1_%d.text",xis2] ;
You also say "the command is not working" without either telling what you are trying to do, or how your code fails to accomplish that task.
You need to provide a much clearer explanation if you actually want help. (but fix the above problems first)
This isn't the right way to do this. You want an IBOutletCollection.

Check if object created: good style? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I recently did some functions like the following one:
-(BOOL)registerSomethingWithParameter:(Parameter*) param
{
Something* some = nil;
if ([self checkParameter:param])
{
some = [[Something alloc] myInitCallWithParameter:param];
}
return (some ? YES : NO);
}
There are many discussions about using the ? in code. What do you think? Is this a proper way to tell the calling function, that everything worked well without returning an object?
I also thought about: isn't it better to check for valid parameter in myInitCallWithParameter: within the Something-Definition, but mostly these Classes are very small and store only a few values. So everything that could result in creating a nil is checked when entering the if.
I don't think there's any problem in using ? instead of if/else. I see a lot of programmers using it and I use it myself. Your code style is fine.
Why not just do:
-(BOOL)registerSomethingWithParameter:(Parameter*) param
{
return [self checkParameter:param];
}
I'm assuming checkParamter returns a bool. In which case you don't even need this registerSomethingWithParameter function as it just creates a local variable that isn't used anywhere anyway ? Unless you've just written this as an example. :-)
While your approach is perfectly viable, a better option might be to simply return the created object itself; like so:
-(id)registerSomethingWithParameter:(Parameter*) param
{
Something* some = nil;
if ([self checkParameter:param]) {
some = [[Something alloc] myInitCallWithParameter:param];
[self registerSomething:some];
}
return some;
}

Can the ternary operator be used outside of assignment statements in Objective-C? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I know setting a variable conditionally is valid:
someProperty = [anObject aFunctionThatReturnsBool]? #"Yes" : #"No";
This question has an answer that details the use of ternary statements in preprocessor macros
#define statusString (statusBool ? #"Approved" : #"Rejected")
and within a string formatting method
[NSString stringWithFormat: #"Status: %#", (statusBool ? #"Approved" : #"Rejected")]
But what about within any method?
[NSNumber numberWithInt:(aVariableThatCouldBeSet)? 100 : 0)];
And conditional method calling?
[anObject aFunctionThatReturnsBool]? [self doThis] : [self doThat];
Bonus points for any other uses not listed.