Mac Developer Library

Developer

AddressBook Framework Reference ABRecord Class Reference

Options
Deployment Target:

On This Page
Language:

ABRecord

Inheritance


Conforms To


Import Statement


Swift

import AddressBook

Objective-C

@import AddressBook;

Availability


Available in OS X v10.2 and later.

ABRecord is an abstract superclass providing a common interface to, and defining common properties for, all Address Book records. A property is a field in the database record, such as the first or last name of a person record. ABRecord defines the types of properties supported, and basic methods for getting, setting, and removing property values.

The ABRecord class is “toll-free bridged” with its procedural C opaque-type counterpart. This means that the ABRecordRef type is interchangeable in function or method calls with instances of the ABRecord class.

  • Initializes a record using the given address book.

    Declaration

    Swift

    init!(addressBook addressBook: ABAddressBook!)

    Objective-C

    - (id)initWithAddressBook:(ABAddressBook *)addressBook

    Parameters

    addressBook

    The address book with which to initialize the record.

    Discussion

    The record is added to addressBook but is not visible to other address books until addressBook is saved. This method is the designated initializer for this class.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.5 and later.

  • Initializes a record using the shared address book.

    Declaration

    Swift

    init!()

    Objective-C

    - (id)init

    Discussion

    On OS X v10.5 and later, this is equivalent to initWithAddressBook:[ABAddressBook addressBook].

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.5 and later.

  • Removes the value for a given property.

    Declaration

    Swift

    func removeValueForProperty(_ property: String!) -> Bool

    Objective-C

    - (BOOL)removeValueForProperty:(NSString *)property

    Parameters

    property

    The property whose value will be removed.

    Return Value

    YEStrue if the value is removed successfully; otherwise, NOfalse.

    Discussion

    When you next call valueForProperty: on that property, it returns nil.

    If property is nil, this method raises an exception.

    For a list of the available properties, see Accessing Address Book Records in Address Book Programming Guide for Mac.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.2 and later.

  • Sets the value of a given property for a record.

    Declaration

    Swift

    func setValue(_ value: AnyObject!, forProperty property: String!) -> Bool

    Objective-C

    - (BOOL)setValue:(id)value forProperty:(NSString *)property

    Parameters

    value

    The value to set for property.

    property

    The property whose value will be set.

    Return Value

    YEStrue if the value was set successfully; otherwise, NOfalse.

    Discussion

    The type of the value must match the property’s type (see Property Types for a list of possible property types). If property is nil or if value is not of the correct type, this method raises an exception. If property is a multivalue list property, this method checks to see if the values in the multivalue list are the same type. If the multivalue list contains mixed types, the value will not be set successfully.

    For a list of the available properties, see Accessing Address Book Records in Address Book Programming Guide for Mac.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.2 and later.

  • Sets the value of a given property for a record, returning error information.

    Declaration

    Swift

    func setValue(_ value: AnyObject!, forProperty property: String!, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)setValue:(id)value forProperty:(NSString *)property error:(NSError **)error

    Parameters

    value

    The value to set for property.

    property

    The property whose value will be set.

    error

    A pointer to an error object that is set to an NSError instance if an error occurs.

    Return Value

    YEStrue if the value was set successfully; otherwise, NOfalse.

    Discussion

    The type of the value must match the property’s type (see Property Types for a list of possible property types). If property is nil or if value is not of the correct type, this method raises an exception. If property is a multivalue list property, this method checks to see if the values in the multivalue list are the same type. If the multivalue list contains mixed types, the value will not be set successfully.

    For a list of the available properties, see Accessing Address Book Records in Address Book Programming Guide for Mac.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.7 and later.

  • Returns the value of a given property for a record.

    Declaration

    Swift

    func valueForProperty(_ property: String!) -> AnyObject!

    Objective-C

    - (id)valueForProperty:(NSString *)property

    Parameters

    property

    The property whose value will be returned.

    Return Value

    The value of the given property.

    Discussion

    The type of the value depends on the property type (see Property Types for a list of possible property types). Note that the returned value is always of an immutable type (for example, an NSString type, not an NSMutableString type, is returned).

    If property is nil, this method raises an exception. If property is invalid, this method returns nil.

    For a list of the available properties, see Accessing Address Book Records in Address Book Programming Guide for Mac.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.2 and later.

  • Returns whether a record is read-only.

    Declaration

    Swift

    func isReadOnly() -> Bool

    Objective-C

    - (BOOL)isReadOnly

    Return Value

    YEStrue if the record is read-only; otherwise, NOfalse.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.4 and later.

  • Returns the unique ID for a record.

    Declaration

    Swift

    var uniqueId: String! { get }

    Objective-C

    @property(readonly, copy) NSString *uniqueId

    Return Value

    The unique ID.

    Discussion

    This method is equivalent to invoking valueForProperty:, passing kABUIDProperty as the argument.

    Import Statement

    Objective-C

    @import AddressBook;

    Swift

    import AddressBook

    Availability

    Available in OS X v10.2 and later.

    See Also

    – recordForUniqueId:(ABAddressBook)