简体   繁体   中英

Calling Objective-C from JavaScript in DashCode

I am making a website in Dashcode. I know objective c very well but barely know javascript at all. Here is an example objective-c class:

/* Here is an example .h file, "CircularList.h".
All behavior is inherited from List, which defines a List of objects.
Nowadays we can use NSArray which is more complex than List.
*/

#include <objc/List.h>  /* Superclass interface */

@interface CircularList: List /* List is superclass */
{  
    int currentLocation;
}  

- (NSString *) next; /* Returns next object in List or nil if none.  */ 

@end 

/* Here is the corresponding .m file: */
#include "CircularList.h"

@implementation CircularList

- (NSString *) next
{   
    int numObjects = [self count];  
    if (currentLocation >= numObjects)  
        currentLocation = 0;    
    return [self objectAt:currentLocation++];
}

@end

How do I connect this class with a safari web application project in DashCode? How do I call next? How can I convert NSString to var and then print the var to the log?

Additional Details

I have looked at the dev library. How do I import the objective c class into a dashcode project?

Here is the class:

/* Here is an example .h file, "CircularList.h".
All behavior is inherited from List, which defines a List of objects.
Nowadays we can use NSArray which is more complex than List.
*/

#include <objc/List.h> /* Superclass interface */

@interface CircularList: List /* List is superclass */
{ 
    int currentLocation;
} 

- (NSString *) next; /* Returns next object in List or nil if none. */ 

@end 










/* Here is the corresponding .m file: */
#include "CircularList.h"

@implementation CircularList

- (NSString *) next
{ 
int numObjects = [self count]; 
if (currentLocation >= numObjects) 
    currentLocation = 0; 
return [self objectAt:currentLocation++];
}

+ (NSString *) webScriptNameForSelector:(SEL)sel
{

if (sel == @selector(nameAtIndex:))
    name = [self next];

return name;
}

+ (BOOL)isSelectorExcludedFromWebScript:(S…
{
if (sel == @selector(nameAtIndex:)) return NO;
    return YES;
}
@end

How do I connect the objective c with the javascript file or dashcode project? Where does the objective c class go (eg same folder as js)? What is the javascript to call my function 'next'? What does the following code do?: + (BOOL)isSelectorExcludedFromWebScript:(S… { if (sel == @selector(nameAtIndex:)) return NO; return YES; }

Long time after...

People (us, third party devs) cannot call obj-c from Dashcode, or at least that is not supposed to be possible. Dashcode is (or was) about very simple apps that can be written in javascript.

Dashboard framework does not load any objective-c executable so making a objc-js bridge would be completely up to you. Which I don't think it is possible. Not at least using only Dashboard javascript framework.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM