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
SCIObservableCollectioninstance.Declaration
Objective-C
- (nonnull instancetype)initWithCapacity:(NSInteger)capacity;Swift
init(capacity: Int)Parameters
capacityThe initial capacity.
-
Creates a new
SCIObservableCollectioninstance which contains the elements of the specified collection.Declaration
Objective-C
- (nonnull instancetype)initWithCollection:(nonnull NSArray<T> *)collection;Swift
init(collection: [T])Parameters
collectionThe collection with items to add.
-
Checks is the
objectis in the collection.Declaration
Objective-C
- (BOOL)contains:(nonnull T)object;Swift
func contains(_ object: T) -> BoolParameters
objectThe object to check.
Return Value
YES if the object is in collection, otherwise - NO;
-
Add an object into this
SCIObservableCollectioninstance.Declaration
Objective-C
- (void)add:(nonnull T)object;Swift
func add(_ object: T)Parameters
objectThe object to add.
-
Add an object into this
SCIObservableCollectioninstance if it wasn’t added before, otherwise nothing happensDeclaration
Objective-C
- (void)safeAdd:(nonnull T)object;Swift
func safeAdd(_ object: T)Parameters
objectThe object to add.
-
Add objects into
SCIObservableCollection.Declaration
Objective-C
- (void)addAll:(nonnull T)objects, ...;Parameters
objectsThe objects to add.
-
Insert object into
SCIObservableCollectionat Index.Declaration
Objective-C
- (void)insert:(nonnull T)object at:(NSInteger)index;Swift
func insert(_ object: T, at index: Int)Parameters
objectThe object to insert.
indexThe index to insert
objectat. -
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) -> IntReturn 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) -> TParameters
indexAn 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
objectobject to be stored at the specified position
indexindex of the element to replace
-
Removes object instance from this collection.
Declaration
Objective-C
- (BOOL)remove:(nonnull T)object;Swift
func remove(_ object: T) -> BoolParameters
objectObject 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
indexIndex 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
idxAn 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 anNSInvalidArgumentExceptionif theobjis nil.Warning
Raises anNSRangeExceptionif index is beyond the end of the array.Declaration
Objective-C
- (void)setObject:(nonnull T)obj atIndexedSubscript:(NSInteger)idx;Parameters
objThe object with which to replace the object at index index in the array. This value must not be nil.
idxThe 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>) -> BoolReturn 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) -> BoolParameters
predicateThe 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) -> BoolParameters
predicateThe 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) -> SelfParameters
predicateThe 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
predicateThe predicate to check.
destinationThe 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) -> IntParameters
predicateThe 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
predicateThe 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() -> TReturn 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) -> TParameters
predicateThe 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
predicateThe 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) -> TParameters
predicateThe predicate to check.
Return Value
The single item.
-
Returns an
NSArraycontaining 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]
View on GitHub