iOS Developer Library

Developer

Foundation Framework Reference NSCondition Class Reference

Options
Deployment Target:

On This Page
Language:

NSCondition

The NSCondition class implements a condition variable whose semantics follow those used for POSIX-style conditions. A condition object acts as both a lock and a checkpoint in a given thread. The lock protects your code while it tests the condition and performs the task triggered by the condition. The checkpoint behavior requires that the condition be true before the thread proceeds with its task. While the condition is not true, the thread blocks. It remains blocked until another thread signals the condition object. More...

Inheritance


Conforms To


Import Statement


import Foundation @import Foundation;

Availability


Available in iOS 2.0 and later.
  • Blocks the current thread until the condition is signaled.

    Declaration

    Swift

    func wait()

    Objective-C

    - (void)wait

    Discussion

    You must lock the receiver prior to calling this method.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    – lock (NSLocking)

  • Blocks the current thread until the condition is signaled or the specified time limit is reached.

    Declaration

    Swift

    func waitUntilDate(_ limit: NSDate) -> Bool

    Objective-C

    - (BOOL)waitUntilDate:(NSDate *)limit

    Parameters

    limit

    The time at which to wake up the thread if the condition has not been signaled.

    Return Value

    YEStrue if the condition was signaled; otherwise, NOfalse if the time limit was reached.

    Discussion

    You must lock the receiver prior to calling this method.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

    See Also

    – lock (NSLocking)

  • Signals the condition, waking up one thread waiting on it.

    Declaration

    Swift

    func signal()

    Objective-C

    - (void)signal

    Discussion

    You use this method to wake up one thread that is waiting on the condition. You may call this method multiple times to wake up multiple threads. If no threads are waiting on the condition, this method does nothing.

    To avoid race conditions, you should invoke this method only while the receiver is locked.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • Signals the condition, waking up all threads waiting on it.

    Declaration

    Swift

    func broadcast()

    Objective-C

    - (void)broadcast

    Discussion

    If no threads are waiting on the condition, this method does nothing.

    To avoid race conditions, you should invoke this method only while the receiver is locked.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.

  • name name Property

    The name of the condition.

    Declaration

    Swift

    var name: String?

    Objective-C

    @property(copy) NSString *name

    Discussion

    You can use a name string to identify a condition object within your code. Cocoa also uses this name as part of any error descriptions involving the condition.

    Import Statement

    import Foundation

    Availability

    Available in iOS 2.0 and later.