Sto provando a cambiare un valore in un array usando plutil
, ma ottengo l'errore
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
Ecco un esempio di plist per illustrare il 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>
La modifica del valore SIMPLE è semplice:
$ 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>
Ottenere il valore dell'array funziona bene:
$ 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>
ma ottengo l'errore quando provo a modificare questo valore:
$ 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