나는이 문제에 대한 해답을 찾고 있었지만, 불행히도 성공하지 못했습니다.Swift - 사전 작업 - 여러 값 추가
저는 사용자가 입력 한 모든 기능의 데이터를 유지하는 수학적 앱 (Swift 기반)을 개발 중입니다. 값과 키를 추가
는 데이터 구조 입니다
가 Dictionary
에 저장 (I는 파서를 사용하여 NSView의에 기능을 그릴 필요) 그러나 나는 할 수 아니에요 .
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()
이 기능을 추가하려면, 내가하는 방법이 (내가의 일부를보고합니다) 구현 :
Dictionary
는 같이를 초기화
...
//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])])'
질문이 충분히 명확하고 완벽했기를 바랍니다.
필요한 경우 즉시 모든 종류의 정보를 추가 할 것입니다.
안녕하십니까.
답장을 보내 주셔서 감사합니다. 그것은 나를 많이 도왔습니다! 마침내 당신이 제안한 것처럼 구조체를 선언하기로 결정했습니다, 그것은 매력처럼 작동합니다! 다시 감사합니다! –