Welcome to 16892 Developer Community-Open, Learning,Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm struggling to make "stringdict" rules work as i need. Already managed to make Int values work correctly by using "d" in NSStringFormatValueTypeKey.

But in 1 case I need to pass a string. I use "s" specifier in stringdict but for some reason i get a string with "(null)" instead of my value.

I haven't found any example for working with string values (yes, it doesn't have a plural form but I still need to use stringdict because of localization). Don't know what keys to use as "one","zero" do not make any sense for string.

This is how I format the string

let inMinVal: String = "some text value"     
let format = NSLocalizedString("select %s days to exercise", comment: "")
let retVal = String(format: format, inMinVal)

And here comes my stringdict file:

<?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>select %s days to exercise</key>
    <dict>
        <key>NSStringLocalizedFormatKey</key>
        <string>There's no better time to start than now. Select %#@v2_min@ when you are gonna exercise. The sessions intensity will adapt based on your choices.</string>
        <key>v2_min</key>
        <dict>
            <key>NSStringFormatSpecTypeKey</key>
            <string>NSStringPluralRuleType</string>
            <key>NSStringFormatValueTypeKey</key>
            <string>s</string>
            <key>one</key>
            <string>%s DAYS</string>
            <key>zero</key>
            <string>%s DAYS</string>
            <key>other</key>
            <string>%s DAYS</string>
        </dict>
    </dict>
  </dict>
</plist>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to 16892 Developer Community-Open, Learning and Share

548k questions

547k answers

4 comments

56.5k users

...