So I have a chunk of code that does some magic with a query and gives me a variable called JSONresult
which has been told to run in it's own thread. Once I get this result, I would like take that variable from that thread and make it so that when an IBAction
method is called on (triggerd by a button press) if data in the variable JSONresult
exists that it will display it in an NSTextView
.
So far I've been able to get the data to appear in an NSTextView
if I specify the data manually within the IBAction
method, but trying to use the JSONresult
variable doesn't work for obvious reasons.
Here is what I've got so far.
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
[NSThread detachNewThreadSelector:@selector(getJSONquery) toTarget:self withObject:nil];
}
-(void)getJSONquery {
[[NSThread currentThread] setName:@"Get JSON Query"];
//Some fancy stuff here
NSArray *JSONresult = [string componentsSeparatedByString:@"<|...|>"];
}
After all this has happened and I've now got my JSONresult
I have an IBAction
setup so that if the button is pushed, the JSONresult
will be taken and displayed in a NSTextView
-(IBAction)showContent:(id)sender {
[content setString:JSONresult];
}
How would I go about passing the variable JSONresult
between the two threads/methods?
Thanks in advance! :)
Also if I should update this post with the header file please let me know. I'm new to the world of Objective C and have a very bad understanding of the general how-to so I don't know whether it's relevant to this situation or not