Я искал ответы на эту проблему, но, к сожалению, безуспешно.Swift - Работа со словарями - добавление нескольких значений
Я разрабатываю математическое приложение (Swift-based), которое хранит данные каждой функции, которую вводит пользователь.
(я тогда нужно сделать функции на NSView с помощью Parser)
Данные структура сохраненную в Dictionary
, но я не в состоянии добавить значения и ключи ,
Dictionary
является инициализируется как:
var functions = [String : [[String : NSBezierPath], [String : NSColor], [String : CGFloat], [String : Bool]]]();
//1A.The String key of the main Dictionary is the value of the function, such as "sin(x)"
//1B.The value of the `Dictionary` is an `Array` od `Dictionaries`
//2.The first value is a dictionary, whose key is a String and value NSBezierPath()
//3.The second value is a dictionary, whose key is a String and value NSColor()
//4.The third value is a dictionary, whose key is a String and value CGFloat()
//5.The first value is a dictionary, whose key is a String and value Bool()
Чтобы добавить функции, я реализовал метод (я доложу часть):
...
//Build the sub-dictionaries
let path : [String:NSBezierPath] = ["path" : thePath];
let color : [String:NSColor] = ["color" : theColor];
let line : [String:CGFloat] = ["lineWidth" : theLine];
let visible : [String:Bool] = ["visible" : theVisibility];
//Note that I'm 100% sure that the relative values are compatible with the relative types.
//Therefore I'm pretty sure there is a syntax error.
//Add the element (note: theFunction is a string, and I want it to be the key of the `Dictionary`)
functions[theFunction] = [path, color, line, visible]; //Error here
...
Я учитывая после ошибка
'@|value $T10' is not identical to '(String,[([String:NSbezierPath],[String : NSColor],[String : CGFloat],[String : Bool])])'
Надеюсь, вопрос был достаточно ясным и полным.
В случае, если я немедленно добавлю любую информацию, которая вам понадобится.
С наилучшими пожеланиями и с праздниками.
Благодарим вас за ответ. Это очень помогло мне! Наконец-то я решил объявить структуру, как вы предполагали, она работает как шарм! Еще раз спасибо! –