IT English Collection(2)of Formatter(IOS)

来源:互联网 发布:p2p平台 知乎 编辑:程序博客网 时间:2024/05/17 23:56

1 前言

今天我们介绍一篇关于IOS的格式化官方解释文档。

2 详述

2.1 正文

A formatter is an object that automatically converts a string representation of a value to an object representing that value, andvice versa. For example, an NSNumberFormatter object can convert the string “1.25” to an NSNumber object representing the value 1.25. An NSDateFormatter; objects can convert an NSDate object representing December 12, 2009 to “11/22/2009”. As you can see, the conversion works both ways, from string to value object and value object to string. The abstract base class for formatters is NSFormatter. You may subclass NSFormatter to create formatters for other types of data, even custom data types defined by your application’s data model.


Configuring and Applying a Formatter
When you create a date or number formatter object, you can configure it in many ways, but the primary attributes are formatter style and locale. You can give NSNumberFormatter objects a decimal, currency, percent, scientific, or “spell-out” style (for example, “25” to “twenty-five”). You can give NSDateFormatter objects both date and time styles in a range ofexplicitness, for example, from “11/22/2009” to “Sunday, November 22, 2009 AD”.

You may also apply an NSLocale object to a formatter object so that it reflects a certain locale; for example, “1.02” in U.S. English would be “1,02” in French. To get the currentlocale (set by the user), call the NSLocale class method currentLocale.

After you have configured a date or number formatter, you apply it to a string obtained from the user interface (typically a text field) to obtain the value object; or you apply it to an NSDate or NSNumber object and write the resulting string to an object in the user interface. The methods you call for thesepurposes are dateFromString:, stringFromDate:, numberFromString:, and stringFromNumber:.

2.2 生词汇总

vice [vaɪs]prep. 代替

versa ['vɜ:sə]adj. 反的

explicitness [iks'plisitnis]n. 直言不讳;明确性
reflect [rɪ'flekt]vt. 反映;反射
certain ['sɜːt(ə)n; -tɪn]adj. 某一;必然的;
locale [ləʊ'kɑːl]n. 场所,现场
obtain [əb'teɪn]vt. 获得
purpose ['pɜːpəs]n. 目的;用途

3 结语

以上是所有内容,希望对大家有所帮助。