读取未在类型为“NSDateFormatter*"的对象上找到的字典元素的预期方法; [英] expected method to read dictionary element not found on object of type "NSDateFormatter*"

查看:54
本文介绍了读取未在类型为“NSDateFormatter*"的对象上找到的字典元素的预期方法;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

NSString *hashKey = [NSString stringWithFormat:@"%lu%lu%lu", (unsigned long)format.hash, (unsigned long)timeZone.hash, (unsigned long)locale.hash];
NSDateFormatter *formatters = [NSDate sharedDateFormatters];
NSDateFormatter *cachedDateFormatter = formatters[hashKey];

我遇到了这条线的问题:

I am having trouble with this line:

NSDateFormatter *cachedDateFormatter = formatters[hashKey];

告诉我:在NSDateFormatter*"类型的对象上找不到读取字典元素的预期方法

Tells me: expected method to read dictionary element not found on object of type "NSDateFormatter*"

一些背景:

    + (NSMutableDictionary<NSString *, NSDateFormatter *>*)sharedDateFormatters {
    static NSMutableDictionary *dict = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        dict = [NSMutableDictionary new];
    });
    return dict;
    }

推荐答案

sharedDateFormatters 方法的返回类型是什么?

What is the return type of your sharedDateFormatters method?

您声明了 formatters 变量是什么数据类型?

What data type did you declare the formatters variable?

看到断开了吗?他们需要匹配.您不能将 NSDictionary 值分配给 NSDateFormatter 类型的变量.

See the disconnect? They need to match. You can't assign an NSDictionary value to a variable of type NSDateFormatter.

将您的线路更改为:

NSDictionary *formatters = [NSDate sharedDateFormatters];

或:

NSDictionary<NSString *, NSDateFormatter *> *formatters = [NSDate sharedDateFormatters];

这篇关于读取未在类型为“NSDateFormatter*"的对象上找到的字典元素的预期方法;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆