RaptureXML iterate:usingBlock warning and crash - ios

I'm parsing an XML file which looks like this:
<partie numero="1">
<exercice numero="1" libelle="blabla"></exercice>
<exercice numero="2" libelle="anything"></exercice>
</partie>
I'm using the Rapture XML Library, so as explained on GitHub, I do the following :
RXMLElement *rxmlPartie = [rxmlParties child:#"partie"];
NSArray *rxmlUnExercice = [rxmlPartie children:#"exercice"];
I can print correctly the "numero" attribute from partie with this line :
NSLog(#"Partie #%#",[rxmlPartie attribute:#"numero"] );
But when I try to use the iterate method on my NSArray :
[rxmlPartie iterate:#"partie.exercice" usingBlock: ^(RXMLElement *exercice) {NSLog(#"Exercice: %# (#%#)", [exercice attribute:#"libelle"], [exercice attribute:#"numero"]);}];
I get a warning, and the the application crash, saying :
-[RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '- [RXMLElement iterate:usingBlock:]: unrecognized selector sent to instance 0xc67f870'
Did I forget to import something, or do I implement the method in a bad way?
The same error happens if i try to use iterateWithRootXPath...
Thanks for your help!!

So, I found out what was my problem.
I didn't know anything about paring with Rapture XML before doing this...So I sticked to the doc (as somebody told me in school :-) ). But the problem was that a method used in the doc, this "iterate usingBlock" is not defined in the framework.
Instead of using
[rxmlPartie iterate:#"partie.exercice" usingBlock: ^(RXMLElement *exercice) {NSLog(#"Exercice: %# (#%#)", [exercice attribute:#"libelle"], [exercice attribute:#"numero"]);}];
I'm using
[rxmlPartie iterate:#"exercice" with: ^(RXMLElement *exercice) {NSLog(#"Exercice: %# (#%#)", [exercice attribute:#"libelle"], [exercice attribute:#"numero"]);}];
Which is well defined within the framework!
It made my day!!

Related

Core Data unable to generate where clause for predicate (Swift)

I have a Core Data managed object with an NSNumber property (stored as Integer 64). I'm attempting to retrieve an object using a predicate object as follows:
let request = NSFetchRequest(entityName: "MyEntity")
request.predicate = NSPredicate(format: "pageId == %#", pageId)
when then causes the following run-time error :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to generate where clause for predicate (pageId == 22205021) (unknown problem)'
where the pageId is "22205021" in this instance. As far as where clauses go it looks OK, namely, pageId == 22205021 so I don't understand why it won't work.
Note: I'm using Xcode 7 beta 4.
Actually this turned out to be my fault - I was using a non-existent property for that object in the predicate. "MyEntity" did not contain a "pageId" - a better error message would not go amiss though.
pageId may not actually be an NSObject when in Swift.
Try NSPredicate(format: "pageId == %d", pageId).
That uses an integer to compare and not an NSNumber.
The code you posted looks correct to me. If the code works in the previous Xcode and there's no other changes (except for conformance) I'd consider that it may be a reportable bug.

Unable to append String NSMutableString - Error

I have the following code
NSMutableString *ibmcountryCodeLabel=[[NSMutableString alloc]init];
NSMutableString *imobileNumberValue=[[NSMutableString alloc]init];
ibmcountryCodeLabel=#"555";
imobileNumberValue=#"333";
NSLog(#"Done1");
[ibmcountryCodeLabel appendString:imobileNumberValue];
NSLog(#"Done2");
Though both the string are mutable when I try to append one with another I am getting "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Attempt to mutate immutable object with appendString:'"
read through all the threads. But not able to find a solution. Kindly help me. Thanks for your time
Here is the problem: this assignment produces a mutable string object:
NSMutableString *ibmcountryCodeLabel=[[NSMutableString alloc]init];
After this assignment, however, the object pointed to by ibmcountryCodeLabel is no longer mutable:
ibmcountryCodeLabel=#"555";
This is because the #"555" constant is an immutable subclass of NSString. Trying to modify it leads to runtime errors.
Change the code as follows to fix this problem:
NSMutableString *ibmcountryCodeLabel=[NSMutableString stringWithString:#"555"];
NSMutableString *imobileNumberValue=[NSMutableString stringWithString:#"333"];

How to resolve a NULL cString crash

I'm getting a crash with the following encoding fix I'm trying to implement:
// encoding fix
NSString *correctStringTitle = [NSString stringWithCString:[[item objectForKey:#"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding];
cell.titleLabel.text = [correctStringTitle capitalizedString];
my crash log output states:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[NSString stringWithCString:encoding:]: NULL cString'
thanks for any help
You seem to think that a double conversion is necessary in order to get the correct result. It isn't, nor is it possible (that's why the call to cStringUsingEncoding:NSISOLatin1StringEncoding returns NULL). Just leave this part out and assign to correctStringTitle directly.
I had the same problem with italian accented characters while trying to get text from html and my solution to avoid the situation that cStringUsingEncoding:NSISOLatin1StringEncoding returns NULL is ensuring that when you get the html from data you use:
[[NSString alloc] initWithData:self.responseData encoding:NSISOLatin1StringEncoding]
and not
encoding:NSUTF8StringEncoding

append a NSString converted from dictionary object to NSMutableArray

I have been bothered by this problem for a long time.
I have a NSString which is the received from a RSS parser, I can successfully NSlog it on the screen, but when I try to append it to an existing NSmutablearray, it causes exception.
Here is my code.
//mystring is a NSMutableString with some content initialized succesfully
NSString *myDate = [dic objectForKey:#"date"];
NSLog(#"%# and %#",myString,myDate);
[myString appendString:myDate];
until the NSLog, both myDate and myString are printed on screen correctly as I desire, but the appendString line causes error
[_NSDate length]: unrecognized selector sent to instance 0*7141a00
Terminating app due to uncaught exception 'NSInvalidArgumentException', reasons: '-[__NSDate length]: ..........
Could someone please help me?
You're calling -appendString: with myDate, which isn't a string. It's an NSDate. You can't pass it to an API that expects a string. You need to convert it into a string somehow. This is probably best done using NSDateFormatter, which gives you full control over how to format your date as a string.
For testing purposes though, you can just replace your last line with [myString appendString:[myDate description]] and it should stop crashing.

TTURLMap with query strings ? (NSNull length error)

I'm using three20 in my project and I'm trying to add this route to my url mapping :
[map from:#"onefeat://missions?(initWithArgs:)"toSharedViewController:[MissionListController class]];
But the app fails at launch with an -[NSNull length]: unrecognized selector sent to instance 0x2a10cd8 error.
Isn't there anyway to have a catchall url and then parse the query myself ?
Thanks for your help !
You should use something like this:
[map from:#"onefeat://missions?missions=(initWithArgs:)" toSharedViewController:[MissionListController class]];
For an extensive list of samples you can see the TTNavigatorDemo demo under the samples folder in three20

Resources