iphone - 可能不响应+alloc?

标签 iphone ios

我不确定问题是什么 - 我收到“找不到 Singleton 的接口(interface)声明”, 这里:@implementation Singleton

我收到“Singleton 可能不会响应 +alloc”, 这里:静态单例*共享;

.m 文件

#import "Singleton.h"

@implementation Singleton

+(Singleton *) sharedSingleton 
{
    static Singleton *shared;
    if (!shared) {
        shared = [[self alloc] init];
    }

    return shared;
}

@结束

.h 文件

#import <Foundation/Foundation.h>

@interface Singleton : NSObject {

}

+ (Singleton *)sharedSingleton;
@end

我只想要一个基本的单例类:(它们显示为警告,但如果可能的话我希望它们消失!希望这不是愚蠢的,这是漫长的一天

最佳答案

如果仍然无法删除警告,请尝试清理您的项目 更改您的线路

shared = [[self alloc] init];

shared = [[Singleton alloc] init];

关于iphone - 可能不响应+alloc?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9425090/

相关文章:

iphone - 如何格式化 NSFetchedResultsSectionInfo 中的日期?

javascript - 在 ios 上的 m.youtube.com 上导航的 uiwebview 上获得点击链接

iOS 11 位置权限从一开始就三个选项

ios - 短暂超时后如何切换到新的 View Controller ?

iphone - 简单的核心数据示例应用程序?

iphone - 在 Swift 中使用 shouldPerformSegueWithIdentifier( ) 方法

ios - swift : SLKTextViewController crashes after editing tableview numberOfSectionsInTableView

iphone - 在 Objective-c/iPhone 中使自定义类可序列化?

ios - Swift 中带有圆角半径的 Collection View

ios - 为 CALayer 的蒙版制作动画