ios - 使用未声明的标识变量

标签 ios objective-c xcode titanium-mobile appcelerator-titanium

我一直在尝试构建一个 native iOS 模块,以供来自官方 appcelerator 文档的 Titanium 应用程序使用:iOS Module Quick Start .不确定为什么构建失败

'/iphone/Classes/ComExampleTestModule.m:55:20: Use of undeclared identifier 'foo'; did you mean 'for'? 

我注意到 deallocsetExampleProp 的错误,我在 ComExampleTestModule.m 文件中使用了 foo 变量。

ComExampleTestModule.h

#import "TiModule.h"

@interface ComExampleTestModule : TiModule
{
}

@end

@interface ComAppcNewmoduleModule : TiModule
{
    NSString *foo;
}
@end

ComExampleTestModule.m

/**


* test
 *
 * Created by Your Name
 * Copyright (c) 2017 Your Company. All rights reserved.
 */

#import "ComExampleTestModule.h"
#import "TiBase.h"
#import "TiHost.h"
#import "TiUtils.h"

@implementation ComExampleTestModule

#pragma mark Internal

// this is generated for your module, please do not change it
-(id)moduleGUID
{
    return @"e5d1b415-6588-4911-9825-3a210032b430";
}

// this is generated for your module, please do not change it
-(NSString*)moduleId
{
    return @"com.example.test";
}

#pragma mark Lifecycle

-(void)startup
{
    // this method is called when the module is first loaded
    // you *must* call the superclass
    [super startup];

    NSLog(@"[INFO] %@ loaded",self);
}

-(void)shutdown:(id)sender
{
    // this method is called when the module is being unloaded
    // typically this is during shutdown. make sure you don't do too
    // much processing here or the app will be quit forceably

    // you *must* call the superclass
    [super shutdown:sender];
}

#pragma mark Cleanup

-(void)dealloc
{
    // release any resources that have been retained by the module
    RELEASE_TO_NIL(foo); // Errors out on this line
    [super dealloc];
}

#pragma mark Internal Memory Management

-(void)didReceiveMemoryWarning:(NSNotification*)notification
{
    // optionally release any resources that can be dynamically
    // reloaded once memory is available - such as caches
    [super didReceiveMemoryWarning:notification];
}

#pragma mark Listener Notifications

-(void)_listenerAdded:(NSString *)type count:(int)count
{
    if (count == 1 && [type isEqualToString:@"my_event"])
    {
        // the first (of potentially many) listener is being added
        // for event named 'my_event'
    }
}

-(void)_listenerRemoved:(NSString *)type count:(int)count
{
    if (count == 0 && [type isEqualToString:@"my_event"])
    {
        // the last listener called for event named 'my_event' has
        // been removed, we can optionally clean up any resources
        // since no body is listening at this point for that event
    }
}

#pragma Public APIs

-(id)example:(id)args
{

    return @"hello world";
}

-(id)exampleProp:(id)foo
{
    NSLog(@"[INFO] In Module - the stored value for exampleProp: %@", foo);
    return foo;
}

-(void)setExampleProp:(id)value
{
    // Macro from TiBase.h to type check the data
    ENSURE_STRING(value);
    // Call the retain method to keep a reference to the passed value
    foo = [value retain]; // Errors out on this line
    NSLog(@"[INFO] In Module - the new value for exampleProp: %@", value);
}

@end

最佳答案

fooComAppcNewmoduleModule 的成员,而不是 ComExampleTestModule 的成员。但是您尝试在 ComExampleTestModule (@implementation ComExampleTestModule) 中访问它。
这就是您收到错误的原因。因为 ComExampleTestModule 不知道 foo

关于ios - 使用未声明的标识变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42645355/

相关文章:

javascript - 如何在 iOS 上的输入类型日期中设置最大值和最小值

ios - 当我用 UIView 覆盖所有屏幕时,如何用 UIView 覆盖 UIStatusBar? (iPhone)

objective-c - Xib 没有出现在 View 中

iphone - 当发布的App对User Interaction无响应时,有什么好的方法可以获取有用的信息?

c++ - Xcode C++ 中文件流/fstream 的问题

ios - Google Books Oauth 访问 token 授权错误

ios - 使用 CocoaHTTPServer 流式传输视频

javascript - 当用户触摸 iPhone 上的 HTML 元素时我该如何 react ?

ios - ScrollView 宽高比中的 UIImageView 不起作用

ios - MFMessageComposeViewController 不工作