Retired Document
Important: This document may not represent best practices for current development. Links to downloads and other resources may no longer be valid.
Value object
A value object is in essence an object-oriented wrapper for a simple data element such as a string, number, or date. The common value classes in Cocoa are NSString
, NSDate
, and NSNumber
. Value objects are often attributes of other custom objects you create.
Value objects offer richer behavior than the corresponding simple scalar types (such as char
, NSTimeInterval
, int
, float
, or double
):
You can put any of the value objects in a collection, such as an instance of
NSArray
orNSDictionary
.Using
NSString
, and its subclassNSMutableString
, you can perform a wide range of string-related operations. For example, you can join strings together, split strings apart, work on file paths, transform the case of characters, and search for substrings. In all of these, string objects are treated as Unicode.Using
NSDate
, in conjunction withNSCalendar
and other related classes, you can perform complicated calendrical calculations such as determining the number of months and days between two instants in time based on the user’s preferred calendar, taking into account variables such as time zones and leap years.Using the
NSNumber
subclassNSDecimalNumber
, you can accurately perform currency-based calculations.
NSValue
NSValue
provides a simple container for a single C or Objective-C data item. It can hold any of the scalar types such as char
, int
, float
, or double
, as well as pointers, structures, and object IDs. It lets you add items of such data types to collections such as instances of NSArray
and NSSet
, which require their elements to be objects. This is particularly useful if you need to put point, size, or rectangle structures (such as NSPoint
, CGSize
, or NSRect
) into a collection.
Copyright © 2018 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2018-04-06