小编Jos*_*ose的帖子

Cordova:从plugin.xml修改*-Info.plist

我正在构建一个插件来使用iOS设备中的星形打印机,使用它们的SDK,一切正常,但config-file修改info.plist文件的命令无法正常工作.在我的plugin.xml里面,我有:

<config-file target="*-Info.plist" parent="Supported external accessory protocols">
  <array>
    <key>item 0</key>
    <string>jp.star-m.starpro</string>
  </array>
</config-file>
Run Code Online (Sandbox Code Playgroud)

有了这个我应该得到一个Supported external accessory protocols数组,其中包含一个名为item 0,类型String和值的项目,jp.star-m.starpro但我得到一个包含两个项目的数组,就好像我会做的那样:

<array>
    <key>item 0</key>
    <string>item 0</string>
    <key>item 1</key>
    <string>jp.star-m.starpro</string>
</array>
Run Code Online (Sandbox Code Playgroud)

我需要的: 一个项目


我得到了什么: 两件事


相关问题:

config-file通过阅读这些问题来实现.

  1. 通过Cordova config.xml向iOS .plist文件添加条目
  2. 修改"*-Info.plist"CFBundleURLTypes的两个cordova插件

info.plist ios cordova cordova-plugins

9
推荐指数
1
解决办法
4118
查看次数

Swift:正确解码不精确的十进制

我需要Decodable正确解码(协议)一个不精确的十进制值,从这个问题我了解如何正确处理十进制实例化,但是在解码时如何做到这一点?

如果尝试将任何数字初始化为字符串

if let value = try! container.decode(String.self, forKey: .d) {
    self.taxAmount = Decimal(string: value)
}
Run Code Online (Sandbox Code Playgroud)

我明白了Fatal Error: "Expected to decode String but found a number instead."

如果尝试将 130.43 初始化为十进制

if let value = try! container.decode(Decimal.self, forKey: .d) {
    //value.description is 130.43000000000002048
    self.d = Decimal(string: value.description)
    //making subtotal to be also 130.43000000000002048 and not 130.43
}
Run Code Online (Sandbox Code Playgroud)

解码时有什么方法可以使用这个构造函数吗?

  • NSDecimalNumber(string: "1.66")
  • NSDecimalNumber(value: 166).dividing(by: 100)
  • Decimal(166)/Decimal(100)
  • Decimal(sign: .plus, exponent: -2, significand: 166)

以下是我从外部服务收到的 JSON 的简化版本:

{
   "priceAfterTax": 150.00, …
Run Code Online (Sandbox Code Playgroud)

nsdecimalnumber swift decodable

5
推荐指数
1
解决办法
5915
查看次数