Estoy intentando cambiar un valor en una matriz usando plutil
, pero me sale el error
Failed to insert value new value 2 at key path PARENT.0.KEY_IN_ARRAY with error -[__NSCFConstantString characterAtIndex:]: Range or index out of bounds
Aquí hay una muestra de muestra para ilustrar el problema:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SIMPLE</key>
<string>value1</string>
<key>PARENT</key>
<array>
<dict>
<key>KEY_IN_ARRAY</key>
<string>value2</string>
</dict>
<dict>
<key>KEY_IN_ARRAY</key>
<string>value3</string>
</dict>
</array>
</dict>
</plist>
Modificar el valor SIMPLE es fácil:
$ plutil -extract SIMPLE xml1 -o - sample.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>value1</string>
</plist>
$ plutil -replace SIMPLE -string "new value 1" sample.plist
$ plutil -extract SIMPLE xml1 -o - sample.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>new value 1</string>
</plist>
Obtener el valor de la matriz funciona bien:
$ plutil -extract PARENT.0.KEY_IN_ARRAY xml1 -o - sample.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<string>value2</string>
</plist>
pero recibo el error cuando intento modificar este valor:
$ plutil -replace PARENT.0.KEY_IN_ARRAY -string "new value 2" sample.plist
sample.plist: Could not modify plist, error: Failed to insert value new
value 2 at key path PARENT.0.KEY_IN_ARRAY with error -[__NSCFConstantString
characterAtIndex:]: Range or index out of bounds