简体   繁体   English

在DashCode中从JavaScript调用Objective-C

[英]Calling Objective-C from JavaScript in DashCode

I am making a website in Dashcode. 我正在用Dashcode创建一个网站。 I know objective c very well but barely know javascript at all. 我非常了解目标c,但几乎一点也不了解javascript。 Here is an example objective-c class: 这是一个示例objective-c类:

/* 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? 如何在DashCode中将此类与野生动物园Web应用程序项目连接? How do I call next? 我下一步怎么打电话? How can I convert NSString to var and then print the var to the log? 如何将NSString转换为var,然后将var打印到日志?

Additional Details 额外细节

I have looked at the dev library. 我看过开发库。 How do I import the objective c class into a dashcode project? 如何将目标c类导入到dashcode项目中?

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? 如何将目标c与javascript文件或dashcode项目连接? Where does the objective c class go (eg same folder as js)? 目标C类要去哪里(例如与js相同的文件夹)? What is the javascript to call my function 'next'? 什么是将我的函数称为“下一个”的JavaScript? What does the following code do?: + (BOOL)isSelectorExcludedFromWebScript:(S… { if (sel == @selector(nameAtIndex:)) return NO; return YES; } 以下代码是做什么的:+(BOOL)isSelectorExcludedFromWebScript:(S…{if(sel == @selector(nameAtIndex :))返回NO;返回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调用obj-c,或者至少不可能这样做。 Dashcode is (or was) about very simple apps that can be written in javascript. Dashcode是(或曾经)关于可以用javascript编写的非常简单的应用程序。

Dashboard framework does not load any objective-c executable so making a objc-js bridge would be completely up to you. 仪表板框架不会加载任何Objective-C可执行文件,因此建立objc-js桥完全由您决定。 Which I don't think it is possible. 我认为这是不可能的。 Not at least using only Dashboard javascript framework. 至少不只使用Dashboard javascript框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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