Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-25-2012, 12:53 PM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default Issue with too many arguments in Twitter API?

So basically i am trying to incorporate the new twitter framework in my app. I can manage to sucessfully "tweet" using the following code:
Code:
[twitter setInitialText:@"my first tweet"];
I am trying to let the user to be able to tweet their high/previous scores with the following code:
Code:
    [twitter setInitialText:@"I just got", lastScore.text, @"on myappname"];
but it says that i have too many arguments? This may just be me being stupid but any help is appreciated

Thanks in advance!
jimmymacapps is offline   Reply With Quote
Old 01-25-2012, 01:38 PM   #2 (permalink)
Use [code] tags please
 
Join Date: Jun 2009
Location: Jacksonville, FL
Posts: 410
timle8n1 is on a distinguished road
Default

Quote:
Originally Posted by jimmymacapps View Post
So basically i am trying to incorporate the new twitter framework in my app. I can manage to sucessfully "tweet" using the following code:
Code:
[twitter setInitialText:@"my first tweet"];
I am trying to let the user to be able to tweet their high/previous scores with the following code:
Code:
    [twitter setInitialText:@"I just got", lastScore.text, @"on myappname"];
but it says that i have too many arguments? This may just be me being stupid but any help is appreciated

Thanks in advance!
NSString stringWithFormat is your friend.
timle8n1 is offline   Reply With Quote
Old 01-25-2012, 01:55 PM   #3 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default

Thanks for the quick reply!
Would you be able to give me any starters on this?
jimmymacapps is offline   Reply With Quote
Old 01-25-2012, 02:12 PM   #4 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

What you are doing here

Code:
[twitter setInitialText:@"I just got", lastScore.text, @"on myappname"];
is passing list of three arguments to setInitialText. That's why you get the error message.

If you have a look at the documentation about NSString here
you will find out that you can concatenate string either by appending them or by creating a string with a specified format.

The first option would be
Code:
[twitter setInitialText:[[@"I just got " stringByAppendingString:lastScore.text] stringByAppendingString:@" on myappname"]];
which is not so convenient

And the second option would be

Code:
[twitter setInitialText:[NSString stringWithFormat:@"I just got %@ on myappname", lastScore.text]];
Where %@ gets replaced by lastScore.text.
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-25-2012, 02:17 PM   #5 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default

Thanks very much!
That worked a treat!
jimmymacapps is offline   Reply With Quote
Old 01-25-2012, 02:21 PM   #6 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by apatsufas View Post
What you are doing here

Code:
[twitter setInitialText:@"I just got", lastScore.text, @"on myappname"];
is passing list of three arguments to setInitialText. That's why you get the error message.

If you have a look at the documentation about NSString here
you will find out that you can concatenate string either by appending them or by creating a string with a specified format.

The first option would be
Code:
[twitter setInitialText:[[@"I just got " stringByAppendingString:lastScore.text] stringByAppendingString:@" on myappname"]];
which is not so convenient

And the second option would be

Code:
[twitter setInitialText:[NSString stringWithFormat:@"I just got %@ on myappname", lastScore.text]];
Where %@ gets replaced by lastScore.text.
Suggestion:

Write an abstract explanation that tells the OP how to do it, but do not provide the exact code.

The OP will not learn as much (anything?) if he/she can just copy and paste code you've written into place.

If you post sample code, write it in general form, not an exact solution to the poster's question.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-25-2012, 02:26 PM   #7 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default

Quote:
Originally Posted by apatsufas View Post
What you are doing here

Code:
[twitter setInitialText:@"I just got", lastScore.text, @"on myappname"];
is passing list of three arguments to setInitialText. That's why you get the error message.

If you have a look at the documentation about NSString here
you will find out that you can concatenate string either by appending them or by creating a string with a specified format.

The first option would be
Code:
[twitter setInitialText:[[@"I just got " stringByAppendingString:lastScore.text] stringByAppendingString:@" on myappname"]];
which is not so convenient

And the second option would be

Code:
[twitter setInitialText:[NSString stringWithFormat:@"I just got %@ on myappname", lastScore.text]];
Where %@ gets replaced by lastScore.text.
I have one other question with regards to fbconnect. Basically i am trying to do the same thing as twitter (be able to post high/latest scores) and i have the same sort of problem with the following code:
Code:
         NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"app name", @"name",
                                       @"app caption", @"caption",
                                       @"I just got %@ on myappname", lastScore.text, @"description",
                                       @"applink", @"link",
                                       nil];
        
        [[facebook] dialog:@"feed"
                             andParams:params
                           andDelegate:self];
my error code is:
Code:
NSInvalidArgumentException', reason: '+[NSMutableDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil.
it would be much appreciated if you could help me with this as well!
Thanks again!
jimmymacapps is offline   Reply With Quote
Old 01-25-2012, 02:35 PM   #8 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jimmymacapps View Post
I have one other question with regards to fbconnect. Basically i am trying to do the same thing as twitter (be able to post high/latest scores) and i have the same sort of problem with the following code:
Code:
         NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"app name", @"name",
                                       @"app caption", @"caption",
                                       @"I just got %@ on myappname", lastScore.text, @"description",
                                       @"applink", @"link",
                                       nil];
        
        [[facebook] dialog:@"feed"
                             andParams:params
                           andDelegate:self];
my error code is:
Code:
NSInvalidArgumentException', reason: '+[NSMutableDictionary dictionaryWithObjectsAndKeys:]: second object of each pair must be non-nil.
it would be much appreciated if you could help me with this as well!
Thanks again!

Ok, lets think. You just learned that you can't pass multiple parameters in place of a single parameter. You have to combine substrings. The OP told you that to create a combined string, you could use a temporary string:

Code:
NSString *tempString = [NSString stringWithFormat: @"The other string is %@", otherString];
You could then pass in tempString as a single parameter.

In your code:


Code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  @"app name", @"name",
  @"app caption", @"caption",
  @"I just got %@ on myappname", lastScore.text, @"description",
  @"applink", @"link",
  nil];
The call to dictionaryWithObjectsAndKeys needs


Code:
value, key,
value, key,
value, key,
nil;
Are you passing in pairs of strings and values? No. You're making the same mistake with

Code:
@"I just got %@ on myappname", lastScore.text

You need to create a temp string in the line before you build your dictionary, and use stringWithFormat to fill it with the combined string you want to put in the "description" key value pair.

This time see if you can work out the code for yourself.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-25-2012, 02:44 PM   #9 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Ok, lets think. You just learned that you can't pass multiple parameters in place of a single parameter. You have to combine substrings. The OP told you that to create a combined string, you could use a temporary string:

Code:
NSString *tempString = [NSString stringWithFormat: @"The other string is %@", otherString];
You could then pass in tempString as a single parameter.

In your code:


Code:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
  @"app name", @"name",
  @"app caption", @"caption",
  @"I just got %@ on myappname", lastScore.text, @"description",
  @"applink", @"link",
  nil];
The call to dictionaryWithObjectsAndKeys needs


Code:
value, key,
value, key,
value, key,
nil;
Are you passing in pairs of strings and values? No. You're making the same mistake with

Code:
@"I just got %@ on myappname", lastScore.text

You need to create a temp string in the line before you build your dictionary, and use stringWithFormat to fill it with the combined string you want to put in the "description" key value pair.

This time see if you can work out the code for yourself.
Thanks very much for all of your help!!!!!!
For anybody who wants to know the code that i used is:
Code:
    NSString *tempScoreString = [NSString stringWithFormat: @"I just got %@ on myappname !!!", lastScore.text];
Thanks again!
jimmymacapps is offline   Reply With Quote
Old 01-25-2012, 02:45 PM   #10 (permalink)
Registered Member
 
apatsufas's Avatar
 
Join Date: Jan 2011
Location: Thessaloniki, Greece
Posts: 121
apatsufas is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Suggestion:

Write an abstract explanation that tells the OP how to do it, but do not provide the exact code.

The OP will not learn as much (anything?) if he/she can just copy and paste code you've written into place.

If you post sample code, write it in general form, not an exact solution to the poster's question.
Note taken. I will keep that in mind.
__________________
SQLed - Your Database Manager on the go

iAZConverter - Converts everything from A to Z
apatsufas is offline   Reply With Quote
Old 01-25-2012, 02:54 PM   #11 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by jimmymacapps View Post
Thanks very much for all of your help!!!!!!
For anybody who wants to know the code that i used is:
Code:
    NSString *tempScoreString = [NSString stringWithFormat: @"I just got %@ on myappname !!!", lastScore.text];
Thanks again!
Woo hoo! I believe the man learned something! Wasn't that better than a cut-and-paste solution?
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is offline   Reply With Quote
Old 01-25-2012, 03:03 PM   #12 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 63
jimmymacapps is on a distinguished road
Default

Quote:
Originally Posted by Duncan C View Post
Woo hoo! I believe the man learned something! Wasn't that better than a cut-and-paste solution?
Yes, definitely! suppose I'm just too impatient! haha
Thanks again!
jimmymacapps is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 392
11 members and 381 guests
Atatator, condor304, FrankWeller, glenn_sayers, iphonedevshani, MAMN84, mraalex, PowerGoofy, QuantumDoja, tim0504, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,674
Threads: 94,123
Posts: 402,908
Top Poster: BrianSlick (7,990)
Welcome to our newest member, Atatator
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:53 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0