小编Nos*_*rac的帖子

按成员字典的键对数组进行排序

如果这有点令人困惑,这里是一个直观的表示:

数组>对象>字典>值

如果这有帮助,这里有一些上下文:

数组包含播放列表.每个播放列表都有一个字典.每个字典包含元数据.

我需要通过这个元数据对原始字典进行排序.

我一直很难实现这一点.思考?

[编辑]将较高的字典更改为数组

objective-c

3
推荐指数
1
解决办法
889
查看次数

Objective-C Singleton超类?

我正在尝试编写一个我可以子类化为具有即时单例的类.这是我到目前为止所拥有的.它的工作原理是它的一个子类通过sharedInstance调用另一个子类,这会导致一个最终耗尽内存的巨大循环.

有任何想法吗?

static NSMutableDictionary *sharedInstances = nil;

@implementation Singleton

+ (Singleton*)sharedInstance
{
    [Singleton initSharedInstances];
    Class myClass = [self class];
    Singleton * sharedInstance = [sharedInstances objectForKey:myClass];
    @synchronized(myClass)
    {
        if (sharedInstance == nil)
        {
            sharedInstance = [[myClass alloc] init];
            [sharedInstances setObject:sharedInstance forKey:myClass];
        }
    }
    return sharedInstance;
}

+ (void) initSharedInstances
{
    if (sharedInstances == nil)
    {
        sharedInstances = [[NSMutableDictionary alloc] init];
    }
}

@end
Run Code Online (Sandbox Code Playgroud)

objective-c

0
推荐指数
1
解决办法
1049
查看次数

标签 统计

objective-c ×2