Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8060483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:00:27+00:00 2026-06-05T10:00:27+00:00

I’m writing a Javascript class that passes a function with one parameter to an

  • 0

I’m writing a Javascript class that passes a function with one parameter to an Objective-C class (Using the NimbleKit framework). It does this like so:

NKRegisterClass("SKGetEvents");    
// TEMP Test date sent to the NKitAction, won't be hardcoded
var testDate = "2011-10-14"; 
var goButton = new NKButton();
goButton.init(100,20,100,50,"callGetEvents(testDate)"); /*Button to launch function */
goButton.setTitle("Get Events");
goButton.show();

function callGetEvents(testDate) {
    CallNKitAction("GetEventsFunction?className=SKGetEvents&dateStringInput="+testDate);
}

So it will call an registered Objective-C class function using CallNKitAction, passing a
javascript string (in this case var testDate = “2011-10-14”) as the argument.
The responding function in the Objective-C class doesn’t get called at all. It looks like this:

-(NSString *) GetEventsFunction:(const char *)dateStringInput {  
// Do stuff with date passed }

If I change the function to take no arguments and just hardcode a date inside that, the function is called fine and works. This tells me the issue is trying to pass the JS var as a (const char *) is the problem. I have no idea how else to call that into the function and then convert it to an NSString for use, so far I’ve tried just passing the string as an NSString, const char and converting that to NSString using StringWithUTF8String, all to no avail.
Sorry for the long explanation, but does anyone have any ideas on how this could be achieved? (Have also asked on their forums but not a very big community so posting here too.) Help will be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:00:28+00:00Added an answer on June 5, 2026 at 10:00 am

    In case anyone else needs to know, I’m adding how I solved this very old question:
    NimbleKit does allow for the passing of as many parameters as needed from Javascript to Objective-C, through some inbuilt parameter methods that are stored in an NSDictionary. It even allows a simple one-liner to return an result back to the calling Javascript function!

    The Javascript side is fine as it is (unless you want to get a result, more on that below), but to the target Objective-C class, add the following to the header:

    @property (nonatomic, retain) NSDictionary *_parameters;
    @property (nonatomic, retain) NSString     *_lastReturnResult;
    

    And also add the following methods to the bottom of the class implementation:

    //Used by NK to receive parameters from JS to a method
    - (void)setNKParameters:(NSDictionary *)parameters { 
       self._parameters = parameters; 
    }
    //Used by NK to return result back to JS without a return call
    - (NSString*)methodResult { 
       return self._lastReturnResult; 
    }
    

    Now to use these functions, here’s an example which can receive a resulting NSString from the iOS class! First the Javascript:

    // Note the &sync=yes, this makes the call synchronous which ensures it will return a result before moving on
    var eventArrayString = CallNKitAction("GetEventsFunction?className=FNGetEvents&fromDate="+fromDate+"&toDate="+toDate+"&sync=yes");
    NKLog("eventString:"+eventArrayString);
    

    And now the Objective-C class (note the return type is void and it accepts no parameters in the typical sense, this is because they are passed in/returned differently):

    - (void) GetEventsFunction {
        // Get the passed parameters from Javascript
        NSString *fromDate = [self._parameters objectForKey:@"fromDate"];
        NSString *toDate = [self._parameters objectForKey:@"toDate"];
    
        NSString *resultString;
    
        /* Do stuff with the passed parameter(s) here... */
    
        // Now return the result back to the Javascript side
        self._lastReturnResult = resultString;
     }
    

    And there you go, not only passing objects to Objective-C from Javascript with NimbleKit, but even returning results for Javascript to use as well! For more resources along these lines, there’s a great project that sprung up on the NimbleKit forums which covers a lot of hybrid JS/iOS functionality here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am doing a simple coin flipping experiment for class that involves flipping a
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.