xcode – 如何使用PlistBuddy通过其属性访问PreferencesSpecified的元素?

xcode – 如何使用PlistBuddy通过其属性访问PreferencesSpecified的元素?,第1张

概述目前我正在使用这个代码 /usr/libexec/PlistBuddy -c "Set PreferenceSpecifiers:1:DefaultValue $productVersion" "Test/Settings.bundle/Root.plist" 在构建阶段的脚本部分将产品版本放在应用程序设置的只读字段中.该字段具有首选项数组的位置1(从0开始). 我问是否有可能使用更强大的1来访问 目前我正在使用这个代码
/usr/libexec/PListBuddy -c "Set PreferenceSpecifIErs:1:DefaultValue $productVersion" "Test/Settings.bundle/Root.pList"

在构建阶段的脚本部分将产品版本放在应用程序设置的只读字段中.该字段具有首选项数组的位置1(从0开始).

我问是否有可能使用更强大的1来访问该领域,因为在开发期间,我或其他开发人员可能会意外改变位置.

无论其位置如何,我可以访问指定它的标识符的元素吗?

为了更好地解释我的需要,我写下了一个例子.我需要像1.2.345这样的数组的第二个字符串的字符串节点,我需要从0.0.0变为1.2.345.是否可以访问dict节点,而不表示它是数组中的第二个?我要求类似于在PListBuddy中使用的xpath表达式(如果有的话).

<?xml version="1.0" enCoding="UTF-8"?><dict><key>PreferenceSpecifIErs</key><array>    <dict>        <key>Title</key>        <string>Application info</string>        <key>Type</key>        <string>PSGroupSpecifIEr</string>    </dict>    <dict>        <key>DefaultValue</key>        <string>0.0.0</string>        <key>Key</key>        <string>version</string>        <key>Title</key>        <string>Version</string>        <key>Type</key>        <string>PSTitleValueSpecifIEr</string>    </dict>    <dict>        <key>DefaultValue</key>        <string>0</string>        <key>Key</key>        <string>build</string>        <key>Title</key>        <string>Build</string>        <key>Type</key>        <string>PSTitleValueSpecifIEr</string>    </dict>         ...
解决方法
#!/bin/tcshset productVersion="1.2.345"set thefile="~/Desktop/PListBuddy/Root.pList"set cnt=`/usr/libexec/PListBuddy -c "Print PreferenceSpecifIErs:" ${thefile} | grep "Dict"|wc -l`# echo "the count is: $cnt."set cnt=`expr "$cnt" '-' '1'`foreach IDx (`seq 0 $cnt`)    # echo "the index is: $IDx."    set val=`/usr/libexec/PListBuddy -c "Print PreferenceSpecifIErs:${IDx}:Title" ${thefile}`    # echo "the value of PreferenceSpecifIErs:${IDx}:Title: is ${val}."    if ( "$val" == "Version" ) then        echo "the index of the entry whose 'Title' is 'Version' is $IDx."        # Now set it        /usr/libexec/PListBuddy -c "Set PreferenceSpecifIErs:${IDx}:DefaultValue $productVersion" ${thefile}        # just to be sure that it worked        set ver=`/usr/libexec/PListBuddy -c "Print PreferenceSpecifIErs:${IDx}:DefaultValue" ${thefile}`        echo 'PreferenceSpecifIErs:$IDx:DefaultValue set to: ' $ver    endifend
总结

以上是内存溢出为你收集整理的xcode – 如何使用PlistBuddy通过其属性访问PreferencesSpecified的元素?全部内容,希望文章能够帮你解决xcode – 如何使用PlistBuddy通过其属性访问PreferencesSpecified的元素?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1111395.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存