iOS & macOS Charting Documentation - SciChart iOS & macOS Charts SDK v4.x

SCIObservableCollection

@interface SCIObservableCollection<__covariant T> : NSObject <NSFastEnumeration>

Defines a collection implementation which allows to get notification about adding, removing objects from it.

Note

T is the type of underlying objects.
  • Checks if this colection is empty or no.

    Declaration

    Objective-C

    @property (nonatomic, readonly) BOOL isEmpty;

    Swift

    var isEmpty: Bool { get }

    Return Value

    YES if count is 0, otherwise - NO.

  • Gets the quantity of objects in collection.

    Declaration

    Objective-C

    @property (nonatomic, readonly) NSInteger count;

    Swift

    var count: Int { get }
  • Gets the first object from this instance of SCIObservableCollection.

    Declaration

    Objective-C

    @property (nonatomic, strong, readonly) T _Nonnull firstObject;

    Swift

    var firstObject: T { get }
  • Creates a new SCIObservableCollection instance.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCapacity:(NSInteger)capacity;

    Swift

    init(capacity: Int)

    Parameters

    capacity

    The initial capacity.

  • Creates a new SCIObservableCollection instance which contains the elements of the specified collection.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithCollection:(nonnull NSArray<T> *)collection;

    Swift

    init(collection: [T])

    Parameters

    collection

    The collection with items to add.

  • Checks is the object is in the collection.

    Declaration

    Objective-C

    - (BOOL)contains:(nonnull T)object;

    Swift

    func contains(_ object: T) -> Bool

    Parameters

    object

    The object to check.

    Return Value

    YES if the object is in collection, otherwise - NO;

  • Add an object into this SCIObservableCollection instance.

    Declaration

    Objective-C

    - (void)add:(nonnull T)object;

    Swift

    func add(_ object: T)

    Parameters

    object

    The object to add.

  • Add an object into this SCIObservableCollection instance if it wasn’t added before, otherwise nothing happens

    Declaration

    Objective-C

    - (void)safeAdd:(nonnull T)object;

    Swift

    func safeAdd(_ object: T)

    Parameters

    object

    The object to add.

  • Add objects into SCIObservableCollection.

    Declaration

    Objective-C

    - (void)addAll:(nonnull T)objects, ...;

    Parameters

    objects

    The objects to add.

  • Insert object into SCIObservableCollection at Index.

    Declaration

    Objective-C

    - (void)insert:(nonnull T)object at:(NSInteger)index;

    Swift

    func insert(_ object: T, at index: Int)

    Parameters

    object

    The object to insert.

    index

    The index to insert object at.

  • Returns the index of the first occurrence of the specified element in this collection.

    Declaration

    Objective-C

    - (NSInteger)indexOf:(nonnull T)object;

    Swift

    func index(of object: T) -> Int

    Return Value

    Returns the index of the first occurrence, otherwise - 1.

  • Returns the object located at the specified index.

    Declaration

    Objective-C

    - (nonnull T)itemAt:(NSInteger)index;

    Swift

    func item(at index: Int) -> T

    Parameters

    index

    An index within the bounds of the array.

    Return Value

    The object located at index.

  • Replaces the element at the specified position in this collection with the specified element.

    Declaration

    Objective-C

    - (void)setObject:(nonnull T)object at:(NSInteger)index;

    Swift

    func setObject(_ object: T, at index: Int)

    Parameters

    object

    object to be stored at the specified position

    index

    index of the element to replace

  • Removes object instance from this collection.

    Declaration

    Objective-C

    - (BOOL)remove:(nonnull T)object;

    Swift

    func remove(_ object: T) -> Bool

    Parameters

    object

    Object instance to be deleted from the collection, if present in it.

    Return Value

    YES If object is removed, otherwise - NO.

  • Removes objects instance from collection.

    Declaration

    Objective-C

    - (void)removeAt:(NSInteger)index;

    Swift

    func remove(at index: Int)

    Parameters

    index

    Index of object, which will be deleted from collection.

  • Removes all objects from collection.

    Declaration

    Objective-C

    - (void)clear;

    Swift

    func clear()
  • Add observer for the collection.

    Declaration

    Objective-C

    - (void)addObserver:
        (nonnull void (^)(SCIObservableCollection<T> *_Nonnull,
                          SCICollectionChangedEventArgs<T> *_Nonnull))observer;

    Swift

    func addObserver(_ observer: @escaping (SCIObservableCollection<T>, SCICollectionChangedEventArgs<T>) -> Void)
  • Remove observer from the collection.

    Declaration

    Objective-C

    - (void)removeObserver:
        (nonnull void (^)(SCIObservableCollection<T> *_Nonnull,
                          SCICollectionChangedEventArgs<T> *_Nonnull))observer;

    Swift

    func removeObserver(_ observer: @escaping (SCIObservableCollection<T>, SCICollectionChangedEventArgs<T>) -> Void)
  • Remove all observers from the collection.

    Declaration

    Objective-C

    - (void)removeAllObservers;

    Swift

    func removeAllObservers()
  • Returns the object at the specified index.

    Declaration

    Objective-C

    - (nonnull T)objectAtIndexedSubscript:(NSInteger)idx;

    Swift

    subscript(idx: Int) -> T { get set }

    Parameters

    idx

    An index within the bounds of the array.

    Return Value

    The object located at index.

  • Replaces the object at the index with the new object, possibly adding the object.

    Warning

    Raises an NSInvalidArgumentException if the obj is nil.

    Warning

    Raises an NSRangeException if index is beyond the end of the array.

    Declaration

    Objective-C

    - (void)setObject:(nonnull T)obj atIndexedSubscript:(NSInteger)idx;

    Parameters

    obj

    The object with which to replace the object at index index in the array. This value must not be nil.

    idx

    The index of the object to be replaced. This value must not exceed the bounds of the array.

  • Checks whether the collection is nil or empty.

    Declaration

    Objective-C

    + (BOOL)isNilOrEmpty:(nonnull SCIObservableCollection *)collection;

    Swift

    class func isNilOrEmpty(_ collection: SCIObservableCollection<AnyObject>) -> Bool

    Return Value

    YES if the collection is nil or empty.

  • Checks whether the collection contains at least one object which satisfies specified predicate.

    Declaration

    Objective-C

    - (BOOL)any:(nonnull SCIPredicate)predicate;

    Swift

    func any(_ predicate: @escaping SCIPredicate) -> Bool

    Parameters

    predicate

    The predicate to check.

    Return Value

    YES if list contains at least one object which satisfies specified predicate.

  • Checks whether all list objects satisfy specified predicate.

    Declaration

    Objective-C

    - (BOOL)all:(nonnull SCIPredicate)predicate;

    Swift

    func all(_ predicate: @escaping SCIPredicate) -> Bool

    Parameters

    predicate

    The predicate to check.

    Return Value

    YES if all list objects satisfy specified predicate.

  • Selects all items which satisfy specified predicate.

    Declaration

    Objective-C

    - (nonnull instancetype)where:(nonnull SCIPredicate)predicate;

    Swift

    func `where`(_ predicate: @escaping SCIPredicate) -> Self

    Parameters

    predicate

    The predicate to check.

    Return Value

    The collection with selected items.

  • Selects all items which satisfy specified predicate.

    Declaration

    Objective-C

    - (void)where:(nonnull SCIPredicate)predicate
        withDestination:(nonnull SCIObservableCollection *)destination;

    Swift

    func `where`(_ predicate: @escaping SCIPredicate, withDestination destination: SCIObservableCollection<AnyObject>)

    Parameters

    predicate

    The predicate to check.

    destination

    The list where selected items should be saved

  • Gets count of items from the list which satisfy specified predicate.

    Declaration

    Objective-C

    - (NSInteger)count:(nonnull SCIPredicate)predicate;

    Swift

    func count(_ predicate: @escaping SCIPredicate) -> Int

    Parameters

    predicate

    The predicate to check.

    Return Value

    Count of items from the list which satisfy specified predicate.

  • Selects the first item from the list, if list is empty returns nil.

    Declaration

    Objective-C

    - (nullable T)firstOrDefault;

    Swift

    func firstOrDefault() -> T?

    Return Value

    The first item from the list, or nil if list is empty.

  • Selects the first item from the list which satisfies specified predicate, if list is empty or match not found returns nil.

    Declaration

    Objective-C

    - (nullable T)firstOrDefault:(nonnull SCIPredicate)predicate;

    Swift

    func firstOrDefault(_ predicate: @escaping SCIPredicate) -> T?

    Parameters

    predicate

    The predicate to check.

    Return Value

    The first item from the list which satisfies specified predicate,, or null if list is empty.

  • Selects the first item from the list, if list is empty throws exception.

    Declaration

    Objective-C

    - (nonnull T)first;

    Swift

    func first() -> T

    Return Value

    The first item from the list.

  • Selects the first item from the list which satisfies specified predicate, if list is empty or match not found throws exception.

    Declaration

    Objective-C

    - (nonnull T)first:(nonnull SCIPredicate)predicate;

    Swift

    func first(_ predicate: @escaping SCIPredicate) -> T

    Parameters

    predicate

    The predicate to check.

    Return Value

    The first item from the list which satisfies specified predicate.

  • Selects single item which satisfies specified predicate, If list is empty returns null and if there are more than one item which satisfies predicate then throws exception.

    Declaration

    Objective-C

    - (nullable T)singleOrDefault:(nonnull SCIPredicate)predicate;

    Swift

    func singleOrDefault(_ predicate: @escaping SCIPredicate) -> T?

    Parameters

    predicate

    The predicate to check.

    Return Value

    The single item.

  • Selects single item which satisfies specified predicate, if there are more than one item which satisfies predicate then throws exception.

    Declaration

    Objective-C

    - (nonnull T)single:(nonnull SCIPredicate)predicate;

    Swift

    func single(_ predicate: @escaping SCIPredicate) -> T

    Parameters

    predicate

    The predicate to check.

    Return Value

    The single item.

  • Returns an NSArray containing all of the elements in this list in proper sequence (from first to last element).

    Declaration

    Objective-C

    - (nonnull NSArray<T> *)toArray;

    Swift

    func toArray() -> [T]