我有X
类型的字典[ String : Double ]
,我试图将其嵌入另一个名为dictArray: [ Int : [String: Double] ]
for (index, element) in hide.vertices.enumerate(){
dictArray[index] = HiddenLatlng(lat: element.latitude, lng: element.longitude).toDictionery()
}
//此处toDictionery
类HiddenLatlng
方法返回X
类型的字典
我正在尝试将此dictArray
嵌入到另一个词典中
dict = [String: AnyObject]()
dict["eventLatLngList"] = dictArray
但是当我打印dict
显示
dictionary is ["eventLatLngList": {
0 = {
latitude = "27.68837718075604";
longitude = "85.31910706311464";
};
3 = {
latitude = "27.68837718075604";
longitude = "85.31910706311464";
};
1 = {
latitude = "27.69259521229669";
longitude = "85.31552363187075";
};
2 = {
latitude = "27.68497603665675";
longitude = "85.31393576413393";
};
}]
但我的期望是:
dictionary is ["eventLatLngList": [
0 : [
"latitude" : 27.68837718075604,
"longitude" : 85.31910706311464
],
3 : [
"latitude" : 27.68837718075604,
"longitude" : 85.31910706311464
],
1 : [
"latitude" : 27.69259521229669,
"longitude" : 85.31552363187075
},
2 : [
"latitude" : 27.68497603665675,
"longitude" : 85.31393576413393
]]
我无法弄清楚造成这种奇怪行为的原因是什么?我使用swift 2.2和xcode 7.3
更新
我正在尝试将一系列坐标保存到firebase以及与这些坐标相关的一些信息。
在dict["eventLatLngList"] = dictArray
我把它保存到firebase:
reference.child("Events").childByAutoId().updateChildValues(dict) { (error: NSError?, reference: FIRDatabaseReference) in
print("hides saved to firebase") // execution does not enter this closure
if error != nil {
print("error: \(error?.localizedDescription)")
}else {
print("information saved.")
}
}
但我的应用程序崩溃时没有任何错误。我不知道它为什么会崩溃。
如果我没有将dictArray
添加到dict
,则所有信息都会保存到firebase中。
,我用虚拟词典测试了它
var testDict = [ "school": ["class" : ["student" : "name"]]]
如果我将testDict
添加到dict
,则会按预期将其保存到firebase。
更新 捕获的堆栈跟踪是:
* thread #1: tid = 0x47921, 0x016bdbe0 libswiftCore.dylib`swift_bridgeNonVerbatimFromObjectiveC + 196, queue
='com.apple.main-thread',stop reason = EXC_BREAKPOINT(code = EXC_ARM_BREAKPOINT,subcode = 0xdefe) * frame#0:0x016bdbe0 libswiftCore.dylib
swift_bridgeNonVerbatimFromObjectiveC + 196 frame #1: 0x0152034c libswiftCore.dylib
Swift._forceBridgeFromObjectiveC (Swift.AnyObject,A.Type) - &gt; A + 404 帧#2:0x015888fc libswiftCore.dylibSwift._NativeDictionaryStorageOwner.bridgingObjectForKey (Swift.AnyObject) -> Swift.Optional<Swift.AnyObject> + 128 frame #3: 0x01588868 libswiftCore.dylib
Swift._NativeDictionaryStorageOwner.objectForKey (Swift.AnyObject) - &gt; Swift.Optional + 32 帧#4:0x01588a70 libswiftCore.dylib@objc Swift._NativeDictionaryStorageOwner.objectForKey (Swift.AnyObject) -> Swift.Optional<Swift.AnyObject> + 40 frame #5: 0x002601cc Hiidden
+ [FSnapshotUtilities internalNodeFrom:priority:withValidationFrom:atDepth:path:](self =, _cmd =,val =,aPriority =,fn = @“updateChildValues:withCompletionBlock:”,depth =, path = @“0 elements”)+ 340,FSnapshotUtilities.m:61 帧#6:0x00260042隐藏+[FSnapshotUtilities nodeFrom:priority:withValidationFrom:atDepth:path:](self=<unavailable>, _cmd=<unavailable>, val=<unavailable>, aPriority=<unavailable>, fn=@"updateChildValues:withCompletionBlock:", depth=0, path=@"0 elements") + 90 at FSnapshotUtilities.m:33 frame #7: 0x0025ffb6 Hiidden
+ [FSnapshotUtilities nodeFrom:priority:withValidationFrom:](self =, _cmd =,val =,priority =,fn = @“updateChildValues:withCompletionBlock:”)+ 130 at FSnapshotUtilities.m:28 帧#8:0x0025ff1a Hiidden+[FSnapshotUtilities nodeFrom:withValidationFrom:](self=<unavailable>, _cmd=<unavailable>, val=<unavailable>, fn=@"updateChildValues:withCompletionBlock:") + 50 at FSnapshotUtilities.m:24 frame #9: 0x00260da8 Hiidden
+ [FSnapshotUtilities compoundWriteFromDictionary:withValidationFrom:](self =, FSnapshotUtilities.m中的_cmd =,values =,fn =)+ 424:161 帧#10:0x00289a26来自@callee_owned的隐藏-[FIRDatabaseReference updateChildValuesInternal:withCompletionBlock:from:](self=<unavailable>, _cmd=<unavailable>, values=<unavailable>, block=(Hiidden
重组thunk助手(@owned Swift.Optional&lt; __ ObjC.NSError&gt ;, @owned __ObjC.FIRDatabaseReference) - &gt; (@unowned())到@callee_unowned @convention(block)(@ unowned Swift.Optional&lt; __ ObjC.NSError&gt;,@ unowned __ObjC.FIRDatabaseReference) - &GT; (@unowned())at FRecord.swift),fn = @“updateChildValues:withCompletionBlock:”)+ 142 at FIRDatabaseReference.m:185 帧#11:0x0028998c Hiidden-[FIRDatabaseReference updateChildValues:withCompletionBlock:](self=0x167ecf90, _cmd=<unavailable>, values=<unavailable>, block=<unavailable>) + 52 at FIRDatabaseReference.m:179 frame #12: 0x000c6330 Hiidden
FRecord.save(hide = Hiidden.Hide @ 0x00fde6c8,completion = 0x0006c8ec HiiddenHiidden.HideViewModel.(save () -> ()).(closure #1) at HideViewModel.swift:39, self=0x1ae54500) -> ()) -> () + 4108 at FRecord.swift:116 frame #13: 0x000697f8 Hiidden
HideViewModel.save(self = 0x173529c8) - &gt;()+ 1432 at HideViewModel.swift:43 帧#14:0x001a08fc HiiddenMessageViewController.btnSave(sender=0x1abee640, self=0x17352800) -> () + 4732 at MessageViewController.swift:77 frame #15: 0x001a0a4c Hiidden
@ objc MessageViewController.btnSave(UIBarButtonItem) - &gt; ()+ 100 at MessageViewController.swift:0 帧#16:0x275f76a0 UIKit-[UIApplication sendAction:to:from:forEvent:] + 80 frame #17: 0x2777a0b8 UIKit
- [UIBarButtonItem(UIInternal)_sendAction:withEvent:] + 140 帧#18:0x275f76a0 UIKit-[UIApplication sendAction:to:from:forEvent:] + 80 frame #19: 0x275f7630 UIKit
- [UIControl sendAction:to:forEvent:] + 64 帧#20:0x275df56a UIKit-[UIControl _sendActionsForEvents:withEvent:] + 466 frame #21: 0x275df696 UIKit
- [UIControl _sendActionsForEvents:withEvent:] + 766 帧#22:0x275f6f50 UIKit-[UIControl touchesEnded:withEvent:] + 616 frame #23: 0x275f6bbe UIKit
- [UIWindow _sendTouchesForEvent:] + 646 帧#24:0x275ef546 UIKit-[UIWindow sendEvent:] + 642 frame #25: 0x275bfdd4 UIKit
- [UIApplication sendEvent:] + 204 帧#26:0x324d751a UIKit-[UIApplicationAccessibility sendEvent:] + 62 frame #27: 0x275be378 UIKit
_ UIApplicationHandleEventQueue + 5016 帧#28:0x22fa39e6 CoreFoundation__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14 frame #29: 0x22fa35d6 CoreFoundation
__ CFRunLoopDoSources0 + 454 帧#30:0x22fa193e CoreFoundation__CFRunLoopRun + 806 frame #31: 0x22ef01c8 CoreFoundation
CFRunLoopRunSpecific + 516 帧#32:0x22eeffbc CoreFoundationCFRunLoopRunInMode + 108 frame #33: 0x2450caf8 GraphicsServices
GSEventRunModal + 160 帧#34:0x27628434在AppDelegate.swift上的UIKitUIApplicationMain + 144 frame #35: 0x001cd098 Hiidden
main + 172:23 帧#36:0x22b9c872 libdyld.dylib`start + 2