【问题标题】:Xode 4.5 Hello World example doesn't workXode 4.5 Hello World 示例不起作用
【发布时间】:2012-10-12 08:06:49
【问题描述】:

我几乎是 XCode 初学者,因此我尝试了 XCode 文档中给出的“Hello World”示例:快速入门指南:Tutorial: Using Xcode to Write “Hello, World!” for OS X

我正在使用 XCode 4.5.1,我使用 OS 10.8.2 从其文档中获取了这个示例。我遵循了指示;该示例不起作用。它产生了窗口,但没有产生“hello world”打印。相关代码为:

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
    NSString *hello = @"Hello, World!";
    NSPoint point =NSMakePoint(15, 75);

    NSMutableDictionary *font_attributes = [[NSMutableDictionary alloc] init];
    NSFont *font = [NSFont fontWithName:@"Futura-MediumItalic" size:42];
    [font_attributes setObject:font forKey:NSFontAttributeName];

    [hello drawAtPoint:point withAttributes:font_attributes];

    [font_attributes release];
}

有两件值得注意的事情。这段代码的最后一行给出了错误:

release is unavailable: not available in automatic reference counting mode

所以我将这一行注释掉并运行程序。窗口出现了,但没有“Hello World”。 All Output 中出现了一条长消息,其中部分内容为:

"/Users/me/Library/ScriptingAdditions/YouHelper.osax/Contents/MacOS/YouHelper: no matching architecture in universal wrapper
Hello: OpenScripting.framework - scripting addition "/Users/me/Library/ScriptingAdditions/YouHelper.osax" declares no loadable handlers."

我是在做一些愚蠢的事情,还是我使用了错误的例子?

【问题讨论】:

    标签: macos xcode4.5


    【解决方案1】:

    您必须在代码末尾删除[font_attributes release];releaseretainallocdealloc 在 ARC(自动引用计数)中不可用。这就是错误所说的。 对于第二个错误,您应该删除任何引用 AppleScript 和应用程序的类似脚本插件的内容。

    【讨论】:

      【解决方案2】:

      如果没有看到您的项目,很难找出其中的问题所在。我的猜测是:您忘记在 IB 中指定自定义视图的类(“设计用户界面”中的第 12 步)。

      【讨论】:

        猜你喜欢
        • 2023-04-10
        • 1970-01-01
        • 1970-01-01
        • 2012-06-17
        • 1970-01-01
        • 1970-01-01
        • 2012-07-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多