TTURLMap with query strings ? (NSNull length error) - ios

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

Related

How to get UIImage from NSDictionary in objective c

I have searched more and more but didn't get the perfect solution.
I have saved an image in a dictionary.
#{
......
#"PrdImg":[UIImage imageNamed:[image objectAtIndex:indexPath.row]
......
};
The image data saved perfectly. I checked it.
But when I want to get this data from the dictionary then an exception encountered. The retrieving code is giving below.
PoctImage.image = [UIImage imageNamed:PrdDetailsDic[#"PrdImg"]];
The encountered exception is -
'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x7f9428e4e930'
I have also read more document about the exception. But didn't get the specific solution.
Now I want to know how can I get the image data from the dictionary. What is the specific syntax for getting the image from the dictionary.
The initializer UIImage imageNamed: is looking for the image in your main bundle, and since you've got it in a dictionary it won't find it. If you're actually storing a UIImage in the dictionary, why not just say...
PoctImage.image = PrdDetailsDic[#"PrdImg"];
I also suspect there's an issue with trying to save an image to the dictionary in the way you specify, for the same reason. It seems like that one should be...
#{
......
#"PrdImg":[image objectAtIndex:indexPath.row];
......
};

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.

Need help understanding a conditional crash when accessing my NSDictionary

I am keeping my data in a property called practiceRecords (an NSArray of dictionaries).
I check to see if the data already exists in the documents folder.
If yes, I load the data into self.practiceRecords.
If not, I build the array of dictionaries (using literal syntax), keeping this data in the self.practiceRecords property, and then write the data out to the documents folder.
(I am NOT reloading the data after writing it out)
As far as I am able to tell, there are no problems occurring during this process.
Then I have a step where I modify my data as follows ...
-(void)incNumberOfTriesFor:(NSString *)stringOfIndex {
if (self.practiceRecords)
{
int index = [stringOfIndex intValue];
int numberOfTries = [(NSNumber *)(self.practiceRecords[index][#"tries"]) intValue] + 1;
//CRASHING on this next line.
self.practiceRecords[index][#"tries"] = #(numberOfTries);
//message to helper method
[self writePracticeRecords];
}
}
So the first time through (when the array is built and written out) I get a crash at the indicated line.
The error is:
-[__NSDictionaryI setObject:forKeyedSubscript:]: unrecognized selector sent to instance
I quit the app, check the documents folder and see the data file written out with no issues.
I re-run the app, and then get no crash and the data file still looks great.
This is repeatable.
If the data file exists, no crash.
If the data first needs to be created, then a crash.
(In all cases, I manually look inside the resulting data file and see exactly what I expect to see - no issues there)
I'm not sure where to even begin squashing this bug, and would really like to understand the details of why this is happening.
Thanks very much for any help!
Just to recap the correct comments above:
-[__NSDictionaryI setObject:forKeyedSubscript:]: unrecognized selector sent to instance
NSDictionary does not implement any of the set... methods because it is immutable. You state that you're creating with literals syntax when the data is not found on disk. The literal syntax creates immutable containers
Instead, try...
// try to initialize from disk, but if not
// we can still use literal (immutable) syntax, but in a mutable container
self.practiceRecords = [NSMutableDictionary
dictionaryWithDictionary:#{ #"key" : #"value" }];

RaptureXML iterate:usingBlock warning and crash

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!!

JSON: NSString stringWithContentsOfURL... with null in stream, crashes

Environment: iOS 4.3+ using Xcode 4.3+
I'm always getting an iOS/Xcode crash when I implement the following string that returns data with nulls in it:
[NSString stringWithContentsOfURL:myURL encoding:NSUTF8StringEncoding error:&error];
NSDictionary *myResult = (NSDictionary *)[myString JSONValue];
The result:
-[NSNull isEqualToString:]: unrecognized selector sent to instance 0x17315e8
When the data stream contains no nulls (mostly), it works fine.
Is this a known problem?
Any remedy?
You can also fix the data coming in from the source. In almost all of my web service interaction, I use COALESCE on queries and SP's to make sure that the data coming out is always consistent.

Resources