在Swift中,如何声明对在objective-c代码中声明的全局指针的引用?

时间:2016-05-01 20:26:22

标签: cocoa-touch swift2

我的应用程序是Objective-c origin,所有新文件都是Swift。我的main.m文件有:

public boolean onMarkerClick(Marker marker) {
    String atm_title = marker.getTitle();
    option = "retreive_message";
    ListView listview = (ListView) findViewById(...) //your listview resource
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,R.layout.list_item,R.id.textView,null);
    listView.setAdapter(adapter);
    new GetAtms(atm_title,adapter).execute();      //here is the call to asyncTask
    return false;

} 

我所有的objective-c(.m)文件都有:

ConfigMgr* configMgr;

它是一个全局指针,因为每个人都需要访问有关配置的一些信息。 (它是我唯一的全局,我不为此道歉。)那么我应该添加到我的Swift文件中以便能够访问此对象的这个实例,通过使用全局,而不是传递指针每个.swift文件? (我主要关注的是确保我不会最终实例化另一个ConfigMgr对象。)

1 个答案:

答案 0 :(得分:0)

假设ConfigMgr类的接口在ConfigMgr.h中声明,请在桥接头中包含以下内容:

#import "ConfigMgr.h"
extern ConfigMgr* configMgr;

你应该好好去!