Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

iPhone: pass variables by reference to sub-contexts

Hi,

Can someone please confirm that on the latest version of the SDK for iPhone (1.4.2 as of now), the variables passed to sub-contexts are passed as value instead of as reference ?

I've been struggling with this feature for Android (and had to upgrade to a 1.5 snapshot) and now everything suggests that the iPhone SDK has the same problem.

I'd like to avoid having to use events to update variable values between my different contexts… ;-)

Thank you.

— asked November 23rd 2010 by Etienne Bernard
  • contexts
  • iphone
  • reference
  • variables
0 Comments

2 Answers

  • Not sure what you mean by "value instead of reference" in this case with regard to windows (I'm assuming we're talking variables passed to a window on creation, as in this example). What are you getting in your window variable that you don't expect?

    If separate contexts are becoming a problem for you, consider ditching them altogether and breaking up your code using Ti.include - we generally do all our pro services apps in a single context.

    — answered November 23rd 2010 by Kevin Whinnery
    permalink
    0 Comments
  • I mean that I can access my variables in the subcontexts, but any update to their value is not "propagated".

    If I refer to the documentation (http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.UI.Window-object#passing_data), "Since b is a reference (vs. a copy by value), any changes made to these Javascript references will be immediately available in all sub-contexts." the changes to the variable should be availables in the sub-contexts.

    This is not the case on Android with 1.4 (but 1.5 fixes the problem), and as it seems it doesn't work either with iPhone and 1.4.2.

    I'll study the option to use just one single context.

    — answered November 23rd 2010 by Etienne Bernard
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.