似乎很清楚它应该设置.
__attribute__功能吗?一个宏?句法?__attribute__((destructor))跑?__attribute__((constructor))
static void initialize_navigationBarImages() {
navigationBarImages = [[NSMutableDictionary alloc] init];
}
__attribute__((destructor))
static void destroy_navigationBarImages() {
[navigationBarImages release];
}
Run Code Online (Sandbox Code Playgroud) 这是一个有点离奇的问题.我的目标是理解语言设计决策并确定C++中反射的可能性.
为什么C++语言委员会不会在语言中实现反思?对于不在虚拟机上运行的语言(如java),反射是否太难?
如果要实现C++的反射,那么挑战是什么?
我想反射的使用是众所周知的:编辑器可以更容易编写,程序代码更小,可以为单元测试生成模拟等等.但是,如果你也可以对反射的使用发表评论,那就太棒了.
作为一个有抱负的Apple开发人员,如果在进入Objective-C并最终进入Cocoa框架之前先学习C更好,我想获得社区的意见吗?
我的直觉说学习C,这将给我一个良好的基础.
我正在Mac OSX上用纯C创建一个应用程序.我想要的是创建一个窗口,我的应用程序将被存储.
我希望它是纯C解决方案,但是如果我必须使用objective-c类来初始化窗口然后将上下文发送到我的C代码那么它就没问题了.
我没有使用xcode,只有简单的文本编辑器,我试图导入cocoa但它只是产生了很多错误.
总结我的问题是:如何在简单的纯C生成代码中显示osx窗口?
对于那些质疑我的理智/浪费时间/能力/动机的人来说,这件事是"基础与勺子"项目的一个端口,现在因为是一个全C的iOS应用程序而臭名昭着.
所以,我有交流文件铆足了劲去,要在主类的全部-C的MAC-应用的背后,但是,限制因素是阻止正在启动的应用程序的组合.就目前而言,该项目只是一个main.m和一个名为AppDelegate.c的类,所以我输入了"AppDelegate"作为info.plist中主要类的名称,令我完全惊讶的是,打印的日志:
无法找到类:AppDelegate,退出
这将iOS中很好地工作,因为主函数接受委托类的名称,并自动处理它,但NSApplicationMain()函数没有这样的说法.
现在,我知道这源于@interface/@implementationC 中没有指令的事实,而这正是操作系统似乎正在寻找的,所以我编写了一个简单的NSApplication子类并将其作为主要类提供给plist,它完美地启动了好.我的问题是,怎样才能将ac文件设置为mac应用程序中的主要类并使其正确启动?
编辑:解决了!该文件可能是.m(框架错误,由于某种原因),但类对的分配足以滑倒.您可以在此处下载基于C的Mac App的源代码.快乐挖!
代码已被编写,签名,密封和盖章,但我需要的只是解决plist中NSPrincipalClass要求的方法.
我正在使用C/Objective-C开发一个应用程序(请不要使用C++,我已经有了解决方案),我遇到了一个有趣的用例.
因为clang不支持嵌套函数,所以我的原始方法不起作用:
#define CREATE_STATIC_VAR(Type, Name, Dflt) static Type Name; __attribute__((constructor)) void static_ ## Type ## _ ## Name ## _init_var(void) { /* loading code here */ }
Run Code Online (Sandbox Code Playgroud)
这段代码可以用GCC编译好,但由于clang不支持嵌套函数,我得到一个编译错误:
预期';' 在宣言结束时.
所以,我找到了一个适用于Clang函数内部变量的解决方案:
#define CREATE_STATIC_VAR_LOCAL(Type, Name, Dflt) static Type Name; ^{ /* loading code here */ }(); // anonymous block usage
Run Code Online (Sandbox Code Playgroud)
但是,我想知道是否有办法利用宏连接来为情况选择合适的方法,例如:
#define CREATE_STATIC_VAR_GLOBAL(Type, Name, Dflt) static Type Name; __attribute__((constructor)) void static_ ## Type ## _ ## Name ## _init_var(void) { /* loading code here */ }
#define CREATE_STATIC_VAR_LOCAL(Type, Name, …Run Code Online (Sandbox Code Playgroud) scope global-variables static-variables clang nested-function
What are the methods of developing for iOS with C++? I am familiar with using Objective-C++ within Xcode, by selecting Obj-C as my language when creating a new project, but what else is there. I know there are tools like Xamarin that allow for iOS development in C#, however i'm curious as to what officially supported ways of developing for iOS in C++ there are? Can an iOS app be written completely in C++ with no Objective-C and …
我有一个关于通用应用程序的问题.我的应用程序不会有故事板或xib文件.没有它可以编写通用的iPhone/iPad应用程序吗?我找到了一些如何使用 storyboard 创建通用应用程序的教程,但我不希望(我不能)在我的项目中使用此功能.
如果有可能我该怎么办?如果我只需要在ViewControllers中进行更改?我开始这样做,我不会改变旧项目,所以我可以做任何事情 - 我应该学习什么/我应该记得什么?
我的目标是iOS 5.
编辑:
我在资源文件中有一个屏幕信息,我的rootViewController或任何其他ViewController将在编译时创建,所以我不能有xib文件,我不能把按钮放在xib与Interface Builder因为我甚至没有我知道那里有多少按钮.我不知道有多少屏幕,直到我在我的项目中运行.
我知道有可能使用objc_msgSend使用Objective C代码,我相信,手动运行Objective C运行时但是当我运行这段代码时,我得到引用NSString的错误(即使我从不使用它)以及其他未使用的类.
来自xcode的错误

我上面的目标C代码(注释掉)我试图'模仿'.
#include <Foundation/Foundation.h> /*Added suggestion by answer, same errors*/
#include <AppKit/AppKit.h>
int main()
{
// convert objective c into c code
/*
NSAlert *alert = [[NSAlert alloc] init];
[alert setAlertStyle:NSInformationalAlertStyle];
[alert setMessageText:@"Hello World"];
[alert setInformativeText:@"Hello World"];
[alert runModal];
*/
id alert = objc_msgSend(objc_msgSend(objc_getClass("NSAlert"), sel_registerName("alloc")), sel_registerName("init"));
objc_msgSend(alert, sel_getUid("setAlertStyle:"), NSInformationalAlertStyle);
objc_msgSend(alert, sel_getUid("setMessageText:"), CFSTR("Hello World!"));
objc_msgSend(alert, sel_getUid("setInformativeText:"), CFSTR("Hello World!"));
objc_msgSend(alert, sel_getUid("runModal"));
}
Run Code Online (Sandbox Code Playgroud)