Is there a way to dynamically create a variable name. Like I pass a string into a method and the method creates an NSString whos name is the string that was passed in. Something like
Is there a way to dynamically create a variable name. Like I pass a string into a method and the method creates an NSString whos name is the string that was passed in. Something like
Why do you want to do this? Variable names are compiled away, and by the time your program runs, you can't see them any more (except in the debugger, if you save symbols.)
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
So that javascript files can pass in a string a create variables in objective-c.
Objective C is a compiled language. You can't create variables at runtime in a compiled language.
The best you're going to be able to do is to use a dictionary and use the JavaScript variable name as a key to the dictionary. If you want to save numeric values, you'll need to save them as NSNumber objects.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.
The app has a javascript portion to it and the guy working on the javascript wants to ensure he can make changes and update to the app after I leave. So he wants to be able to send variables to the objective-c code so that they can be saved with NSUserDefaults.
The app has a javascript portion to it and the guy working on the javascript wants to ensure he can make changes and update to the app after I leave. So he wants to be able to send variables to the objective-c code so that they can be saved with NSUserDefaults.
You can't create or rename variables dynamically in a compiled language like Objective C (or C, or C++). Not possible. I promise.
If the goal is to save them to user defaults, use a dictionary. That is perfect for this application. You can then either save the dictionary to user defaults as a single object, or copy the objects out of the dictionary into user defaults. Saving the dictionary as an object probably makes more sense because then you can keep the objects added from JavaScript separate from other things your program saves to user defaults.
Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.