我有以下代码尝试将字典转换为NSData:
func dataFromDict<ValueType>(dict: [String:ValueType]) -> NSData {
return NSKeyedArchiver.archivedDataWithRootObject(dict)
}
Run Code Online (Sandbox Code Playgroud)
编译器给我这个错误dict作为参数传递:
Argument type '[String:ValueType]' does not conform to expected type 'AnyObject'
编辑:
@ vadian的解决方案对我有用.
我还试图将这个词组投射到NSDictionary:
return NSKeyedArchiver.archivedDataWithRootObject(dict as NSDictionary)
Run Code Online (Sandbox Code Playgroud)
但是得到这个错误:
Cannot convert value of type '[String:ValueType]' to type 'NSDictionary' in coercion
为什么?
以下rakefile将崩溃红宝石:
require 'json'
task :default do |t, p|
end
Run Code Online (Sandbox Code Playgroud)
跑步rake会得到:
$ rake
/Users/mobile/.rvm/gems/ruby-2.0.0-p594/gems/json-1.8.3/lib/json/ext/parser.bundle: [BUG] Segmentation fault
ruby 2.0.0p645 (2015-04-13 revision 50299) [universal.x86_64-darwin15]
-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:
* ~/Library/Logs/CrashReporter
* /Library/Logs/CrashReporter
* ~/Library/Logs/DiagnosticReports
* /Library/Logs/DiagnosticReports
the more detail of.
-- Control frame information -----------------------------------------------
c:0026 p:-17548726946152 s:0099 e:000098 TOP [FINISH]
c:0025 p:---- s:0097 e:000096 CFUNC :require
c:0024 p:0115 s:0093 e:000092 METHOD /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55
c:0023 p:0009 s:0083 …Run Code Online (Sandbox Code Playgroud)