Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Draque

macrumors newbie
Original poster
Jan 6, 2015
7
0
I'm collecting a string value in a method of my app, and as it closes, I need to pass the value back to the top level main. The reason for this is because I need to spawn a thread in a manner that can only be done from main.

Is there a way to do this? Since I am calling NSAplicationMain immediately, there doesn't seem to be a way to access the class representing my program from there.
 

briloronmacrumo

macrumors 6502a
Jan 25, 2008
534
343
USA
Seems like you need to learn the basics of Cocoa

A method can return an NSString, so a method called from main ( or applicationDidFinishLaunching: or whereever ) could use the returned string. Some consideration will be required for retention of the string ( and the use ( or not ) of ARC is a consideration too )

If you post code it will be much easier to respond instead of guessing how ( and from where ) the method is called. Programming requires effort and that includes providing information in posts. Otherwise it's GIGO.


Code:
-(NSString *)methodThatCollectsStringValue {
    
    NSString *someString = blah_blah; // do "collection" of string here. Need to consider string retention.
    return someString;
}
 
Last edited:

mfram

Contributor
Jan 23, 2010
1,321
361
San Diego, CA USA
Put a global variable in the main file. Declare an external global variable in your file where you want to write the variable. This is basic C.

I assume this would work, but I haven't tried it.
 

Draque

macrumors newbie
Original poster
Jan 6, 2015
7
0
Thanks for the replies, guys!

I did find a solution to this, but unfortunately neither of those ones would work for me. The string is passed to a delegate class, and the NSAplicationMain() method abstracts away my ability to directly call the program's active class directly.

What I ended up doing was making a two pass system, where the first pass runs a cocoa program whose only purpose is to collect the value of the double clicked file, then starts the second executable, passing the collected values and killing itself.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.