从目标C中的Swift结构类读取数据

时间:2019-06-19 08:41:49

标签: objective-c swift dictionary nsdictionary

在读取目标C中的Swift结构类时遇到问题。我的swift结构类包含使字典不区分大小写的代码。 迅速,它是有效的,但在目标c中,当我读取字典的值时,出现“无法读取类型为'CaseInsensitiveDictionary *'的对象上找不到的字典元素的预期方法”的错误

// swift class

import Foundation
public struct MyDictionary<Key: Hashable, Value: NSValue>:     Collection {
public typealias DictionaryType = Dictionary<Key, Value>
private var dictionary: DictionaryType

//Collection: these are the access methods
public typealias IndexDistance = DictionaryType.IndexDistance
public typealias Indices = DictionaryType.Indices
public typealias Iterator = DictionaryType.Iterator
public typealias SubSequence = DictionaryType.SubSequence

public var startIndex: Index { return dictionary.startIndex }
public var endIndex: DictionaryType.Index { return  dictionary.endIndex }
public subscript(position: Index) -> Iterator.Element { return dictionary[position] }
public subscript(bounds: Range<Index>) -> SubSequence { return dictionary[bounds] }
public var indices: Indices { return dictionary.indices }
public subscript(key: Key)->Value? {
    get { return dictionary[key] }
    set { dictionary[key] = newValue }
}
public func index(after i: Index) -> Index {
    return dictionary.index(after: i)
}

//Sequence: iteration is implemented here
public func makeIterator() -> DictionaryIterator<Key, Value> {
    return dictionary.makeIterator()
}

//IndexableBase
public typealias Index = DictionaryType.Index
}

// to read

@property (retain, nonatomic) CaseInsensitiveDictionary *caseDic;
self.caseDic = (CaseInsensitiveDictionary *)fields.firstObject;
NSLog(@"caseDic name %@", self.caseDic[@"name"]);

在Log中,我想要字典的值。但我收到错误消息“在'CaseInsensitiveDictionary *'类型的对象上找不到字典元素的预期方法

0 个答案:

没有答案