external NSString from NSDictionary string item
-
28-06-2021 - |
Question
I have a PList with strings and a dictionary. I am loading it in to an NSDictionary object, that much I've worked out fine. What I'm stuck with is getting a string entry from the NSdictionary object in to an external string, because by the time the external variable references the object (gotten with "ObjectByKey") from a separate class, the NSDictionary is no longer anywhere to be found. My question is, how do I get a string from an NSDictionary as a static string - not as a reference to an NSDictionary string entry? Below is my code:
loginGlobals.h
extern NSString *loginError;
LoginProcessorViewController.m
NSDictionary *responseData = [NSPropertyListSerialization propertyListFromData:plistData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&error];
loginError = [responseData objectForKey:@"Error"];
and then the error comes up (EXC_BAD_ACCESS) when I do this in loginViewController.m:
loginErrorLabel.text = loginError;
Solution
Retain the loginError
object
loginError = [[responseData objectForKey:@"Error"] retain];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow