I am a newbie on iOS development, so I find no clue when error like this, the code is like:
- (void)postToWall {
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
autorelease];
dialog.userMessagePrompt = #"Enter your message:";
dialog.attachment = [NSString
stringWithFormat:#"{\"name\":\"Facebook Connect for
iPhone\",\"href\":\"http://developers.facebook.com/
connect.phptab=iphone\",\"caption\":\"Caption\",
\"description\":\"Description\",\"media\":[{\"type\":
\"image\",\"src\":\"http://img40.yfrog.com/img40/
5914/iphoneconnectbtn.jpg\",\"href\":
\"http://developers.facebook.com/connect.php?
tab=iphone/\"}],\"properties\":{\"another link\":
{\"text\":\"Facebook home page\",\"href\":
\"http://www.facebook.com\"}}}"];
[dialog show];
}
I am trying to learn from a online tutorial about facebook connect, so I got this error in the code and the file includes:
import "FBSession.h"
import "FBLoginButton.h"
Do you think it could be this causes the problem?
Either write the string in a single line, or add " to the end and beginning of each line:
dialog.attachment = [NSString
stringWithFormat:#"{\"name\":\"Facebook Connect for"
"iPhone\",\"href\":\"http://developers.facebook.com/"
"connect.phptab=iphone\",\"caption\":\"Caption\","
"\"description\":\"Description\",\"media\":[{\"type\":"
"\"image\",\"src\":\"http://img40.yfrog.com/img40/"
"5914/iphoneconnectbtn.jpg\",\"href\":"
"\"http://developers.facebook.com/connect.php?"
"tab=iphone/\"}],\"properties\":{\"another link\":"
"{\"text\":\"Facebook home page\",\"href\":"
"\"http://www.facebook.com\"}}}"];
Also, note that in this case you don't need to use stringWithFormat, you can create the string like this:
dialog.attachment = #"{\"name\":\"Facebook Connect for"
"iPhone\",\"href\":\"http://developers.facebook.com/"
"connect.phptab=iphone\",\"caption\":\"Caption\","
"\"description\":\"Description\",\"media\":[{\"type\":"
"\"image\",\"src\":\"http://img40.yfrog.com/img40/"
"5914/iphoneconnectbtn.jpg\",\"href\":"
"\"http://developers.facebook.com/connect.php?"
"tab=iphone/\"}],\"properties\":{\"another link\":"
"{\"text\":\"Facebook home page\",\"href\":"
"\"http://www.facebook.com\"}}}";
The only thing apparently wrong with the code you've posted is all of the line breaks in the middle of your long string. Also, using stringWithFormat is not necessary there. Also your first 'href' is missing a '?' from the GET query. So try this and see what happens:
dialog.attachment = #"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
Or better yet, break all of your keys and values out into their own NSStrings and put the long string back together using stringWithFormat. Or even BETTER, create the whole thing in memory and use NSJSONSerialization to create your JSON string. It will be much cleaner and less prone to errors.
I could be wrong but i think facebook excepts a dictionary of values for each of those keys.
There example code is very good and well documented.
Try replacing " with ' inbetween the start and end of the string.
Related
Sorry for title. I don't know what to write.
This is my problem:
If i write this is all ok:
$obj_license = License::where('licenses.company_id',$company->id)->first();
But this throw an error:
$license='License';
$obj_license = $license::where('licenses.company_id',$company->id)->first();
ERROR: Class 'Butchery_license' not found
This is just an example. I really need to have the second way working. There is a solution?
Try to use full path to a class:
$license='App\License';
$obj_license = $license::where('licenses.company_id',$company->id)->first();
I'm following a tutorial(http://youtube.com/watch?v=xvvsG9Cl4HA 19 min 20sec) and to make his code look neat he puts some on a ew line like this
if let myPlacement = myPlacements?.first
{
let myAddress = "\(myPlacement.locality) \
(myPlacement.country) \
(myPlacement.postalCode)"
}
. But when I try I get an error
unterminated string literal
and
consecutive statements on a line must be seperated by a ';'
but the guy in the tutorial has done it the exact same way. What's going on?
I'm using the latest swift and and latest xcode 7.2 any help would be apreciated
if I write everything on the same line like this
if let myPlacement = myPlacements?.first
{
let myAddress = "\(myPlacement.locality) \(myPlacement.country) \(myPlacement.postalCode)"
}
it works fine though
if I write everything on the same line like this
Well, there's your answer. You are not permitted to break up a string literal into multiple lines as you are doing in your first example. There are languages that permit this, but Swift is not one of them. This is not legal:
let s = "hello
there"
There is no magic line-continuation character which, placed at the end of the first line, would make that legal.
If the window is narrower than the line, the editor may wrap the line, for display purposes; but you cannot put actual line breaks inside a string literal.
You can work around this by combining (concatenating) multiple string literals, if you think that makes for greater legibility. This, for example, is legal:
let myAddress = "\(myPlacement.locality) " +
"\(myPlacement.country) " +
"\(myPlacement.postalCode)"
I look your video tutorial carefully. You have a misunderstanding here.
You must pay attention to the video, the code in this picture is not break lines because he add a return here, it is because his screen is too narrow.
So, the real code is
let myAddress = "\(myPlacement.locality) \(myPlacement.country) \(myPlacement.postalCode)"
Please watch it carefully.
And you may need know first, \ in \(myPlacement.locality) is a escape character, it means to get the value of myPlacement.locality and put in the string.
NSSet *subFolders = [_account subscribedFolders];
NSLog(#"subFolders: %#",subFolders);
Output:
...
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea",
"[Gmail]/\U05d7\U05e9\U05d5\U05d1"
...
Is there any way I can show the above text in its original language (Hebrew) ?
Things I tried:
changing the debugger from LLDB to GDB - Didn't work
Checking under preferences -> Text Editing UTF-* is selected
Thanks
There is no issue with displaying unicode characters in the console, so I would assume it's the way the string is getting into the set in the first place.
I would suggest iterating over all the objects inside subFolders with something like:
for( id object in [subFolders allObjects] ) {
//Print out the name of the item explicitly
}
Even if this doesn't work, it at least lets you work with the strings directly. If it's still printing out:
"[Gmail]/\U05d8\U05d9\U05d5\U05d8\U05d5\U05ea"
It would look as if you're being sent escaped unicode characters, and I would suggest this: https://stackoverflow.com/a/7861345/352891 - this may work directly on NSSet's description
NSString* strOld=[NSString stringWithFormat:#"%#",responseObject];
NSLog(#"%#",[NSString
stringWithCString:[strOld cStringUsingEncoding:NSUTF8StringEncoding]
encoding:NSNonLossyASCIIStringEncoding]);
I have a string (from HTTP Header) and want to split it into a dictionary.
foo = \"bar\",baz=\"fooz\", beta= \"gamma\"
I ca not guarantee that the string is the same every time. Maybe there are spaces, maybe not, sometimes the double quotes are escaped, sometimes not.
So I found the solution in PHP with regular expressions. Unfortunately I can't convert it to work on iOS.
preg_match_all('#('.$key.')=(?:([\'"])([^\2]+?)\2|([^\s,]+))#', $input, $hits, PREG_SET_ORDER);
foreach ($hits as $hit) {
$data[hit[1]] = $hit[3] ? $hit[3] : $hit[4];
}
Can anybody help me converting this to Objective-C?
I met a guy which is kinda RegEx guru. He explained the whole stuff and I got the following (working!!!!) solution in RegEx.
This gives me strings like foo="bar":
(?<=[,\\s])((realm|qop|nonce|opaque)=(?:([\"'])([^\2]+?)\2|([^\\s,]+)))
I then use another RegEx to split it by key and value to create a dictionary.
Need to separate a string on & but not on &.
Is there a more elegant way to code this up rather than just replacing it first then separating it on the &? Like this...
query = [query stringByReplacingOccurrencesOfString:#"&" withString:#"~~~"];
NSArray * kvpairs = [query componentsSeparatedByString:#"&"];
NSMutableArray *mArr = [[NSMutableArray alloc] init];
for (NSString *kvp in kvpairs) {
[mArr addObject:[kvp stringByReplacingOccurrencesOfString:#"~~~" withString:#"&"]];
}
kvpairs = [NSArray arrayWithArray:mArr];
[mArr release];
You could use NSRegularExpression to enumerate through the string on a regular expression that matches & but not &, e.g.: #"&(?!amp;)". This will be more cumbersome than your current method but more exact, because it will work without modifying the original string and doesn't rely on a token value.
If you control the input to this method and can guarantee that ~~~ won't appear normally, there's nothing wrong with using ~~~. However if you don't control the input then you should attempt to parse the string without modification.
There isn't really anything wrong with that, as long as you are 100% sure that the string ~~~ won't occur in your query.
If you are not, my next step would be to implement a method to parse the string into an array. In this method, you could find each &, then check if it is followed by amp;. If it is, move on to the next one, if it is not, cut the string there and repeat.
HTML entities and references are really not a good thing to have hanging around in URLs. Unless there is a very good reason that HTML entities must be used, I would recommend using '%26' in the URL encode an ampersand.
That being said, you will run into problems if '&' is not the only HTML entity or reference, so unless you are absolutely sure '&' is the only one, you will need a more robust solution.