This document contains a description and summary guide to the use of various library units.
Because the that the library currently continues to improve, there may be some lag in this section of the real state of the software code. Therefore, in addition to studying this manual, we recommend to consult the description of the classes and library files.
Guide sections:
Introduction
Samond Classes Library is a suite of Objective-C protocols, classes and categories, incorporated with each other to perform the following tasks:
- expanding functionality of the standard Objective-C classes
- porting to Apple platforms the my old code for UNIX
- using of the developed solutions to more than one project
In the following sections we will look at various issues of the use of certain units of the library. The learning process of my development, we will follow various examples.
Just I want to draw your attention to the fact that several of my components in some duplicates the functionality of the individual elements of the standard classes, but personally I do not pay attention to it, because it allows for the implementation of projects to choose the most convenient and appropriate module.
Classes common elements
In this section, we examine the library components, by which all its modules, regardless of their type, have the same functionality. Order to ensure this both in our own classes, and classes in the standard Objective-C in the library are mandatory for the implementation of the protocols:
Implementation of these protocols is provided in the following structures:
Category NSObject(SCObject)
Category NSObject(SCObject) implements all of the above described protocols, thus providing support for the library functionality by all classes that are subclasses of the standard class NSObject. Because of this when you create a subclass of NSObject or categories of its existing child classes eliminates the need for the new implementation of the protocols - enough to override only the minimum necessary methods.
Class SCObject
All the library units (except for extending the functionality of the standard classes of categories and exception classes) are children of a common ancestor class SCObject. Beginning with version 1.2.1, this class is used to group own library classes, but in previous versions the class provided implementation of the main protocols, which is now implemented in the category NSObject(SCObject).
The class provides access to the following library features:
Class name determination
Common units for identifying instances of classes libraries use a method that is declared in key protocols as follows:
@property (nonatomic, readonly, copy) NSString *className;
The method returns the instance class name. Declaration of this method is necessary due to the fact that its support for the standard classes provided not on all platforms, while we tried to make our library to use the same regardless of the device on which the application using it will be performed.
When creating your own children of the NSObject or SCObject class you always must override this method. Also, the definition of this method is necessary for categories, which extends the standard classes and classes from the third-party libraries.
Serialized files support and protocol SCCoding
Standard Objective-C libraries make available features to read and write serialized files (special format of parameters list plist). To support these features protocol SCCoding (successor of standard protocol NSCoding) declares the following methods:
- (instancetype)initWithContentsOfSerializedFile:(NSString *)path;
- (BOOL)writeContentsToSerializedFile:(NSString *)path;
- Method initWithContentsOfSerializedFile: initializes the class instance using the contents of serialized file with the specified file.
- Method writeContentsToSerializedFile: writes receiver's encoded data into the serialized file with the specified path.
From standard protocol NSCoding protocol SCCoding inherits methods for interacting with the standard encoders (NSCoder):
- (instancetype)initWithCoder:(NSCoder *)coder;
- (void)encodeWithCoder:(NSCoder *)coder;
- Method initWithCoder: initializes the class instance using the specified coder.
- Method encodeWithCoder: encodes the receiver's data to the specified coder.
These methods must be overridden in child classes if they have their own fields. If a child class does not contain such fields, but only declares new or overrides existing methods, need to override these methods do not have.
More information about serialized files can be obtained from the guide section Serialized files support.
Dictionaries support and protocol SCDictionaring
Standard classes NSDictionary and NSMutableDictionary provide functionality for storing information in the properties list. This method of storage is used by the library as a way to store the instance data.
Protocol SCDictionaring requires implementation the following methods:
- (instancetype)initWithDataDictionary:(NSDictionary *)dictionary;
- (instancetype)initWithDataDictionaryFromFile:(NSString *)path;
- (void)writeToDataDictionary:(NSMutableDictionary *)dictionary;
- (void)writeToDataDictionaryFile:(NSString *)path atomically:(BOOL)atomically;
- (void)writeToDataDictionaryFile:(NSString *)path;
- (NSDictionary *)dataDictionary;
- initWithDataDictionary: initializes the class instance using the specified dictionary
- initWithDataDictionaryFromFile: initializes the class instance using the dictionary from the specified file
- writeToDataDictionary: writes the receiver's data into the specified dictionary
- writeToDataDictionaryFile:atomically: and writeToDataDictionaryFile: write the receiver's data into the dictionary file with the specified path
- dataDictionary: returns the dictionary with the receiver's data
If the child class contains its own data fields, you need to override the methods initWithDataDictionary: and writeToDataDictionary:.
Work with dictionaries describes in the guide section Dictionaries support.
Streams support and protocol SCStreaming
The streams - implemented on the basis of class SCStream technologies for data streaming using different technologies - are currently supported file streams, standard input and output streams, and null output stream.
Protocol SCStreaming required implementatopm of the following methods:
- (instancetype)initWithStream:(
SCStream *)stream;
- (instancetype)initWithFileStream:(NSString *)path;
- (void)writeToStream:(
SCStream *)stream;
- (void)writeToFileStream:(NSString *)path;
- (void)appendToFileStream:(NSString *)path;
- initWithStream: initializes class instance from the specified stream
- initWithFileStream: initializes class instance from the stream file with the specified path
- writeToStream: saves the receiver's class instance to the specified stream
- writeToFileStream: saves the receiver's class instance to the created stream file with the specified path
- appendToFileStream: appends the receiver's class instance to the new or existing stream file with the specified path
Methods initWithStream: and writeToStream: must be oveerided in the child class if this child class has the own data fields.
Details of streams you can obtain the the guide section Streams.
Collections support and protocol SCCollectioning
Collections are the data sets of various class instances. Collections are implemented as a separate class hierarchy based of the SCCollection class. Also some collections are implemented as a categories for extending the standard classes. To support collections each class must be implemented the following protocol SCCollectioning methods:
- copyObject returns the copy of receiver's instance
- compareWithObject: returns the result of comparison receiver's instance with the specified instance (overlaps if necessary)
Method compareWithObject: returns one of the following values:
Details of collections unit can be obtained in the guide section Collections.
Interaction with Data Objects
Data objects are instances of classes NSData and NSMutableData, that provides the access to different data in the form of raw bytes. For interaction with data objects and files and URLs class SCObject implements the following methods from the protocol SCDating:
- (instancetype)initWithData:(NSData *)data;
- (instancetype)initWithDataWrapper:(
SCData *)data;
- (instancetype)initWithContentsOfFile:(NSString *)path;
- (instancetype)initWithContentsOfURL:(NSURL *)url;
- (instancetype)initWithContentsOfURLString:(NSString *)urlString;
- (void)writeToData:(NSMutableData *)data;
- (BOOL)writeToFile:(NSString *)path;
- (BOOL)writeToURL:(NSURL *)url;
- (BOOL)writeToURLString:(NSString *)urlString;
- (NSData *)data;
- Method initWithData: initializes a class instance using the data from the specified data object of class NSData.
- Method initWithDataWrapper: initializes a class instance using the specified data object wrapper (class SCData instance). We recommend override this method instead the method initWithData:.
- Method initWithContentsOfFile: initializes a class instance using the data from the file with the specified path.
- Method initWithContentsOfURL: returns a class instance initialized by using data from the specified URL.
- With similar works a method initWithContentsOfURLString:, only instead of URL method accepts the URL string.
- Method writeToData: writes the class instance into the specified data object of the class NSMutableData.
- Method writeToFile: allows storing the class instance data into the file with the specified path.
- Method writeToURL: writes the data of the class instance into the specified URL.
- Method writeToURLString: also writes the class instance data into the URL, but uses the URL string instead URL.
- Method data returns a data object that contains the data of the class instance.
See details about data objects in the appropriate section of this manual.
Library functionality and standard classes
As noted above, when using with the children of class SCObject to interact with various library units necessary the overring only the specified methods.
However, the implementation of categories expanding the standard classes are subject to all of the methods of the relevant protocols.
Serialized files support
Serialized files are a special version of the properties list file that allow you to store various data in XML files. Reading and writing this file are made by standard class NSCoder instances.
The basic functionality of serialized files is implemented in the standard protocol NSCoding. SCL extends this functionality especially in order to bring it to a common format with other units.
This section of the manual describes the techniques and methods of working with sequential files. Requirements for class instances are described in the section Serialized files support and protocol SCCoding. Note that the main requirement - compliance with the protocol SCCoding.
Section contents:
Instances storing
Writing to serialized file by using the method writeContentsToSerializedFile:, as a parameter that gives the path to the file. If the write operation is successful, the method returns the value YES, otherwise it returns NO. If a serialized file already exists, its contents destroyed.
NSString *sourceString = @"Sample source string";
if ( [sourceString writeContentsToSerializedFile:@"/tmp/serial.plist"]) {
NSLog( @"Writing complited");
} else {
NSLog( @"Writing error");
}
2016-06-17 02:24:14.644 libtest[14033:493323] Writing complited
The resulting file is an example of a method using:
Instances loading
Initialize a class instance by using the data from the serialized file is performed by the method initWithContentsOfSerializedFile:, which is passes as a parameter the path to the serialized file.
NSString *string = [[NSString alloc] initWithContentsOfSerializedFile:@"/tmp/serial.plist"];
NSLog( @"%@", string);
2016-06-17 02:57:16.339 libtest[14308:521945] Sample source string
In many classes and categories are declared the additional class methods that return from serialized files downloaded and initialized instances of classes:
+ (
SCArray *)arrayWithCoder:(NSCoder *)coder;
+ (
SCArray *)arrayWithContentsOfSerializedFile:(NSString *)path;
Dictionaries support
Dictionaries on the basis of the standard classes NSDictionary and NSMutableDictionary and provide universal access to data stores, working on the principle of "key-value", according to which access to stored data is carried out by means of the keys, as who might be instances of any objects Objective-C.
Dictionaries are directly related to the properties list. With this available programmers are not only simple tools for the organization of universal storage, but also the possibility to control and edit these storage - built-in Xcode property list editor provides easy access to data.
With the dictionaries can interact instances of classes that match SCDictionaring protocol. Description of the implementation of this protocol is given in section Dictionaries support and protocol SCDictionaring.
Section contents:
Writing to data dictionary
The basic method for recording data in the dictionary is the method writeToDataDictionary:, receiving as a parameter the dictionary (NSMutableDictionary class instance), which is performed for instance writing. This method is subject to the overlap in child classes to keep in dictionaries other than the ancestor class data, if necessary.
Here is an example saving in the dictionary the class instance:
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[sourceDictionary writeToDataDictionary:dictionary];
NSLog( @"%@", dictionary);
2017-09-10 10:43:29.416454+0300 libtest[13324:1085938] {
"Read Only" = 0;
"Item 3" = {
Key = {
OBJC_ClassName = NSString;
String = System
};
Object = {
OBJC_ClassName = NSString;
String = MacOS
}
};
"Item 0" = {
Key = {
OBJC_ClassName = NSString;
String = Build
};
Object = {
OBJC_ClassName = NSNumber;
Number = 2319
}
};
"Item 1" = {
Key = {
OBJC_ClassName = NSString;
String = Verbose
};
Object = {
OBJC_ClassName = NSNumber;
Number = 0
}
};
"Item 2" = {
Key = {
OBJC_ClassName = NSString;
String = Startup
};
Object = {
OBJC_ClassName = NSDate;
Date = "2017-09-10 07:43:29 +0000"
}
};
Name = Configuration
}
Property dataDictionary returns the dictionary with stored class instance:
NSString *sourceString = @"Sample UTF-8 string";
NSLog( @"%@", sourceString.dataDictionary);
2016-06-17 04:25:17.156 libtest[14713:582644] {
"OBJC_ClassName" = NSString;
String = "Sample UTF-8 string";
}
Writing the class instance into the properties list is carried out by the following methods:
- (void)writeToDataDictionaryFile:(NSString *)path atomically:(BOOL)atomically;
- (void)writeToDataDictionaryFile:(NSString *)path;
Both methods accept as an argument the path to the file. If this file exists, its contents destroyed. The difference between the methods is that the first of these parameter atomically: allows you to specify whether a file is produced directly (NO) or through an intermediate file (YES). The second method always writes through an intermediate file.
After executing this code creates a file with the following content:
Since version 1.2.5 into a class NSMutableDictionary was added the following method:
This method stores the specified object with a given key in a data dictionary format. Use of this method instead a standard method setObject:forKey: guarantees that the object and its key will be saved regardless of their type - a standard dictionaries support into a dictionary file a limited number of types of objects and can use in a dictionary file only NSString keys.
Reading from data dictionary
To download class instances from the dictionaries and property lists you can using the following methods:
- (instancetype)initWithDataDictionary:(NSDictionary *)dictionary;
- (instancetype)initWithDataDictionaryFromFile:(NSString *)path;
Method initWithDataDictionary: initializes a class instance by using the data from the specified dictionary. By overlapping this method is carried out in the child classes to add support for loading from the dictionaries of their own data.
The method initWithDataDictionaryFromFile: carried out a class instance initialization by using the data from the property list with the specified path.
In many classes and c ategories are declared the additional class methods that returns downloaded from dictionaries and property lists and initializes class instances.
+ (
SCQueue *)queueWithDataDictionary:(NSDictionary *)dictionary;
+ (
SCQueue *)queueWithDataDictionaryFromFile:(NSString *)path;
Since version 1.2.5 in addition to a standard method objectForKey: into a class NSDictionary the method os added:
- (id)getObjectForKey:(NSString *)key;
This method creates and returns an object for a given key, which was saved earlier in a data dictionary format. Method provides support in dictionary files of all object types and keys, and not just what are by default supported by the classes NSDictionary and NSMutableDictionary.
Streams
Streams are a group of classes that implement the concept of byte-oriented input and output media. According to this concept, the streams realize input and output data withot any processing (exception for class instances and strings - their processing is a part of streams unit).
Section contents:
Stream classes hierarchy
The common ancestor of stream classes is class SCStream that defines all stream mechanisms, except input and output operation - in the class SCStream methods for this operations are abstract.
Child classes mandatory override input and output methods, and, if necessaity, adding the techniques that are specified to the certain stream type. For example, the child class SCFileStream declares open and closing methods.
Description of streams we start with methods of class SCStreams, but because of its abstractness in the example we will use real streams instances, primarily SCFileStream class instances. After the description common to all methods and techniques, we turn to the description of specified stream classes.
Stream error processing
When working with different streams can occur errors associated directly with the streams (or specific classes of stream) and appearing outside of our code, for example when trying to write to a file available only for reading.
Error handling mode is defines through the property errorHandling and can be one of the following values:
By default the strem throws the SCStreamException exception.
Exception SCSystemException generation
Mode is activated through the direct on indirect assignment of property errorHandling the value SCStreamErrorHandlingSystem.
When using this option strem unit throws a SCSystemException exception, which contains information about an error that has been returned by the system call or the function of standard libraries. Class SCSystemException instance property error contains the identifier of a detected system error. For more information see Programming Guide section Class SCSystemException.
Give an example of using this method of handling errors:
2016-07-05 23:01:53.322 libtest[5608:1486493] SCL-20002: No such file or directory (2, /tmp/error.txt)
Exception SCStreamException generation
Mode is activated through the direct or indirect assignment of property errorHandling the value SCStreamErrorHandlingStream.
This error handling mode throws an exception SCStreamException which contains information to help determine the cause of the error. Unlike class SCSystemException instance class SCStreamException contains information about stream specified error.
With this exception can be handled the following errors:
Here is an example of stream error handling through thr throwing the exception SCStreamException:
2016-07-05 22:52:34.159 libtest[5534:1475780] SCL-20029: Stream "/tmp/start.txt" open error (2)
Stream status changing
Mode is activated through the direct or indirect assignment of property errorHandling the value SCStreamErrorHandlingStatus.
When using this error handling mode the stream unit processes the detected error by using the following algorithm:
- If an error occurs during the system call execution the stream unit creates class SCSystemException instance, pointer to which is assosiated to the class SCStream property systemException without throwing this exception instance.
- Stream unit creates the SCStreamException instance, then assigns the pointer to the class SCStream property streamException without throwing this exception instance.
- If the stream instance has the delegate object, the stream unit calls the method stream:didDetectError: of the delegate object is called.
- The stream status property is set to the correspondig value.
- Control is returned to the superior code.
Here is an example of error handling using this method:
NSLog(
@"Stream status: %d", stream.
status);
2016-07-05 23:19:45.803 libtest[5678:1502988] Stream status: -20029
Stream status
Stream status is determined by the following property:
Directly through the SCStreamStatus type defines the following stream statuses:
Child classes can define their own types of derived stream states. For example, class SCFileStream defines the type SCFileStreamStatus, which extends the basic stream states. Details of this extension are described in the Programming Guide section Files and class SCFileStream.
Stream Properties
Class SCStream contains the declaration of the following properties:
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign) BOOL opened;
@property (nonatomic, assign, readonly, getter=eof) BOOL eof;
@property (nonatomic, assign, getter=delegate, setter=setDelegate:) id<SCStreamDelegate> delegate;
@property (nonatomic, readonly, assign) BOOL readable;
@property (nonatomic, assign, readonly, getter=writable) BOOL writable;
@property (nonatomic, assign, readonly, getter=readOnly) BOOL readOnly;
@property (nonatomic, assign, readonly, getter=writeOnly) BOOL writeOnly;
@property (nonatomic, assign, readonly, getter=readWrite) BOOL readWrite;
@property (nonatomic, assign, readonly, getter=streamException)
SCStreamException *streamException;
@property (nonatomic, assign, readonly, getter=systemException)
SCSystemException *systemException;
- Property errorHandling detects the error handling mode. See the Programming Guide section Stream error processing.
- Property status (read only) stores the stream current status. See the Programming Guide section Stream status.
- Property name (read only) contains the stream name. For the class SCFileStream instances this propery contains the file stream path.
- Property opened (read only) returns the value YES for the opened stream and value NO for the closed stream.
- Property eof (read only) contains the value YES if the end of stream detected. In the class SCStream this property is abstract and method eof must be overriden.
- Property delegate stores the pointer to the stream delegate object. See the Programming Guide section Delegation protocol SCStreamDelegate.
- Properties readable and writable (read only) can determine whether the stream supports read and write operations.
- Property readOnly (read only) returnes the YES value for streams, which does not support write operations (opens only for reading) and NO value if the stream supports write operations.
- Property readWrite (read only) returns the YES value if the stream supports both read and write operations.
Child classes can be declare the own properties.
Data reading from stream
The main method of reading data from the stream SCStream declared in the class as follows:
This method reads from the stream specified number of bytes into the specified by the pointer buffer. Method returns the actually readed bytes number. In the base class SCStream this method is abstract and must be overridden in all child classes for supporting real reading operations.
In addition to the basic reading method class SCStream declares the specialized methods, providing reading into the buffer the specified data types. In fact, these methods call the method readBytes:toBuffer: with the hidden indication of the number of bytes, which corresponding to the specified type. This methods also return the actually readed number of bytes.
- (
SCSize)readToChar:(
char *)buffer;
- (
SCSize)readToUnichar:(unichar *)buffer;
- (
SCSize)readToBool:(BOOL *)buffer;
- (
SCSize)readToNSInteger:(NSInteger *)buffer;
- (
SCSize)readToNSUInteger:(NSUInteger *)buffer;
Also class SCStream declares the methods, which return from the stream the data for the corresponding types.
- (char)readChar;
- (unichar)readUnichar;
- (const char *)readCharString;
- (BOOL)readBool;
- (NSInteger)readNSInteger;
- (NSUInteger)readNSUInteger;
Note that the data reading from the stream is possible only if the stream supports a data read operations. Otherwise, the stream unit detects an error.
Data writing to stream
Class SCStream declares the following primary data writing method:
- (
SCSize)writeBytes:(
SCSize)count fromBuffer:(const
void *)buffer;
This method writes into the stream the specified number of bytes from the specified buffer. Method also returns the actually writed number of bytes. In the class SCStream this method is abstract and must be overridden in any child class.
To simplify the work with the standard data types class SCStream declares the following writing methods:
- (void)writeByte:(
SCByte)variable;
- (void)writeUByte:(
SCUByte)variable;
- (void)writeShort:(
SCShort)variable;
- (void)writeLong:(
SCLong)variable;
- (void)writeULong:(
SCULong)variable;
- (void)writeChar:(char)variable;
- (void)writeUnichar:(unichar)variable;
- (void)writeCharString:(const char *)variable;
- (void)writeBool:(BOOL)variable;
- (void)writeFloat:(
SCFloat)variable;
- (void)writeNSInteger:(NSInteger)variable;
- (void)writeNSUInteger:(NSUInteger)variable;
I want note that the writing operations are possible only if this stream supports this operations. If any of writing methods was called for read only stream, the error was occur.
Streams and classes
Although the basis of streams is character-oriented data transferring, the main stream purpose is class instances transmitting. With streams can interact only instances, which implements the protocol SCStreaming:
Protocol SCStreaming methods
For supporting interaction with streams protocol SCStreaming declares the following methods:
- (void)writeToStream:(
SCStream *)stream;
- (instancetype)initWithStream:(
SCStream *)stream;
- Method writeToStream: saves the receiver's class instance to the specified stream.
- Method initWithStream: initializes class instance from the specified stream.
In addition to the method of initializing an instance the class can be declared a class method to create an instance by using the loaded from stream data. Here is an example of such class method from the category NSString(SCString):
+ (NSString *)stringWithStream:(
SCStream *)stream;
Class SCFileStream uses a number of protocol SCStreaming methods, which are described in Programming Guide section Files and class SCFileStream.
Class SCStream methods
For reading and writing class instances SCStream declares the following methods:
The method writeObject: writes into the stream the specified class instance. Just before writing class instance the stream unit identifies the class of the instance and writes into the stream the service information required for the later class instance loading. After writing the service information the stream unit calls the stored class method writeToStream:.
Method readObject reads from the stream the service information, detectes the required class name, creates the required class instance and calls the instance method initWithStream: for loading the instance specified data from the stream.
Give an example of the using the methods writeObject: and readObject:
[outputStream
writeObject:[NSNumber numberWithInteger:19091975]];
while ( YES) {
if ( !object) break;
NSLog( @"Object %d: %@", counter, object);
counter++;
}
2016-07-06 15:37:15.691 libtest[8743:2490662] Object 0: Sample String
2016-07-06 15:37:15.692 libtest[8743:2490662] Object 1: This is a test
2016-07-06 15:37:15.693 libtest[8743:2490662] Object 2: <null>
2016-07-06 15:37:15.694 libtest[8743:2490662] Object 3: 19091975
Streams and text files
Unlike ordinary files, text files do not consist of a sequence of characters. Text files contain the character strings of different length, each of which ends with a special and of line character. To work with such data class SCStream declares the some methods.
For writing text strings into the stream class SCStream declares the following methods:
- (void)writeString:(NSString *)string encoding:(NSStringEncoding)encoding;
- (void)writeString:(NSString *)string;
- method writeString:encoding: writes into the stream the specified text string with the specified encoding end of line character
- method writeString: writes into the stream the specified UTF-8 text string with end of line character
Example of writing text strings into the stream:
This is a test
This is a test again
For reading text strings from the stream class SCStream declares the following methods:
- (NSString *)readStringWithEncoding:(NSStringEncoding)encoding max:(
SCInteger)max;
- (NSString *)readStringWithEncoding:(NSStringEncoding)encoding;
- (NSString *)readStringWithMax:(
SCInteger)max;
- (NSString *)readString;
- method readStringWithEncoding:max: returns the string with the specified max length and readed by using the specified encoding. If the stream line exceeds the maximum length, extending beyond the symbols are discarded.
- method readStringWithEncoding: returns the string readed by using the specified encoding.
- method readStringWithMax: returns the string with the specified max length and readed by using the UTF-8 encoding
- method readString returns the string readed by using the UTF-8 encoding.
Here is an example of strings reading from the stream:
NSString *string;
while ( ( string = [file readString])) NSLog( @"%@", string);
2016-07-06 17:46:00.777 libtest[9504:2628316] #
2016-07-06 17:46:00.777 libtest[9504:2628316] # /etc/afpovertcp.cfg is used to set the system-wide AFP defaults
2016-07-06 17:46:00.777 libtest[9504:2628316] # for the LibcAT AppleTalk library.
2016-07-06 17:46:00.778 libtest[9504:2628316] #
2016-07-06 17:46:00.778 libtest[9504:2628316] # Copyright 1998 Apple Computer, Inc.
2016-07-06 17:46:00.778 libtest[9504:2628316] #
2016-07-06 17:46:00.778 libtest[9504:2628316] # If this file exists, TCP/IP will be used as the default transport
2016-07-06 17:46:00.778 libtest[9504:2628316] # protocol for AFP. Otherwise ATP will be used.
2016-07-06 17:46:00.778 libtest[9504:2628316] #
2016-07-06 17:46:00.779 libtest[9504:2628316] # Supported commands are:
2016-07-06 17:46:00.779 libtest[9504:2628316] #
2016-07-06 17:46:00.779 libtest[9504:2628316] # quantum [quantum size]
2016-07-06 17:46:00.779 libtest[9504:2628316] # 16384 is a reasonable value; 4624 is the default.
2016-07-06 17:46:00.814 libtest[9504:2628316] #
2016-07-06 17:46:00.814 libtest[9504:2628316] # port [TCP listen port]
2016-07-06 17:46:00.814 libtest[9504:2628316] # The default is 548.
2016-07-06 17:46:00.815 libtest[9504:2628316] #
2016-07-06 17:46:00.815 libtest[9504:2628316] # It is legal for this file to exist and for it to have no contents.
2016-07-06 17:46:00.815 libtest[9504:2628316] #
2016-07-06 17:46:00.815 libtest[9504:2628316] quantum 16384
Delegation protocol SCStreamDelegate
If for the stream is specified the delegate object (instance of the class, which implemented the protocol SCStreamDelegate), then the appropriate methods of delegate object will be called when the events occur.
Delegation protocol defines methods to respond to the following events:
- stream error processing
- writing to stream events
- reading from stream events
Child classes may be added to the delegate object handlers of their own events. That's what makes SCFileStream class.
A full list of the methods shown in the description of the relevant protocol and class SCStreamDelegate.
Stream statistics
In the during the work a stream is accumulate basic statistical data. Access to this data is carried out through class SCStream instance properties (read only):
@property (nonatomic, assign, readonly, getter=totalRead)
SCULong totalRead;
@property (nonatomic, assign, readonly, getter=totalWrite)
SCULong totalWrite;
@property (nonatomic, assign, readonly, getter=lastRead)
SCULong lastRead;
@property (nonatomic, assign, readonly, getter=lastWrite)
SCULong lastWrite;
- property totalRead shows total number of characters that have been read since the opening of stream
- property totalWrite contains the total number of characters written to the stream since its opening
- property lastRead allows the programmer to find the number of characters read from the stream during the last read operation
- property lastWrite gives access to the number of characters written into the stream during the last write operation
For resetting the stream statistics class SCStream declares the method resetStats.
Files and class SCFileStream
As already states, SCStream is an abstract class and con not be used directly. Therefore, the different child classes have benn created, the central of which is the class SCFileStream, that is, a class that implements one of the most popular stream type - disk files. This guide section examine the various aspects of class SCFileStream:
Protocol SCStreaming methods
Protocol SCStreaming for interacting with file streams declares the following methods:
- (void)writeToFileStream:(NSString *)path;
- (void)appendToFileStream:(NSString *)path;
- (instancetype)initWithFileStream:(NSString *)path;
- method writeToFileStream: saves the receiver's class instance to the created stream file with the specified path
- method appendToFileStream: appends the receiver's class instance to the new or existing stream file with the specified path
- method initWithFileStream: initializes class instance from the stream file with the specified path
In addition to the initialization methods may be declared the class methods for creating class instances by using the data readed from the file stream with the specified path. For example, category NSString(SCString) declares the following class methods:
+ (NSString *)stringWithFileStream:(NSString *)path;
Below is an example of the using the protocol SCStreaming methods:
NSString *source = @"This is a test again";
[source writeToFileStream:@"/tmp/string.dat"];
NSString *string = [NSString stringWithFileStream:@"/tmp/string.dat"];
NSLog( @"%@", string);
2016-07-06 16:34:03.204 libtest[9064:2557807] This is a test again
File stream error processing
File stream error are handled as exactly as SCStream errors. The only difference is that in the class SCStreamException declares the following additional exceptions:
File stream status
Class SCFileStream extends the stream status data type SCStreamStatus by declaring the file stream status data type SCFileStreamStatus, which defines the following status constants:
File stream opening modes
File stream can be opened in various modes. Open mode defines by the class SCFileStream instance property (read only):
Type SCFileStreamOpenMode defines the following file stream open modes:
- SCFileStreamOpenReadOnly - Open file for reading. The stream is positioned at the beginning of the file.
- SCFileStreamOpenReadWrite - Open file for reading and writing. The stream is positioned at the beginning of the file.
- SCFileStreamOpenWriteOnly - Truncate file to zero length or create text file for writing. The stream is positioned at the beginning of the file.
- SCFileStreamOpenWriteRead - Open for reading and writing. The file is created if it does not exist, otherwise it is truncated. The stream is positioned at the beginning of the file.
- SCFileStreamOpenAppendWriteOnly - Open for writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening seek operations.
- SCFileStreamOpenAppendReadWrite - Open for reading and writing. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening seek operations.
File stream open mode defines during opening, initializing and creating the stream and does not changes during read, write and offset operations. You cannot change the open mode thithout closing and reopening the file stream.
File stream opening and closing
Class SCFileStream declares the following methods for opening file stream:
- (void)openWithPath:(NSString *)path;
- (void)openReadOnlyWithPath:(NSString *)path;
- (void)openWriteOnlyWithPath:(NSString *)path;
- (void)openAppendWithPath:(NSString *)path;
- Method openWithPath:mode:handling: opens the receiver's stream using the following arguments:
- Method openWithPath:mode: is the primary way of opening the file stream. All other methods for opening, initializing and creating file streams call this method. Error processing is based on the value of the instance property errorHandling.
- Method openWithPath: opens for reading and writing (SCFileStreamOpenReadWrite) the stream using the specified path. The stream is positioned at the beginning of the file. Error processing is based on the value of the instance property errorHandling.
- Method openReadOnlyWithPath: opens for reading (SCFileStreamOpenReadOnly) the stream using the specified path. The stream is positioned at the beginning of the file.
- Method openWriteOnlyWithPath: truncates stream to zero length or creates stream for writing using the specified path. The stream is positioned at the beginning of the file. After execution of this method file stream is opened in the mode SCFileStreamOpenWriteOnly.
- Method openAppendWithPath: opens for writing the stream using the specified path (SCFileStreamOpenAppendWriteOnly). The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening seek operations.
If no errors detected during the opening operation, than the file stream status is set to SCFileStreamOK, and an instance property opened is set to value YES. If you call the any of stream open methods for already opening stream, than call of this method is ignored.
For closing the file stream the class SCFileStream declares the following method:
Method closes the previously opened file stream and sets the instance property opened to the value NO. If you call the method close for closed file stream, the method call is ignored.
File stream creating
Class SCFileStream declares the following method for creating the class instances:
+ (instancetype)fileStreamWithPath:(NSString *)path
+ (instancetype)fileStreamWithPath:(NSString *)path;
+ (instancetype)readOnlyFileStreamWithPath:(NSString *)path;
+ (instancetype)writeOnlyFileStreamWithPath:(NSString *)path;
+ (instancetype)appendFileStreamWithPath:(NSString *)path;
+ (instancetype)fileStream;
- Class method fileStreamWithPath:mode:delegate:handling: returns the opened stream created by using the specified stream path, open mode, delegate object, and error handling type.
- Class method fileStreamWithPath:mode:delegate: returns the opened stream created by using the specified stream path, open mode and delegate object. Error processing is performed through exception SCStreamException throwing.
- Class method fileStreamWithPath:mode: returns the opened stream created by using the specified stream patn and open mode. Created class instance does not have delegate object. Error handling is performed through exception SCStreamException throwing.
- Class method appendFileStreamWithPath: returns the opened for writing (SCFileStreamOpenAppendWriteOnly) the stream created by using the specified path. The file is created if it does not exist. The stream is positioned at the end of the file. Subsequent writes to the file will always end up at the then current end of file, irrespective of any intervening seek operations. Create stream instanse does not have delegate object. Error handling is performed by using the SCStreamException exception throwing.
- Class method fileStream returns the stream with the default properties. Method returns the pointer to the closed stream.
All class methods, except fileStream, open the created file stream. If this operation is successfully, then instance property opened is set to value YES, and instance property status is set to value SCFileStreamOK.
Introducing an example of using the file stream creating methods:
NSLog(
@"/etc/ttys status: %d", ttys.
status);
if ( ttys.
opened) NSLog(
@"/etc/ttys is opened");
2016-07-07 03:20:14.014 libtest[11678:3116658] /etc/ttys status: 0
2016-07-07 03:20:14.014 libtest[11678:3116658] /etc/ttys is opened
File stream initializing
Class SCFileStream declares the following methods for initializing the class instances:
- (instancetype)initWithPath:(NSString *)path
- (instancetype)initWithPath:(NSString *)path;
- (instancetype)initReadOnlyWithPath:(NSString *)path;
- (instancetype)initWriteOnlyWithPath:(NSString *)path;
- (instancetype)initAppendWithPath:(NSString *)path;
- (instancetype)init;
- Method initWithPath:mode:delegate:handling: initializes and opens the file stream using the specified file stream path, open mode, delegate object and error handling mode. This method is a designed class initializer.
- Method initWithPath:mode:delegate: initializes and opens the file stream using the specified file stream path, open mode and delegate objects. Error handling is performed by using the SCStreamException exception throwing.
- Method initWithPath:mode: uses for initializing and opening the file stream with the specified file stream path and open mode. Initialized class instance does not have the delegation object. Error processing is performed by using the SCStreamException exception throwing.
- Method initReadOnlyWithPath: initializes and opens for reading (SCFileStreamOpenReadOnly) the file stream using the specified file stream path and without delegate object. Error processing is performed by using the throwing of the SCStreamException exception. Write operations for the initialized class instance are not allowed.
- Method init initializes file stream without opening and default properties.
All initialization methods, except init, open the file stream after initialization. If the open operation is successfully, the instance property SCStream.opened "opened" is set to value YES, and the property status is set to value SCFileStreamOK.
File stream offset
File streams support the offset operations, that is a change the position of next read or write operation. Class SCFileStream declares the following offset methods:
@property (nonatomic, readonly, assign) BOOL eof;
- (void)setOffset:(NSInteger)offset;
- (NSInteger)offset;
- (void)rewind;
- Property eof determines end of stream flag. It returns the value YES if the read position is set to the end of the file stream.
- Method setOffset:whence: sets the stream position to the specified offset and whence.
- Method setOffset: sets the stream position to the specified offset from the begin of the stream.
- Method offset returns the offset in bytes from the begin of the stream.
- Method rewind sets the position to the begin of the file stream.
When using for positioning the method setOffset:whence: as the second argument passes one of the floowing constant from the type SCFileStreamOffsetWhence :
Delegation protocol SCStreamDelegate methods
Class SCFileStream adds into the delegation protocol SCStreamDelegate methods, which called when file stream is open or close. See details in the Programming Guide section Delegation protocol SCStreamDelegate.
Standard streams
Library includes the following classes to provide access to the standard input and output streams:
All three of the above classes are children of the SCStream class. In the following sections, each of classes is described in more detail.
Standard input stream SCStandardInputStream
Class SCStandardInputStream gives programmers access to the standard input stdin. This stream provides a read-only operations.
To provide access to this stream in the class declared the following methods:
+ (instancetype)stdinStream;
- Class method stdinStreamWithDelegate: returns the stdin stream opening by using the specified delegate object.
- Class method stdinStream returns the stdin stream without delegate object.
Please note the both of this methods always return a pointer to the same stream - because the standard input stream stdin exists in a single copy in the operating system. Furthemore the existence of multiple instances of classes may potentially lead to conflicts, especially when the objects were created several different threads.
Provide the example of using the standard input stream:
while ( !input.eof) {
if ( string) NSLog( @"%@", string);
}
Sample input string
2016-07-08 00:54:46.809 libtest[17772:4042392] Sample input string
Request for proposal
2016-07-08 00:54:54.691 libtest[17772:4042392] Request for proposal
Last entered string
2016-07-08 00:55:01.249 libtest[17772:4042392] Last entered string
Standard output stream SCStandardOutputStream
Class SCStandardOutputStream provides programmers access to the standard output stream stdout. This stream allows only a write operations.
For access to this output stream in the class SCStandardOutputStream declares the following methods:
+ (instancetype)stdoutStream;
- Class method stdoutStreamWithDelegate: returns the stdout stream opening by using the specified delegate object.
- Class method stdoutStream returns the stdout stream without the delegate object.
Please note the both of this methods always return a pointer to the same stream - because the standard output stream stdout exists in a single copy in the operating system. Furthemore the existence of multiple instances of classes may potentially lead to conflicts, especially when the objects were created several different threads.
Example of using the standard output stream:
Sample output string
This is a test string
Last output string
Standard error stream SCStandardErrorStream
Class SCStandardErrorStream provides programmers access to the standard error stream stderr. This stream provides a write-only operations.
To provide access to this stream in the class SCStandardErrorStream declares the following classes:
+ (instancetype)stderrStream;
- Class method stderrStreamWithDelegate: returns the stderr stream opening by using the specified delegate object.
- Class method stderrStream returns the stderr stream without the delegate object.
Please note that the both of described methods always return a pointer to the same stream - because the standard error stream stderr exists in a single copy in the operating system. Furthemore the existence of multiple instances of classes may potentially lead to conflicts, especially when the objects were created several different threads.
Example of using the standard error stream:
System error: 2319
Application error: 2315
Fatal falture
Null output stream SCNullStream
Class SCNullStream is a child of the class SCStream and provides access to the system device /dev/null. This stream supports only write operations. The main purpose of the null stream - the ability to write into the stream an unlimited number of data (all writed into the null stream data are discarded).
Access to the null stream provides with using the following class SCNullStream methods:
+ (instancetype)nullStream;
- Class method nullStreamWithDelegate: returns the /dev/null stream opening by using the specified delegate object.
- Class method nullStream returns the /dev/null stream without using the delegate object.
Please note that the both of this methods always return a pointer to the same stream - because the /dev/null stream exists in a single copy in the operating system. Furthemore the existence of multiple instances of classes may potentially lead to conflicts, especially when the objects were created several different threads.
Collections
Collections are instances of classes, which are containers for instances of other classes. A typical example of the collection is object instances array. The library includes two types of collections:
- library collections, which are the children of the abstract class SCCollection:
- categories that extend the functionality of standard classes Objective-C:
Library collections interact with processed objects through the protocol SCCollectioning methods.
Section contents:
Collection classes hierarchy
Class SCCollection is an abstract class, because it does not contains real data storage mechanisms, implemented in the child classes in accordance with their function. However class SCCollection declares the collection common methods, which override in the child classes.
Collection class types
To organize the distribution of functionality by collection classes and categories and simplify implementation of collection functions we create the set of protocols, compliance with which determines the compatibility of library collections. In this set include the following protocols:
In the following paragraphs, these protocols will be reviewed in more details.
SCCollection protocol
Protocol defines the list of properties and methods, which implementation in the class or category required for support functionality of read-only collections. All collection classes are compliance to this protocol. Also with SCCollection protocol are compliance the following categories of standard classes:
Protocol declares the following properties, which required for all collection classes:
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign)
SCIndex count;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL readOnly;
@property (nonatomic, readonly, retain) id<SCCollectionDelegate> delegate;
Collection classes and categories must be implemented the following initialization methods:
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
SCCollection protocol requires the implementation of the following objects search methods:
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
Protocol requires the implementation of the following converting properties for all collection instances:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, retain) NSArray *foundationArray;
@property (nonatomic, readonly, retain) NSSet *foundationSet;
@property (nonatomic, readonly, retain) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, retain) NSDictionary *foundationDictionary;
Attention! When using instances of the class NSOrderedSet you must use the property libraryArray instead a property array because of existence in a class the method with this name.
For collection type detection all collection classes and categories must emplemented the following protocol SCCollection properties:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
Also protocol declares the following optional properties for support the collection enumerating:
@property (nonatomic, readonly, assign) NSEnumerator *objectEnumerator;
@property (nonatomic, readonly, assign) NSEnumerator *reverseObjectEnumerator;
Support of operator for..in in collection classes is provided with implementation of the following protocol method:
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)objects count:(NSUInteger)count;
For comparing collections the protocol declares following methods:
Description above properties and methods given in the relevant sections of the Programming Guide.
SCMutableCollection protocol
Protocol SCMutableCollection extends the protocol SCCollection by declaring the methods, which must be implemented in the collection classes and categories for support the collection changing. All librray collections implement this methods of protocol SCMutableCollection. Also with the SCMutableCollection protocol are compliance the following standard classes categories:
Protocol requires the implementation of the following coping methods:
For protocol compliance must be implemented the following object adding methods:
Also protocol requires the implementation of the following object removing methods:
- (void)removeAllObjects;
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
See the details of this methods in the corresponding sections of the Programming Guide.
SCIndexedCollection protocol
Protocol SCIndexedCollection declares methods, which must be implemented in the indexed collections. Indexed collections support the direct access to each collection object by using the specified index. With this protocol are compliance the following library classes:
Also to the protocol SCIndexedCollection are compliance the following categories of the standard classes:
Protocol requires the implementation of the following properties and methods for indexed access to collection objects:
@property (nonatomic, readonly, assign) id firstObject;
@property (nonatomic, readonly, assign) id lastObject;
- (id)objectAtIndex:(
SCIndex)index;
- (id)objectAtIndexedSubscript:(
SCIndex)index;
Also protocol declares the following required properties and methods for object search:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastObject;
Details of indexed collection methods provides in the Programming Guide corresponding sections.
SCMutableIndexedCollection protocol
Protocol SCMutableIndexedCollection declares methods, which can change the objects in the indexed collections. With this protocol are compliance the following library classes:
Also to the protocol are compliance the following standard classes categories:
Protocol SCMutableIndexedCollection declares the following required methods:
- (void)removeObjectAtIndex:(
SCIndex)index;
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
For detailed information about this methods see the corresponding sections of the Programming Guide.
SCKeyedCollection protocol
Protocol SCKeyedCollection declares methods, which must be implemented in the keyed collections. Keyed collections support the direct access to each collection object by using the specified key. With this protocol are compliance the following library classes:
Also to the protocol SCKeyedCollection are compliance the following categories of the standard classes:
Protocol requires the implementation of the following properties and methods for keyed access to collection objects:
- (id)objectForKey:(NSString *)key;
- (id)objectForKeyedSubscript:(NSString *)key;
- (id)valueForKey:(NSString *)key;
Details of keyed collection methods provides in the Programming Guide corresponding sections.
SCMutableKeyedCollection protocol
Protocol SCMutableKeyedCollection declares methods, which can change the objects in the keyed collections. With this protocol are compliance the following library classes:
Also to the protocol are compliance the following standard classes categories:
Protocol SCMutableKeyedCollection declares the following required methods:
- (void)setObject:(
id<
SCCollectioning>)object forKeyedSubscript:(NSString *)key;
- (void)removeObjectForKey:(NSString *)key;
For detailed information about this methods see the corresponding sections of the Programming Guide.
Collection support types
For collections support file SCCollectionProtocols.h declares the following data types:
- Type SCIndex uses in the indexed collections and text objects as a item index.
- Type SCCollectionType declares a set of constants that identified a various types of the supported collections:
Collection properties
Class SCCollection instances declares the following properties:
@property (nonatomic, readwrite, retain) NSString *name;
@property (nonatomic, readonly, assign)
SCIndex count;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readwrite, assign) BOOL readOnly;
@property (nonatomic, readwrite, retain) id<SCCollectionDelegate> delegate;
@property (nonatomic, readonly, copy) NSString *typeName;
- Property name defines the collection name.
- Property count (read only) returns the collection objects count.
- Property empty (read only) returns the value YES if the collection does not contains objects and value NO if the collection contains at least one object.
- Property readOnly defines the possibility of collection changes. Values of this property can be changed programmatically.
- Property delegate allows to define the collection delegate object. This delegate objects describes in the Programming Guide section Delegation protocol SCCollectionDelegate.
- Property typeName (read only) returns the collection type name.
Coping collections
Coping methods remove the current collection content and replace it by the objects from the specified methods parameters. Class SCCollection declares the following coping methods:
- Method setCollection: replaces the content and settings of the receiving collection of content and settings from the specified existing collection:
[existingArray addObject:@"String 00"];
[existingArray addObject:@"String 01"];
[existingArray addObject:@"String 02"];
[source addObject:@"String 10"];
[source addObject:@"String 10"];
[source addObject:@"String 10"];
NSLog( @"%@", existingArray);
NSLog( @"%@", existingArray);
2016-07-11 01:25:17.215 libtest[22320:5173906] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-11 01:25:17.216 libtest[22320:5173906] Array count=3: (
"String 10",
"String 10",
"String 10"
)
- Method setObject: replaces the content of the receiving collection by the specified object.
[existingArray addObject:@"String 00"];
[existingArray addObject:@"String 01"];
[existingArray addObject:@"String 02"];
NSLog( @"%@", existingArray);
NSLog( @"%@", existingArray);
2016-07-11 01:43:46.979 libtest[22417:5184286] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-11 01:43:46.980 libtest[22417:5184286] Array count=1: (
"String 10"
)
- Method setObjects: replaces the receiver's collection content by the items from the specified existing objects.
[existingArray addObject:@"String 00"];
[existingArray addObject:@"String 01"];
[existingArray addObject:@"String 02"];
NSLog( @"%@", existingArray);
[existingArray
setObjects:@"String 10", @"String 11", nil];
NSLog( @"%@", existingArray);
2016-07-11 01:46:38.537 libtest[22456:5186176] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-11 01:46:38.537 libtest[22456:5186176] Array count=2: (
"String 10",
"String 11"
)
If the collection in the read-only mode (property readOnly is set to value YES), than the collection generate the error SCL-20043.
Comparing collections
Class SCCollection declares the following methods for comparing collection with other collection instances:
- (BOOL)isEqual:(id)object;
- Method isEqualToCollection: returns a boolean value that indicates whether the contents of the receiving collection is equals to the contents of another given collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
[collection addObject:@"String 00"];
[collection addObject:@"String 01"];
NSLog( @"%d", [array isEqualToCollection:collection]);
[collection addObject:@"String 02"];
NSLog( @"%d", [array isEqualToCollection:collection]);
collection.
name =
@"sampleArray";
NSLog( @"%d", [array isEqualToCollection:collection]);
2016-07-11 05:04:58.792 libtest[23602:5698937] 0
2016-07-11 05:04:58.793 libtest[23602:5698937] 1
2016-07-11 05:04:58.793 libtest[23602:5698937] 1
- Method isEqual: returns a boolean value that indicates whether the receiver and a given object are equal. This method is equal to the method isEqualToCollection: if this method as an argument given the pointer to the collection, otherwise this method returns value NO without comparing.
Enumerating collection objects
Class SCCollection declares the object enumerating properties and methods:
@property (nonatomic, readonly, assign) NSEnumerator *objectEnumerator;
@property (nonatomic, readonly, assign) NSEnumerator *reverseObjectEnumerator;
- (void)enumerate;
- (void)reverseEnumerate;
- Property objectEnumerator returns an enumerator object that lets you access each object in the collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSEnumerator *enumerator = [array objectEnumerator];
id object;
while ( ( object = enumerator.nextObject)) NSLog( @"%@", object);
2016-07-11 05:17:03.098 libtest[23759:5708985] String 00
2016-07-11 05:17:03.099 libtest[23759:5708985] String 01
2016-07-11 05:17:03.099 libtest[23759:5708985] String 02
- Property reverseObjectEnumerator returns an enumerator object that lets you access each object in the collection, in reverse order:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSEnumerator *enumerator = [array reverseObjectEnumerator];
id object;
while ( ( object = enumerator.nextObject)) NSLog( @"%@", object);
2016-07-11 05:36:59.934 libtest[23872:5720807] String 02
2016-07-11 05:36:59.934 libtest[23872:5720807] String 01
2016-07-11 05:36:59.934 libtest[23872:5720807] String 00
- Methods enumerateWithDelegate: and enumerate calls for the each collection object (from first to last) the delegate object method processObject:collection:. The difference between these methods is that the method enumerateWithDelegate: calls the specified delegate object, and method enumerate calls the default collection delegate object (if the object is not defines, than the method does nothing).
@end
@implementation SCTestDelegate
- (void)processObject:(
id)object collection:(
SCCollection *)collection {
NSLog( @"Process item \"%@\"", object);
}
@end
SCTestDelegate *delegate = [[[SCTestDelegate alloc] init] autorelease];
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
2016-07-11 05:57:51.828 libtest[24125:5734820] Process item "String 00"
2016-07-11 05:57:51.828 libtest[24125:5734820] Process item "String 01"
2016-07-11 05:57:51.828 libtest[24125:5734820] Process item "String 02"
Also class SCCollection and its child classes since version 1.2.5 support an operator оператор for..in, which supports in Objective C sinve version 2.0:
for ( id object in array) NSLog( @"%@", object);
2017-09-10 19:42:23.832149+0300 libtest[3335:100619] 100
2017-09-10 19:42:23.832178+0300 libtest[3335:100619] 200
2017-09-10 19:42:23.832203+0300 libtest[3335:100619] 300
2017-09-10 19:42:23.832249+0300 libtest[3335:100619] 400
Converting collections
Class SCCollection declares the following properties for converting collection instance from one collection type into the other collection type with objects retaining if converting type is allowed:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, assign) NSArray *foundationArray;
@property (nonatomic, readonly, assign) NSSet *foundationSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, assign) NSDictionary *foundationDictionary;
Adding objects
Class SCCollection declares the following methods for adding objects into the collection instance:
- Method addObject: adds into the receiving collection the specified object:
[array addObject:@"String 00"];
NSLog( @"%@", array);
[array addObject:@"New string"];
NSLog( @"%@", array);
2016-07-12 09:07:15.947 libtest[26117:6591434] Array count=1: (
"String 00"
)
2016-07-12 09:07:15.947 libtest[26117:6591434] Array count=2: (
"String 00",
"New string"
)
- Method addObjects: adds into the collection the specified objects:
[array addObject:@"String 00"];
NSLog( @"%@", array);
[array
addObjects:@"New string", @"Test string", nil];
NSLog( @"%@", array);
2016-07-12 09:11:44.393 libtest[26183:6593841] Array count=1: (
"String 00"
)
2016-07-12 09:11:44.393 libtest[26183:6593841] Array count=3: (
"String 00",
"New string",
"Test string"
)
- Method addCollection: adds into the receiving collection the objects from the specified existing collection:
[array addObject:@"String 00"];
[source addObject:@"String 10"];
[source addObject:@"String 11"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-12 09:22:11.744 libtest[26243:6597746] Array count=1: (
"String 00"
)
2016-07-12 09:22:11.744 libtest[26243:6597746] Array count=3: (
"String 00",
"String 10",
"String 11"
)
If any of object adding methods calls for the read only collection, then the error SCL-20043 is generated.
Removing objects
Class SCCollection declares the following methods for removing objects from the collection instance:
- (void)removeAllObjects;
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
- Method removeAllObjects removes all objects from the receiver's collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%@", array);
[array removeAllObjects];
NSLog( @"%@", array);
2016-07-12 10:01:29.533 libtest[26411:6622066] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-12 10:01:29.533 libtest[26411:6622066] Array count=0:
)
- Method removeObjectsWithClass: removes from the receiver's collection all objects of the specified class:
[array addObject:@"String 00"];
[array addInteger:1909];
[array addInteger:1975];
[array addObject:@"String 01"];
NSLog( @"%@", array);
[array removeObjectsWithClass:[NSNumber class]];
NSLog( @"%@", array);
2016-07-12 10:04:35.671 libtest[26447:6624285] Array count=4: (
"String 00",
"1909",
"1975",
"String 01"
)
2016-07-12 10:04:35.671 libtest[26447:6624285] Array count=2: (
"String 00",
"String 01"
)
- Method removeObjectsWithClassName: works as a previous method, but without removing objects class receipts as an argument the removing class name:
[array addObject:@"String 00"];
[array addInteger:1909];
[array addInteger:1975];
[array addObject:@"String 01"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-12 10:06:14.012 libtest[26474:6625250] Array count=4: (
"String 00",
"1909",
"1975",
"String 01"
)
2016-07-12 10:06:14.012 libtest[26474:6625250] Array count=2: (
"1909",
"1975"
)
- Method removeCollection: removes from the receiving collection objects, which are parts of the specified collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-12 10:09:16.356 libtest[26516:6627087] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-12 10:09:16.357 libtest[26516:6627087] Array count=1: (
"String 00"
)
- Method removeObject: removes all occurrences in the collection of a given object:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%@", array);
[array removeObject:@"String 01"];
[array removeObject:@"String 11"];
NSLog( @"%@", array);
2016-07-12 10:10:45.943 libtest[26541:6628329] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-12 10:10:45.943 libtest[26541:6628329] Array count=2: (
"String 00",
"String 02"
)
- Method removeObjects: removes all occurrences in the collection of the objects from the specified nil terminated list:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%@", array);
[array
removeObjects:@"String 01", @"String 00", @"String 11", nil];
NSLog( @"%@", array);
2016-07-12 10:12:11.710 libtest[26565:6629231] Array count=3: (
"String 00",
"String 01",
"String 02"
)
2016-07-12 10:12:11.710 libtest[26565:6629231] Array count=1: (
"String 02"
)
If any of object removing methods calls for the read-only collection, then then the error SCL-20043 is generated.
Search collection items
Serach methods detects the presense in the collection the required objects. Class SCCollection declares the following search methods:
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
- Method containsObject: returns a Boolean value that indicates whether a equivalent of the given object is present in the receiver's collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%d", [array containsObject:@"String 01"]);
NSLog( @"%d", [array containsObject:@"String 11"]);
2016-07-11 02:06:28.303 libtest[22651:5200484] 1
2016-07-11 02:06:28.303 libtest[22651:5200484] 0
- Method containsObjects: returns a Boolean value that indicates whether the receiver's collection contains the all objects from the specified nil terminated list:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%d", [array containsObjects:@"String 00", @"String 02"]);
NSLog( @"%d", [array containsObjects:@"String 00", @"String 12"]);
NSLog( @"%d", [array containsObjects:@"String 10", @"String 12"]);
2016-07-11 03:29:18.947 libtest[22819:5227995] 1
2016-07-11 03:29:18.947 libtest[22819:5227995] 0
2016-07-11 03:29:18.947 libtest[22819:5227995] 0
- Method containsCollection: returns a Boolean value that indicates whether the receiver's collection contains the all objects from the specified collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog(
@"%d", [array containsCollection:[
SCArray arrayWithObjects:
@"String 00",
@"String 02", nil]]);
NSLog(
@"%d", [array containsCollection:[
SCArray arrayWithObjects:
@"String 00",
@"String 12", nil]]);
NSLog(
@"%d", [array containsCollection:[
SCArray arrayWithObjects:
@"String 10",
@"String 12", nil]]);
2016-07-11 03:48:33.555 libtest[23105:5394701] 1
2016-07-11 03:48:33.556 libtest[23105:5394701] 0
2016-07-11 03:48:33.556 libtest[23105:5394701] 0
- Method containsAnyObject: returns a Boolean value that indicates whether the receiver's collection contains at least one object from the specified nil terminated list:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog( @"%d", [array containsAnyObject:@"String 00", @"String 02", nil]);
NSLog( @"%d", [array containsAnyObject:@"String 00", @"String 12", nil]);
NSLog( @"%d", [array containsAnyObject:@"String 10", @"String 12", nil]);
2016-07-11 04:18:22.893 libtest[23264:5650221] 1
2016-07-11 04:18:22.893 libtest[23264:5650221] 1
2016-07-11 04:18:22.893 libtest[23264:5650221] 0
- Method containsAnyObjectFromCollection: returns a Boolean value that indicates whether the receiver's collection contains at least one object from the specified collection:
[array addObject:@"String 00"];
[array addObject:@"String 01"];
[array addObject:@"String 02"];
NSLog(
@"%d", [array containsAnyObjectFromCollection:[
SCArray arrayWithObjects:
@"String 00",
@"String 02", nil]]);
NSLog(
@"%d", [array containsAnyObjectFromCollection:[
SCArray arrayWithObjects:
@"String 00",
@"String 12", nil]]);
NSLog(
@"%d", [array containsAnyObjectFromCollection:[
SCArray arrayWithObjects:
@"String 10",
@"String 12", nil]]);
2016-07-11 04:25:44.907 libtest[23333:5677089] 1
2016-07-11 04:25:44.907 libtest[23333:5677089] 1
2016-07-11 04:25:44.907 libtest[23333:5677089] 0
Collection type detection
Class SCCollection declares the following properties for collection type determination:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
- Property collectionType returns a constant, that indicates a type of the collection.
- Property isCollection returns value YES if the class instance is a collection of any supported type.
- Property isLibraryCollection returns value YES if the class instance is a library collection (classes SCArray, SCSet, SCOrderedSet, SCDictionary, SCStack, SCQueues, SCUnidirectionalLists and SCBidirectionalList).
- Property isFoundationCollection returns value YES if the class instance is a standard Objective-C collection (classes NSArray, NSMutableArray, NSSet, NSMutableSet, NSOrderedSet, NSMutableOrderedSet, NSDictionary and NSMutableDictionary).
- Property isSet returns the value YES if the receiving instance is an unordered set of any supported type (classes SCSet, NSSet and NSMutableSet).
- Property isLibrarySet returns the value YES if the class instance is a library unordered set (class SCSet).
- Property isFoundationSet returns YES value if the receiving instance is a standard unordered set (classes NSSet and NSMutableSet).
Also class SCCollection declares the following class methods for collection type determination of the specified class instances:
+ (BOOL)isCollection:(id)object;
+ (BOOL)isLibraryCollection:(id)object;
+ (BOOL)isFoundationCollection:(id)object;
+ (BOOL)isArray:(id)object;
+ (BOOL)isLibraryArray:(id)object;
+ (BOOL)isFoundationArray:(id)object;
+ (BOOL)isSet:(id)object;
+ (BOOL)isLibrarySet:(id)object;
+ (BOOL)isFoundationSet:(id)object;
+ (BOOL)isOrderedSet:(id)object;
+ (BOOL)isLibraryOrderedSet:(id)object;
+ (BOOL)isFoundationOrderedSet:(id)object;
+ (BOOL)isDictionary:(id)object;
+ (BOOL)isLibraryDictionary:(id)object;
+ (BOOL)isFoundationDictionary:(id)object;
+ (BOOL)isStack:(id)object;
+ (BOOL)isQueue:(id)object;
+ (BOOL)isList:(id)object;
+ (BOOL)isSortable:(id)object;
Additionally, class SCCollection declares the class methods for determination collection type of the class by using the specified class name:
+ (BOOL)isCollectionClass:(NSString *)name;
+ (BOOL)isLibraryCollectionClass:(NSString *)name;
+ (BOOL)isFoundationCollectionClass:(NSString *)name;
+ (BOOL)isArrayClass:(NSString *)name;
+ (BOOL)isLibraryArrayClass:(NSString *)name;
+ (BOOL)isFoundationArrayClass:(NSString *)name;
+ (BOOL)isSetClass:(NSString *)name;
+ (BOOL)isLibrarySetClass:(NSString *)name;
+ (BOOL)isFoundationSetClass:(NSString *)name;
+ (BOOL)isOrderedSetClass:(NSString *)name;
+ (BOOL)isLibraryOrderedSetClass:(NSString *)name;
+ (BOOL)isFoundationOrderedSetClass:(NSString *)name;
+ (BOOL)isDictionaryClass:(NSString *)name;
+ (BOOL)isLibraryDictionaryClass:(NSString *)name;
+ (BOOL)isFoundationDictionaryClass:(NSString *)name;
+ (BOOL)isStackClass:(NSString *)name;
+ (BOOL)isQueueClass:(NSString *)name;
+ (BOOL)isListClass:(NSString *)name;
+ (BOOL)isSortableClass:(NSString *)name;
Arrays
Arrays is a collection of objects, each identified by the index. Therefore, an array is a collection with the random access to the objects. Also, array is a kind of sorted collection.
Class SCArray implements the arrays in the library. Class instances supports both read and update contained objects.
Creating arrays
Class SCArray implements the following methods for creating arrays using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)arrayWithCoder:(NSCoder *)coder;
+ (instancetype)arrayWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)arrayWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)arrayWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)arrayWithStream:(
SCStream *)stream;
+ (instancetype)arrayWithFileStream:(NSString *)path;
+ (instancetype)arrayWithData:(NSData *)data;
+ (instancetype)arrayWithContentsOfFile:(NSString *)path;
+ (instancetype)arrayWithContentsOfURL:(NSURL *)url;
+ (instancetype)arrayWithContentsOfURLString:(NSString *)urlString;
Class SCArrays declares the following methods for creating arrays:
+ (instancetype)arrayWithName:(NSString *)name;
+ (instancetype)arrayWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)arrayWithArray:(
SCArray *)array;
+ (instancetype)array;
- Class method arrayWithName: returns the empty array created by using the specified array name:
NSLog( @"%@", array);
NSLog(
@"Array name: %@", array.
name);
2016-07-21 13:13:14.395 libtest[4044:837368] Array "UsersList" count=0:
)
2016-07-21 13:13:14.395 libtest[4044:837368] Array name: UsersList
- Class method arrayWithObject: returns the array created by using the specified existing object:
2016-07-21 13:16:42.819 libtest[4100:840315] Array count=1: (
"Sample string"
)
- Class method arrayWithObjects: returns the array created by using the specified nil terminated list of existing objects:
2016-07-21 13:26:10.353 libtest[4168:845565] Array count=3: (
"String 00",
"String 01",
"String 02"
)
- Class method arrayWithCollection: returns the array created by using the specified existing collection:
NSSet *source = [NSSet setWithObjects:@"Code 10", @"Code 20", @"Code 30", nil];
NSLog( @"%@", array);
2016-07-21 13:27:56.528 libtest[4195:846841] Array count=3: (
"Code 10",
"Code 20",
"Code 30"
)
- Class method arrayWithArray: returns the array created by using the existing array:
2016-07-21 13:32:11.010 libtest[4232:850227] Array count=3: (
"Object 00",
"Object 10",
"Object 20"
)
- Class method array returns the created empty unnamed array:
2016-07-21 13:35:23.386 libtest[4280:853760] Array count=0:
)
Initializing arrays
Class SCArray implements the following class instances initialization methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)init;
- Method initWithName: initializes the empty array using the specified name (see the property name).
- Method initWithObject: initializes the unnamed array using the specified existing object.
- Method initWithObjects: initializes the array using the specified nil terminated list of existing objects.
- Method initWithCollection: initializes the array using the specified existing collection.
- Method initWithArray: initializes the array using the existing array.
- Method init initializes the empty array using the default settings.
Coping arrays
Class SCArray declares the following array coping methods:
- Method setArray: removes the array current content and copy settings and objects from the specified existing source array. If this method calls for the read-only collection, than error SCL-20043 occurs.
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-21 14:58:21.653 libtest[4698:910061] Array count=3: (
"String 00",
"String 10",
"String 20"
)
2016-07-21 14:58:21.653 libtest[4698:910061] Array count=3: (
"Object 00",
"Object 01",
"Object 02"
)
Comparing arrays
Class SCArray extends the parent class SCCollection by implements the following additional methods for comparing class instances:
- (BOOL)isEqualToArray:(
SCArray *)array;
- Method isEqualToArray: returns a boolean value that indicates whether the contents of the receiving array is equala to the contents of another given array.
[array addObject:@"Line 00"];
[array addObject:@"Line 01"];
[array addObject:@"Line 02"];
[source addObject:@"Line 00"];
[source addObject:@"Line 01"];
[source addObject:@"Line 02"];
[sample addObject:@"Line 00"];
[sample addObject:@"Line 10"];
[sample addObject:@"Line 20"];
NSLog( @"[array isEqualToArray:source] = %d", [array isEqualToArray:source]);
NSLog( @"[array isEqualToArray:sample] = %d", [array isEqualToArray:sample]);
2016-07-25 01:36:51.081 libtest[11081:1745880] [array isEqualToArray:source] = 1
2016-07-25 01:36:51.081 libtest[11081:1745880] [array isEqualToArray:sample] = 0
Deriving new arrays
You can use the following methods of the class SCArray for deriving new array by using the existing content of the receiving arrays:
- (
SCArray *)subarrayWithRange:(NSRange)range;
- Methods arrayByAddingObject: creates and returns an array that contains objects from the receiving arrays and a given object which added to the end of a new array:
NSLog( @"%@", [array arrayByAddingObject:@"Message"]);
2017-06-08 10:30:10.725367+0300 libtest[84981:5871189] Array count=4: (
200,
800,
400,
Message
)
- Method arrayByAddingObjects: returns an array that contains objects from the receiving array and objects from a given list:
NSLog( @"%@", [array arrayByAddingObjects:@"String", @"Message", nil]);
2017-06-08 10:59:00.233581+0300 libtest[85501:5891803] Array count=5: (
200,
800,
400,
String,
Message
)
- Method arrayByAddingCollection: returns an array that contains objects from the receiving array and objects from a given collection of any supported type:
NSLog( @"%@", [array arrayByAddingCollection:@[ @"One", @"Two"]]);
2017-06-08 11:13:31.334683+0300 libtest[85959:5902947] Array count=5: (
200,
800,
400,
One,
Two
)
- Methods arrayByAddingObjectsFromArray: and arrayByAddingArray: combines objects from the receiving and a given arrays:
NSLog( @"%@", [array arrayByAddingObjectsFromArray:source]);
2017-06-08 11:31:29.517764+0300 libtest[86389:5915516] Array count=5: (
200,
800,
400,
MacOS,
FreeBSD
)
- Method subarrayWithRange: returns a new array that contains objects within a given range from the receiving array:
NSLog( @"%@", [array subarrayWithRange:NSMakeRange( 1, 2)]);
2017-06-08 11:44:12.780674+0300 libtest[86726:5925128] Array count=2: (
800,
400
)
Sorting arrays
Arrays, like any indexed collection, can provide various modes of objects sorting. Class SCArray implements the number of methods that allow performs sorting operations. For performs the sorting operations class SCArray uses the sorters, which are instances of classes, that comforms to the protocol SCSorter. You can direct set the sorter class instance or use the default array sorter. See details in the Programming Guide section Sorters.
During the sorting operation sorter comparing array object by using the protocol SCCollectioning method compareWithObject:.
Class SCArray declares the following properties methods of sorting its contents:
- (void)sortAscendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortDescendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortWithSorter:(
id<
SCSorter>)sorter;
- (void)sortAscending;
- (void)sortDescending;
- (void)sort;
@property (nonatomic, readonly, assign)
SCArray *ascendingSortedArray;
@property (nonatomic, readonly, assign)
SCArray *descendingSortedArray;
@property (nonatomic, readonly, assign)
SCArray *sortedArray;
- Method sortAscendingWithSorter: sorts ascending the receiving array using the specified sorter instance.
- Method sortDescendingWithSorter: sorts descending the receiving array using the specified sorter instance.
- Method sortWithSorter: sorts ascending the receiving the receiving array using the specified sorter instance. This method is analog of sortAscendingWithSorter:.
- Method sortAscending sorts ascending the receiving array using the default sorter instance.
- Method sortDescending sorts descending the receiving array using the default sorter instance.
- Method sort sorts ascending the receiving array using the default sorter instance. This method is analog of sortAscending.
[array addObject:@"String 04"];
[array addObject:@"String 01"];
[array addObject:@"String 00"];
[array addObject:@"String 02"];
[array addObject:@"String 03"];
NSLog( @"================ SOURCE ARRAY =================");
NSLog( @"%@", array);
NSLog( @"=========== ASCENDING SORTED ARRAY ============");
NSLog( @"%@", array);
NSLog( @"=========== DESCENDING SORTED ARRAY ===========");
NSLog( @"%@", array);
2016-07-22 10:25:14.707 libtest[7423:1366810] ================ SOURCE ARRAY =================
2016-07-22 10:25:14.707 libtest[7423:1366810] Array count=5: (
"String 04",
"String 01",
"String 00",
"String 02",
"String 03"
)
2016-07-22 10:25:14.708 libtest[7423:1366810] =========== ASCENDING SORTED ARRAY ============
2016-07-22 10:25:14.708 libtest[7423:1366810] Array count=5: (
"String 00",
"String 01",
"String 02",
"String 03",
"String 04"
)
2016-07-22 10:25:14.708 libtest[7423:1366810] =========== DESCENDING SORTED ARRAY ===========
2016-07-22 10:25:14.708 libtest[7423:1366810] Array count=5: (
"String 04",
"String 03",
"String 02",
"String 01",
"String 00"
)
Also the class SCArray declares the class methods for creating arrays using the sorted contents of the existing collection of any supported type:
+ (instancetype)arrayWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)arrayWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)arrayWithAscendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)arrayWithDescendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)arrayWithSortedCollection:(
id<
SCCollection>)collection;
Additionally class SCArray implements the methods for initializing the arrays using the sorted contents of the existing collections of any supported type:
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithSortedCollection:(
id<
SCCollection>)collection;
In addition to copying methods class SCArray provides the following methods of copying sorted contents of the existing collections of any supported type:
- (void)setAscendingSortedCollection:(
id<
SCCollection>)collection;
- (void)setDescendingSortedCollection:(
id<
SCCollection>)collection;
Adding objects to array
Class SCArray extends the parent class SCCollection with the following methods for adding methods into the array:
- (void)insertAtIndexes:(NSIndexSet *)indexes objects:(
id<
SCCollectioning>)object, ...;
- (void)insertCollection:(
id<
SCCollection>)collection atIndexes:(NSIndexSet *)indexes;
- (void)addObjectsFromArray:(
SCArray *)array;
- Method insertObject:atIndex: inserts a given object into the array's contents at a given index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 11:31:05.699 libtest[7812:1401032] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 11:31:05.699 libtest[7812:1401032] Array count=5: (
"Object 00",
"Object 01",
"=========",
"Object 02",
"Object 03"
)
- Method insertAtIndex:objects: inserts the objects from a given nil terminated list into the array's contents at a given index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 11:36:38.795 libtest[7861:1403442] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 11:36:38.795 libtest[7861:1403442] Array count=7: (
"Object 00",
"Object 01",
"=========",
"Object AA",
"=========",
"Object 02",
"Object 03"
)
- Method insertCollection:atIndex: inserts the objects from a given collection of any supported type into the receiving array at a given index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 11:39:16.854 libtest[7896:1404848] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 11:39:16.854 libtest[7896:1404848] Array count=7: (
"Object 00",
"Object 01",
"=========",
"Object XX",
"=========",
"Object 02",
"Object 03"
)
- Method insertAtIndexes:objects: inserts the objects from a given nil terminated list into the receiving array at the specified indexes:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", array);
2016-07-22 11:48:35.908 libtest[7992:1411049] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 11:48:35.908 libtest[7992:1411049] Array count=6: (
"Object 00",
"=========",
"=========",
"Object 01",
"Object 02",
"Object 03"
)
- Method insertCollection:atIndexes: inserts the objects from a given collection of any supported type into the receiving array at the specified indexes:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", array);
2016-07-22 11:56:41.190 libtest[8065:1416993] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 11:56:41.190 libtest[8065:1416993] Array count=6: (
"Object 00",
"---------",
"---------",
"Object 01",
"Object 02",
"Object 03"
)
- Method setObject:atIndex: replaces the object with the specified index to a given object or adds this object into the array if the specified index is incorrect:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 12:00:44.853 libtest[8098:1419094] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:00:44.853 libtest[8098:1419094] Array count=5: (
"Object 00",
"=========",
"Object 02",
"Object 03",
"---------"
)
- Methods addObjectsFromArray: and addArray: add into the receiving array objects from a given array:
2017-06-08 11:53:18.411601+0300 libtest[87049:5931757] Array count=5: (
200,
800,
400,
Windows,
Solaris
)
Removing objects from array
In addition to the parent class SCCollection objects removing methods class SCArray implements the own removing methods:
- (void)removeFirstObject;
- (void)removeLastObject;
- (void)removeObjectAtIndex:(
SCIndex)index;
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
- (void)removeObjectsInRange:(NSRange)range;
- Method removeFirstObject removes from array the first object:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 12:50:33.098 libtest[8506:1455405] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:50:33.098 libtest[8506:1455405] Array count=3: (
"Object 01",
"Object 02",
"Object 03"
)
- Method removeLastObject removes from array the last object:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 12:51:32.881 libtest[8525:1455783] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:51:32.881 libtest[8525:1455783] Array count=3: (
"Object 00",
"Object 01",
"Object 02"
)
- Method removeObjectAtIndex: removes from array the object at the specified index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 12:52:34.254 libtest[8548:1456319] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:52:34.254 libtest[8548:1456319] Array count=3: (
"Object 00",
"Object 02",
"Object 03"
)
- Method removeObjectsAtIndexes: removes from array the objects at the indexes from the specified index set:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:3];
NSLog( @"%@", array);
2016-07-22 12:54:11.132 libtest[8582:1456999] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:54:11.132 libtest[8582:1456999] Array count=2: (
"Object 00",
"Object 02"
)
- Method removeObjectsInRange: removes from the array objects in the specified range:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 1, 2);
NSLog( @"%@", array);
2016-07-22 12:56:47.358 libtest[8610:1459386] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 12:56:47.358 libtest[8610:1459386] Array count=2: (
"Object 00",
"Object 03"
)
Replacing array objects
Class SCArrays declares the following methods for object replacing:
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(
id<
SCCollectioning>)object, ...;
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withCollection:(
id<
SCCollection>)collection;
- (void)replaceObjectsInRange:(NSRange)range withObjects:(
id<
SCCollectioning>)object, ...;
- (void)replaceObjectsInRange:(NSRange)range withCollection:(
id<
SCCollection>)collection;
- Method replaceObjectAtIndex:withObject: replaces the object at the specified index with a given object. Unlike of setObject:atIndex: this method occurs the error SCL-20052 if the specified index is incorrect.
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 13:41:38.478 libtest[8877:1486667] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 13:41:38.478 libtest[8877:1486667] Array count=4: (
"Object 00",
"=========",
"Object 02",
"Object 03"
)
- Method replaceObjectsAtIndexes:withObjects: replaces the objects in the receiving array at specified locations with the objects from a given nil terminated list. Number of indexes must be equal to number of objects.
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:3];
NSLog( @"%@", array);
2016-07-22 13:45:06.495 libtest[8933:1488667] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 13:45:06.495 libtest[8933:1488667] Array count=4: (
"=========",
"Object 01",
"Object 02",
"========="
)
- Method replaceObjectsAtIndexes:withCollection: replaces the objects in the receiving array at specified locations with the objects from a given collection of any supported type. Number of indexes must be equal to number of objects in collection.
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", array);
2016-07-22 13:46:53.474 libtest[8959:1489294] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 13:46:53.475 libtest[8959:1489294] Array count=4: (
"Object 00",
"=========",
"=========",
"Object 03"
)
- Method replaceObjectsInRange:withObjects: replaces the objects in the receiving array specified by a given range with all of the objects from a specified nil terminated list:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 2, 2);
NSLog( @"%@", array);
2016-07-22 13:52:29.635 libtest[9011:1493525] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 13:52:29.635 libtest[9011:1493525] Array count=4: (
"Object 00",
"Object 01",
"=========",
"========="
)
- Method replaceObjectsInRange:withCollection: replaces the objects in the receiving array specified by a given range with all of the objects from a specified collection of any supported type:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 0, 2);
NSArray *source = [NSArray arrayWithObjects:@"=========", @"=========", nil];
NSLog( @"%@", array);
2016-07-22 14:01:32.564 libtest[9039:1496565] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 14:01:32.564 libtest[9039:1496565] Array count=4: (
"=========",
"=========",
"Object 02",
"Object 03"
)
- Method setObject:atIndexedSubscript: provides the support of the replacing array object by using an operator [] and a given index of object:
NSLog( @"%@", array);
array[2] = @"Message";
NSLog( @"%@", array);
2017-09-10 23:39:27.582410+0300 libtest[6976:198790] Array count=4: (
100,
200,
300,
400
)
2017-09-10 23:39:27.582664+0300 libtest[6976:198790] Array count=4: (
100,
200,
Message,
400
)
Coping and moving array objects
Class SCArray implements some methods for coping and moving objects in the array.
Method exchangeObjectAtIndex:withObjectAtIndex: exchanges the objects in the array at given indices:
- (void)exchangeObjectAtIndex:(
SCIndex)index withObjectAtIndex:(
SCIndex)destination;
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 15:38:02.392 libtest[9467:1548785] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 15:38:02.392 libtest[9467:1548785] Array count=4: (
"Object 03",
"Object 01",
"Object 02",
"Object 00"
)
Class SCArray implements the following methods for duplicating objects within the array:
- (void)duplicateObjectAtIndex:(
SCIndex)index;
- (void)duplicateObjectsInRange:(NSRange)range;
- (void)duplicateAllObjects;
- (void)duplicate;
This methods required from the objects the compliance to the protocol SCCollection and implementation of the method copyObject.
- Method duplicateObjectAtIndex: duplicates the object at the specified index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 15:45:44.172 libtest[9529:1554390] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 15:45:44.173 libtest[9529:1554390] Array count=5: (
"Object 00",
"Object 01",
"Object 02",
"Object 02",
"Object 03"
)
- Method duplicateObjectsInRange: duplicate the objects within the specified range:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 1, 2);
NSLog( @"%@", array);
2016-07-22 15:49:58.931 libtest[9559:1557433] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 15:49:58.931 libtest[9559:1557433] Array count=6: (
"Object 00",
"Object 01",
"Object 02",
"Object 01",
"Object 02",
"Object 03"
)
- Method duplicateAllObjects duplicates each object within receiving array:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 16:00:43.341 libtest[9602:1564387] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 16:00:43.341 libtest[9602:1564387] Array count=8: (
"Object 00",
"Object 00",
"Object 01",
"Object 01",
"Object 02",
"Object 02",
"Object 03",
"Object 03"
)
- Method duplicate duplicates content of the receving array:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 16:10:47.411 libtest[9630:1567479] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 16:10:47.411 libtest[9630:1567479] Array count=8: (
"Object 00",
"Object 01",
"Object 02",
"Object 03",
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
Class SCArray declares the following methods for copying objects within array (required support of the method copyObject for array objects):
- (void)copyObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)copyObjectsInRange:(NSRange)range toIndex:(
SCIndex)destination;
- Method copyObjectAtIndex:toIndex: copies the object at the specified index to a given destination index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 16:40:05.530 libtest[9913:1592911] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 16:40:05.530 libtest[9913:1592911] Array count=5: (
"Object 00",
"Object 01",
"Object 00",
"Object 02",
"Object 03"
)
- Method copyObjectsInRange:toIndex: copies the objects within the specified range to a given destination index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 0, 2);
NSLog( @"%@", array);
2016-07-22 16:43:22.648 libtest[9944:1594899] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 16:43:22.648 libtest[9944:1594899] Array count=6: (
"Object 00",
"Object 01",
"Object 02",
"Object 00",
"Object 01",
"Object 03"
)
Class SCArray implements the following methods for moving objects within array:
- (void)moveObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)moveObjectsInRange:(NSRange)range toIndex:(
SCIndex)destination;
- Method moveObjectAtIndex:toIndex: moves the object at the specified index to a given destination index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 17:12:58.760 libtest[10026:1616064] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 17:12:58.760 libtest[10026:1616064] Array count=4: (
"Object 01",
"Object 02",
"Object 00",
"Object 03"
)
- Method moveObjectsInRange:toIndex: moves the objects within the specified range to a given destination index:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSRange range = NSMakeRange( 0, 2);
NSLog( @"%@", array);
2016-07-22 17:15:52.892 libtest[10074:1617968] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 17:15:52.892 libtest[10074:1617968] Array count=4: (
"Object 02",
"Object 03",
"Object 00",
"Object 01"
)
Additional class SCArray declares the methods for reversing array contents:
[array addObject:@"Object 00"];
[array addObject:@"Object 01"];
[array addObject:@"Object 02"];
[array addObject:@"Object 03"];
NSLog( @"%@", array);
NSLog( @"%@", array);
2016-07-22 17:22:13.296 libtest[10119:1622519] Array count=4: (
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)
2016-07-22 17:22:13.296 libtest[10119:1622519] Array count=4: (
"Object 03",
"Object 02",
"Object 01",
"Object 00"
)
Array objects access
Class SCArray declares the following properties and methods for the access to the array objects:
@property (nonatomic, readonly, assign) id firstObject;
@property (nonatomic, readonly, assign) id lastObject;
- (id)objectAtIndex:(
SCIndex)index;
- (
SCArray *)objectsAtIndexes:(NSIndexSet *)indexes;
- (
SCArray *)objectsInRange:(NSRange)range;
- (id)objectAtIndexedSubscript:(
SCIndex)index;
- Property firstObject returns the first object from the receiving array:
2016-07-21 15:58:45.314 libtest[4990:942093] Array first object: Object 00
- Property lastObject returns the last object of the receiving array:
NSLog(
@"Array last object: %@", array.
lastObject);
2016-07-21 16:01:57.614 libtest[5031:943478] Array last object: Object 02
- Method objectAtIndex: returns the object located at the specified index. If the required index does not exists in the array, than error SCL-20052 occurs.
NSLog( @"%@", [array objectAtIndex:1]);
2016-07-21 16:11:27.241 libtest[5072:948192] Object 01
- Method objectsAtIndexes: returns an array containing the objects in the array at the indexes specified by a given index set. Method ignores the incorrect indexes from the set.
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:2];
NSLog( @"%@", [array objectsAtIndexes:indexSet]);
indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:3];
NSLog( @"%@", [array objectsAtIndexes:indexSet]);
2016-07-21 16:17:37.845 libtest[5167:953186] Array count=2: (
"Object 00",
"Object 02"
)
2016-07-21 16:17:37.851 libtest[5167:953186] Array count=1: (
"Object 01"
)
- Method objectsInRange: returns an array containing the objects in the array in the specified range. If method receives the incorrect range, error SCL-20053 occurs.
NSLog( @"%@", [array objectsInRange:NSMakeRange( 1, 2)]);
2016-07-21 16:25:34.720 libtest[5226:960949] Array count=2: (
"Object 01",
"Object 02"
)
- Method objectAtIndexedSubscript: returns an object at a given index and provides access to array objects by using an operator []:
2017-09-11 00:14:50.703531+0300 libtest[7177:211851] 200
Search array objects
For finding objects in the arrays class SCArray implements the following methods and properties:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastObject;
- Method indexOfObject: returns the lowest index whose corresponding array value is equal to a given object. If required object not found, method returns the value NSNotFound.
NSLog( @"Object 01 index: %d", [array indexOfObject:@"Object 01"]);
NSLog( @"Object 11 index: %d", [array indexOfObject:@"Object 11"]);
2016-07-21 17:02:24.153 libtest[5488:986364] Object 01 index: 1
2016-07-21 17:02:24.153 libtest[5488:986364] Object 11 index: -1
- Method inRange: returns the lowest index from the specified range whose corresponding array value is equal to a given object. If the method detects the incorrect range, error SCL-20053 is occuring.
NSRange range = NSMakeRange( 4, 3);
NSLog( @"Index of 04: %d", [array indexOfObject:@"04" inRange:range]);
NSLog( @"Index of 07: %d", [array indexOfObject:@"07" inRange:range]);
2016-07-21 17:05:35.402 libtest[5523:988128] Index of 04: 4
2016-07-21 17:05:35.402 libtest[5523:988128] Index of 07: -1
- Property indexOfLastObject returns the index of the last object within the receiving array or NSNotFound if array is empty:
2016-07-21 17:09:03.368 libtest[5552:990330] Index of last object: 4
Sets
Set (unordered set) is a type of collection, which can store certain objects, without any particular order, and no repeated values. Sets does not support direct access to objects.
For supporting sets the library implements the class SCSet:
Creating sets
For creating class instances using the data from the serialized files, data dictionaries, streams and data objects class SCSet implements the following class methods:
+ (instancetype)setWithCoder:(NSCoder *)coder;
+ (instancetype)setWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)setWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)setWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)setWithStream:(
SCStream *)stream;
+ (instancetype)setWithFileStream:(NSString *)path;
+ (instancetype)setWithData:(NSData *)data;
+ (instancetype)setWithContentsOfFile:(NSString *)path;
+ (instancetype)setWithContentsOfURL:(NSURL *)url;
+ (instancetype)setWithContentsOfURLString:(NSString *)urlString;
Class SCSet declares the following the class methods for creating the class instances:
+ (instancetype)setWithName:(NSString *)name;
+ (instancetype)setWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)setWithSet:(
SCSet *)set;
+ (instancetype)setWithArray:(
SCArray *)array;
+ (instancetype)set;
- Method setWithName: returns the empty set created by using the specified set name:
2016-07-25 10:21:17.443 libtest[12358:1926852] Set "SampleSet" count=0: {
)}
- Method setWithObject: returns the set created by using the specified existing object:
2016-07-25 10:22:26.707 libtest[12382:1927619] Set count=1: {(
"String"
)}
- Method setWithObjects: returns the set created by using the specified nil terminated list of existing objects:
2016-07-25 10:23:54.179 libtest[12409:1928270] Set count=3: {(
"Data",
"String",
"Object"
)}
- Method setWithCollection: returns the set created by using the specified existing collection:
2016-07-25 10:26:26.474 libtest[12450:1929854] Set count=3: {(
"Source",
"Information",
"String"
)}
- Method setWithSet: returns the set created by using the existing set:
2016-07-25 14:54:03.819 libtest[12824:2053546] Set count=3: {(
"Source",
"Information",
"String"
)}
- Method setWithArray: creates a set using the settings and contents of a given array:
2017-06-08 13:57:24.499518+0300 libtest[89922:6020417] Set count=3: {(
800,
400,
200
)}
- Method set returns the empty unnamed set with the default settings:
2016-07-25 15:02:32.395 libtest[12853:2059488] Set count=0: {
)}
Initializing sets
Class SCSet implements the following initializing methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithSet:(
SCSet *)set;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)init;
- Method initWithName: initializes the emty set using the specified set name.
- Method initWithObject: initializes the set using the specified existing object.
- Method initWithObjects: initializes the set using the specified nil terminated list of existing objects.
- Method initWithCollection: initializes the set using the specified existing collection.
- Method initWithSet: initializes the set using the existing set.
- Method initWithArray: initializes a new set using the settings and contents of a given array
- Method init initializes the empty unnamed set using the default settings.
Coping sets
Class SCSet declares the following coping methods:
- (void)setSet:(
SCSet *)set;
- Method setSet: removes the receiving set settings and contents and copy into the receiving set settings and contents from the specified existing set:
NSLog( @"%@", set);
NSLog( @"%@", set);
2016-07-25 16:54:30.830 libtest[1242:50070] Set count=3: {(
"String",
"System",
"Information"
)}
2016-07-25 16:54:30.830 libtest[1242:50070] Set count=3: {(
"Line 00",
"Line 01",
"Line 02"
)}
- Method setArray: replaces the settings and contents of the receiving set with the settings and contents of the specified array.
Comparing sets
Class SCSet implements the following comparing methods:
- (BOOL)isEqualToSet:(
SCSet *)set;
- (BOOL)isEqualToArray:(
SCArray *)array;
- Method isSubsetOfSet: returns a boolean value that indicates whether every object in the receiving set is also present in a given collection of any supported type:
NSLog( @"%d", [set isSubsetOfSet:original]);
[set addObject:@"06"];
NSLog( @"%d", [set isSubsetOfSet:original]);
2016-07-25 17:33:56.069 libtest[1426:74723] 1
2016-07-25 17:33:56.069 libtest[1426:74723] 0
- Method intersectsSet: returns a boolean value that indicates whether at least one object in the receiving set is also present in a given collection of any supported type:
NSLog( @"%d", [set intersectsSet:original]);
[set removeObject:@"04"];
NSLog( @"%d", [set intersectsSet:original]);
2016-07-25 17:36:51.172 libtest[1452:76573] 1
2016-07-25 17:36:51.172 libtest[1452:76573] 0
- Method isEqualToSet: returns a boolean value that indicates whether the contents of the receiving set is equals to the contents of another given set.
- Method isEqualToArray: returns a boolean value that indicates whether the contents of the receiving set is equals to the contents of the specified array.
Deriving New Sets
Class SCSet implements the following methods for deriving a new sets using the existing sets:
- (
SCSet *)setByAddingObjectsFromSet:(
SCSet *)set;
- Method setByAddingObject: returns a new set formed by adding a given object to the receiving set:
NSLog( @"%@", [set setByAddingObject:@700]);
2017-06-08 15:33:48.586103+0300 libtest[90987:6085243] Set count=4: {(
700,
800,
400,
200
)}
- Method setByAddingObjects: creates a new set that contains objects from the receiving set and objects from a given list:
NSLog( @"%@", [set setByAddingObjects:@100, @500, nil]);
2017-06-08 16:01:27.019024+0300 libtest[91399:6104536] Set count=5: {(
500,
800,
100,
400,
200
)}
- Methods setByAddingObjectsFromArray: and setByAddingArray: create and return a new set that contains objects from the receiving set and objects from a given array
NSLog( @"%@", [set setByAddingObjectsFromArray:array]);
2017-06-08 16:26:54.969578+0300 libtest[91876:6121958] Set count=5: {(
Two,
800,
One,
400,
200
)}
- Methods setByAddingObjectsFromSet: and setByAddingSet: create a new set that contains objects from the receiving set and objects from a given another set:
NSLog( @"%@", [set setByAddingObjectsFromSet:source]);
2017-06-08 16:38:36.409967+0300 libtest[92278:6131120] Set count=5: {(
Solaris,
MacOS,
800,
400,
200
)}
- Method setByAddingCollection: returns a new set that contains objects from the receiving set and objects from a given collection of any supported type:
NSLog( @"%@", [set setByAddingCollection:@[ @100, @500]]);
2017-06-08 16:57:18.022427+0300 libtest[92633:6144235] Set count=5: {(
500,
800,
100,
400,
200
)}
Adding Objects
Except the methods inherited from the class SCCollection the class SCSet implements own methods of adding objects:
- (void)addObjectsFromArray:(
SCArray *)array;
- (void)addObjectsFromSet:(
SCSet *)set;
- (void)addSet:(
SCSet *)set;
- Methods addObjectsFromArray: and addArray: add into the receiving set the objects from a given array:
2017-06-08 17:06:25.080290+0300 libtest[92964:6151034] Set count=5: {(
Two,
800,
One,
400,
200
)}
- Methods addObjectsFromSet: and addSet: add into the receiving set the objects from a given another set:
2017-06-08 17:18:35.923215+0300 libtest[93305:6159978] Set count=5: {(
FreeBSD,
MacOS,
800,
400,
200
)}
Set objects access
For accessing the set objects class SCSet implements the following properties and methods:
@property (nonatomic, readonly, assign)
SCArray *allObjects;
@property (nonatomic, readonly, assign) id anyObject;
- Property allObjects returns an array containing the set's members:
2016-07-25 16:35:26.090 libtest[1098:38625] Array count=3: (
"String",
"System",
"Information"
)
- Property anyObject returns one of the objects in the set or nil if the set is empty:
2016-07-25 16:36:17.183 libtest[1130:39344] String
- Method member: determines whether the set contains a given object. If a given object is a member of the receiving set, then method returns the pointer to this object, otherwise method returns a nil pointer.
NSLog( @"%@", [set member:@600]);
NSLog( @"%@", [set member:@400]);
2017-06-08 15:01:54.003366+0300 libtest[90323:6062042] (null)
2017-06-08 15:01:54.003427+0300 libtest[90323:6062042] 400
Combining and recombining sets
Combining and recombining operations are supported by the following methods of the class SCSet:
- Method unionSet: adds each object from the specified collection of any supported type to the receiving set, if not present. This opeation also names the union sets.
NSLog( @"%@", set);
NSLog( @"%@", set);
2016-07-26 09:37:27.565 libtest[2761:411807] Set count=3: {(
"04",
"00",
"02"
)}
2016-07-26 09:37:27.565 libtest[2761:411807] Set count=5: {(
"01",
"04",
"00",
"03",
"02"
)}
- Method minusSet: removes each object in another given collection of any supported type from the receiving set, if present. This operation also names the minus sets.
NSLog( @"%@", set);
NSLog( @"%@", set);
2016-07-26 09:43:08.223 libtest[2794:414790] Set count=5: {(
"01",
"04",
"00",
"03",
"02"
)}
2016-07-26 09:43:08.223 libtest[2794:414790] Set count=3: {(
"04",
"00",
"02"
)}
- Method intersectSet: removes from the receiving set each object that isn't a member of the specified collection of the any supported type:
NSLog( @"%@", set);
NSLog( @"%@", set);
2016-07-26 09:46:20.929 libtest[2816:416605] Set count=5: {(
"01",
"04",
"00",
"03",
"02"
)}
2016-07-26 09:46:20.929 libtest[2816:416605] Set count=2: {(
"01",
"03"
)}
Ordered sets
Ordered sets on the basis of class SCOrderedSet represent a set of objects that differ from unordered sets SCSet both support a specific sequence elements (thus the name), and index access to the objects of the set.
Ordered sets are similar as the array (the order of items, indexed access), and with unordered sets - each object is present in the ordered set only once.
Creating ordered sets
For creating ordered sets from the serialized files, data dictionaries, streams and data objects class SCOrderedSet declares the following class methods:
+ (instancetype)orderedSetWithCoder:(NSCoder *)coder;
+ (instancetype)orderedSetWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)orderedSetWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)orderedSetWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)orderedSetWithStream:(
SCStream *)stream;
+ (instancetype)orderedSetWithFileStream:(NSString *)path;
+ (instancetype)orderedSetWithData:(NSData *)data;
+ (instancetype)orderedSetWithContentsOfFile:(NSString *)path;
+ (instancetype)orderedSetWithContentsOfURL:(NSURL *)url;
+ (instancetype)orderedSetWithContentsOfURLString:(NSString *)urlString;
Class SCOrderedSet implements the following class methods for creating ordered sets:
+ (instancetype)orderedSetWithName:(NSString *)name;
+ (instancetype)orderedSetWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)orderedSetWithArray:(
SCArray *)array;
+ (instancetype)orderedSetWithSet:(
SCSet *)set;
+ (instancetype)orderedSetWithOrderedSet:(
SCOrderedSet *)orderedSet;
+ (instancetype)orderedSet;
- Class method orderedSetWithName: returns the empty ordered set created by using the specified ordered set name:
NSLog( @"%@", orderedSet);
2016-07-26 10:54:09.862 libtest[3149:454751] Ordered set "Sample Ordered Set" count=0: {
)}
- Class method orderedSetWithObject: returns the ordered set created by using the specified existing object:
NSLog( @"%@", orderedSet);
2016-07-26 10:56:24.434 libtest[3166:455918] Ordered set count=1: {(
"00"
)}
- Class method orderedSetWithObjects: returns the ordered set created by using the specified nil terminated list of existing objects:
NSLog( @"%@", orderedSet);
2016-07-26 11:06:39.568 libtest[3191:458982] Ordered set count=3: {(
"00",
"02",
"01"
)}
- Class method orderedSetWithCollection: returns the ordered set created by using the specified existing collection of any supported type:
NSArray *source = [NSArray arrayWithObjects:@"00", @"02", @"01", nil];
NSLog( @"%@", orderedSet);
2016-07-26 11:10:53.932 libtest[3230:461010] Ordered set count=3: {(
"00",
"02",
"01"
)}
- Class method orderedSetWithArray: returns the ordered set created by using the specified existing array:
NSLog( @"%@", orderedSet);
2016-07-26 11:12:38.291 libtest[3251:462189] Ordered set count=3: {(
"00",
"02",
"01"
)}
- Class method orderedSetWithSet: returns the ordered set created by using the specified existing unordered set:
NSLog( @"%@", orderedSet);
2016-07-26 11:14:55.740 libtest[3281:463482] Ordered set count=3: {(
"01",
"00",
"02"
)}
- Class method orderedSetWithOrderedSet: returns the ordered set created by using the specified existing ordered set:
NSLog( @"%@", orderedSet);
2016-07-26 11:16:40.621 libtest[3300:464470] Ordered set count=3: {(
"00",
"02",
"01"
)}
- Class method orderedSet returns the empty unnamed ordered set created by using the default settings:
NSLog( @"%@", orderedSet);
2016-07-26 11:18:19.393 libtest[3317:465430] Ordered set count=0: {
)}
Initializing ordered sets
Class SCOrderedSet declares the following initializing methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)initWithSet:(
SCSet *)set;
- (instancetype)initWithOrderedSet:(
SCOrderedSet *)orderedSet;
- (instancetype)init;
- Method initWithName: initializes the empty ordered set with the specified name.
- Method initWithObject initializes the ordered set using the specified existing object.
- Method initWithObjects: initializes the ordered set using the specified nil terminated list of existing objects.
- Method initWithCollection: initializes the ordered set using the specified existing collection of any supported type.
- Method initWithArray: initializes the ordered set with the objects of the specified existing array.
- Method initWithSet: initialies the ordered set using the existing unordered set.
- Method initWithOrderedSet: initializes the copy of the existing ordered set.
- Method init initializes the empty unnamed ordered set with using the default settings.
Coping ordered sets
Class SCOrderedSet declares the following methods for ordered set coping:
- (void)setSet:(
SCSet *)set;
- Method setSet: (SCOrderedSet) removes the current settings and contents of the receiving orderes set and coping contents and settings from the specified existing unordered set:
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 14:42:13.786 libtest[4326:584007] Ordered set count=3: {(
"00",
"01",
"02"
)}
2016-07-26 14:42:13.786 libtest[4326:584007] Ordered set count=3: {(
"12",
"11",
"10"
)}
- Method setOrderedSet: replaces the current contents and settings of the receiving ordered set with the contents and settings of the specified existing ordered set:
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 14:45:29.657 libtest[4352:585705] Ordered set count=3: {(
"00",
"01",
"02"
)}
2016-07-26 14:45:29.658 libtest[4352:585705] Ordered set count=3: {(
"10",
"11",
"12"
)}
- Method setArray: removing from the receiving ordered set all existing objects and settings with objects and settings from the specified array.
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 15:25:27.657 libtest[4352:585705] Ordered set count=3: {(
"00",
"01",
"02"
)}
2016-07-26 15:25:27.658 libtest[4352:585705] Ordered set count=3: {(
"20",
"21",
"22"
)}
Comparing ordered sets
For the comparing operations class SCOrderedSet implements the following methods:
- (BOOL)isEqualToSet:(
SCSet *)set;
- (BOOL)isEqualToArray:(
SCArray *)array;
- Method isSubsetOfOrderedSet: returns a boolean value that indicates whether every object in the receiving ordered set is also present in a given collection of any supported type:
NSLog( @"%d", [orderedSet isSubsetOfSet:set]);
NSLog( @"%d", [orderedSet isSubsetOfOrderedSet:source]);
2016-07-26 15:44:30.141 libtest[4701:621519] 1
2016-07-26 15:44:30.141 libtest[4701:621519] 0
- Method intersectsOrderedSet: returns a boolean value that indicates whether at least one object in the receiving set is also present in a given collection of any supported type:
NSLog( @"%d", [orderedSet intersectsSet:set]);
NSLog( @"%d", [orderedSet intersectsOrderedSet:source]);
2016-07-26 15:55:25.821 libtest[4737:625668] 1
2016-07-26 15:55:25.821 libtest[4737:625668] 0
- Method isEqualToSet: returns a boolean value that indicates whether the contents of the receiving ordered set is equals to the contents of the specified set.
- Method isEqualToArray: compares the receiving ordered set with the specified array.
Deriving New Ordered Sets
Class SCOrderedSet implements the following methods for deriving new ordered set by using existing ordered sets:
- Method orderedSetByAddingObject: returns an ordered set that contains objects from the receiving ordered set and a given object:
NSLog( @"%@", [orderedSet orderedSetByAddingObject:@700]);
2017-06-13 12:57:37.403473+0300 libtest[1810:7093442] Ordered set count=4: {(
200,
800,
400,
700
)}
- Method orderedSetByAddingObjects: creates a new ordered set with objects from the receiving ordered set and objects from a given list:
NSLog( @"%@", [orderedSet orderedSetByAddingObjects:@100, @500, nil]);
2017-06-13 13:16:39.098112+0300 libtest[2145:7105107] Ordered set count=5: {(
200,
800,
400,
100,
500
)}
- Method orderedSetByAddingCollection: returns a new ordered set that contains objects from the receiving oredered set and objects from a given collection of any supported type:
NSLog( @"%@", [orderedSet orderedSetByAddingCollection:@[ @"One", @"Two"]]);
2017-06-13 13:24:25.571012+0300 libtest[2475:7111478] Ordered set count=5: {(
200,
800,
400,
One,
Two
)}
- Methods orderedSetByAddingObjectsFromArray: and orderedSetByAddingArray: create a new ordered set with objects from the receiving ordered set and objects from a given array:
NSLog( @"%@", [orderedSet orderedSetByAddingArray:source]);
2017-06-13 13:32:06.503600+0300 libtest[2803:7117490] Ordered set count=5: {(
200,
800,
400,
300,
700
)}
- Methods orderedSetByAddingObjectsFromSet: and orderedSetByAddingSet: return an ordered set that contains objects from the receivig ordered set and objects from a given set:
NSLog( @"%@", [orderedSet orderedSetByAddingSet:source]);
2017-06-13 13:40:55.681079+0300 libtest[3150:7124469] Ordered set count=5: {(
200,
800,
400,
One,
Two
)}
- Methods orderedSetByAddingObjectsFromOrderedSet: and orderedSetByAddingOrderedSet: create a new ordered set that contains objects from the receiving ordered set and objects from a given ordered set:
NSLog( @"%@", [orderedSet orderedSetByAddingOrderedSet:source]);
2017-06-13 13:51:42.858173+0300 libtest[3501:7132813] Ordered set count=5: {(
200,
800,
400,
MacOS,
Solaris
)}
Sorting ordered sets
Becase ordered sets support the indexed access to the objects, we also support and the sorting operations. As an arrays, ordered sets use the sorters - instances of the classes, which compliance to the SCSorter protocol. Class SCOrderedSet supports both methods with the specified sorters and with default library sorters. Details about the sorters you can obtain from the Programming Guide section Sorters.
During the sorting operation sorter comparing array object by using the protocol SCCollectioning method compareWithObject:.
Class SCOrderedSet implements the following methods and properties of sorting its contents:
- (void)sortAscendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortDescendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortWithSorter:(
id<
SCSorter>)sorter;
- (void)sortAscending;
- (void)sortDescending;
- (void)sort;
@property (nonatomic, readonly, assign)
SCOrderedSet *ascendingSortedOrderedSet;
@property (nonatomic, readonly, assign)
SCOrderedSet *descendingSortedOrderedSet;
@property (nonatomic, readonly, assign)
SCOrderedSet *sortedOrderedSet;
- Method sortAscendingWithSorter: sorts ascending the receiving ordered set using the specified sorter instance.
- Method sortDescendingWithSorter: sorts descending the receiving ordered set using the specified sorter instance.
- Method sortWithSorter: sorts ascending the receiving the receiving ordered set using the specified sorter instance. This method is analog of sortAscendingWithSorter:.
- Method sortAscending sorts ascending the receiving ordered set using the default sorter instance.
- Method sortDescending sorts descending the receiving ordered set using the default sorter instance.
- Method sort sorts ascending the receiving ordered set using the default sorter instance. This method is analog of sortAscending.
[orderedSet addObject:@"04"];
[orderedSet addObject:@"01"];
[orderedSet addObject:@"00"];
[orderedSet addObject:@"02"];
[orderedSet addObject:@"03"];
NSLog( @"================ SOURCE ORDERED SET =================");
NSLog( @"%@", orderedSet);
NSLog( @"=========== ASCENDING SORTED ORDERED SET ============");
NSLog( @"%@", orderedSet);
NSLog( @"=========== DESCENDING SORTED ORDERED SET ===========");
NSLog( @"%@", orderedSet);
2016-07-26 16:53:02.377 libtest[5100:665305] ================ SOURCE ORDERED SET =================
2016-07-26 16:53:02.377 libtest[5100:665305] Ordered set count=5: {(
"04",
"01",
"00",
"02",
"03"
)}
2016-07-26 16:53:02.378 libtest[5100:665305] =========== ASCENDING SORTED ORDERED SET ============
2016-07-26 16:53:02.378 libtest[5100:665305] Ordered set count=5: {(
"00",
"01",
"02",
"03",
"04"
)}
2016-07-26 16:53:02.378 libtest[5100:665305] =========== DESCENDING SORTED ORDERED SET ===========
2016-07-26 16:53:02.378 libtest[5100:665305] Ordered set count=5: {(
"04",
"03",
"02",
"01",
"00"
)}
Also the class SCOrderedSet declares the class methods for creating ordered sets using the sorted contents of the existing collection of any supported type:
+ (instancetype)orderedSetWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithAscendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)orderedSetWithDescendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)orderedSetWithSortedCollection:(
id<
SCCollection>)collection;
Additionally class SCOrderedSet implements the methods for initializing the ordered sets using the sorted contents of the existing collections of any supported type:
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithSortedCollection:(
id<
SCCollection>)collection;
In addition to copying methods class SCOrderedSet provides the following methods of copying sorted contents of the existing collections of any supported type:
- (void)setAscendingSortedCollection:(
id<
SCCollection>)collection;
- (void)setDescendingSortedCollection:(
id<
SCCollection>)collection;
Adding objects to ordered set
Class SCOrderSet extends the class SCCollection by implementing the advanced methods for adding objects into the ordered set. Please note that each object can be added to an ordered set only once - second attempt to add an object to be ignored.
- (void)insertAtIndexes:(NSIndexSet *)indexes objects:(
id<
SCCollectioning>)object, ...;
- (void)insertCollection:(
id<
SCCollection>)collection atIndexes:(NSIndexSet *)indexes;
- (void)addObjectsFromArray:(
SCArray *)array;
- (void)addObjectsFromSet:(
SCSet *)set;
- (void)addSet:(
SCSet *)set;
- (void)addObjectsFromOrderedSet:(
SCOrderedSet *)orderedSet;
- Method insertObject:atIndex: inserts the specified object into receiving ordered set at a given index:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 17:32:25.025 libtest[5549:699992] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:32:25.025 libtest[5549:699992] Ordered set count=5: {(
"Object 00",
"Object 01",
"=========",
"Object 02",
"Object 03"
)}
- Method insertAtIndex:objects: inserts the objects from a given nil terminated list into the ordered set's contents at a given index:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 17:33:32.735 libtest[5569:701031] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:33:32.736 libtest[5569:701031] Ordered set count=7: {(
"Object 00",
"Object 01",
"=========",
"Object AA",
"---------",
"Object 02",
"Object 03"
)}
- Method insertCollection:atIndex: inserts the objects from a given collection into the receiving ordered set at a given index:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 17:38:36.784 libtest[5607:703539] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:38:36.784 libtest[5607:703539] Ordered set count=7: {(
"Object 00",
"Object 01",
"=========",
"Object XX",
"---------",
"Object 02",
"Object 03"
)}
- Method insertAtIndexes:objects: inserts the objects from a given nil terminated list into the receiving ordered set at the specified indexes:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", orderedSet);
2016-07-26 17:39:39.909 libtest[5629:704448] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:39:39.910 libtest[5629:704448] Ordered set count=6: {(
"Object 00",
"=========",
"---------",
"Object 01",
"Object 02",
"Object 03"
)}
- Method insertCollection:atIndexes: inserts the objects from a given collection into the receiving ordered set at the specified indexes:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", orderedSet);
2016-07-26 17:41:50.263 libtest[5654:706235] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:41:50.263 libtest[5654:706235] Ordered set count=6: {(
"Object 00",
"---------",
"=========",
"Object 01",
"Object 02",
"Object 03"
)}
- Method setObject:atIndex: replaces within the ordered set the object at the specified index with a given object. If the required index does not found, the method adds a given index into the ordered set.
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-26 17:43:13.001 libtest[5676:707389] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-26 17:43:13.001 libtest[5676:707389] Ordered set count=5: {(
"Object 00",
"=========",
"Object 02",
"Object 03",
"---------"
)}
- Methods addObjectsFromArray: and addArray: add into the receiving ordered set objects from a given array:
NSLog( @"%@", orderedSet);
2017-06-13 14:10:46.729899+0300 libtest[3884:7145349] Ordered set count=5: {(
200,
800,
400,
Windows,
SCO
)}
- Methods addObjectsFromSet: and addSet: add into the receiving ordered set objects from a given set:
NSLog( @"%@", orderedSet);
2017-06-13 14:17:57.552421+0300 libtest[4209:7151184] Ordered set count=5: {(
200,
800,
400,
One,
Two
)}
- Methods addObjectsFromOrderedSet: and addOrderedSet: add into the receiving ordered set objects from a given ordered set:
NSLog( @"%@", orderedSet);
2017-06-13 14:26:37.236315+0300 libtest[4543:7158721] Ordered set count=5: {(
200,
800,
400,
100,
500
)}
Removing objects from ordered set
Class SCOrderSet expands the parent class SCCollection by adding the following methods for removing objects from the ordered set:
- (void)removeFirstObject;
- (void)removeLastObject;
- (void)removeObjectAtIndex:(
SCIndex)index;
- (void)removeObjectsAtIndexes:(NSIndexSet *)indexes;
- (void)removeObjectsInRange:(NSRange)range;
- Method removeFirstObject removes from ordered set the first object:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 09:12:13.634 libtest[10663:2559320] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 09:12:13.634 libtest[10663:2559320] Ordered set count=3: {(
"Object 01",
"Object 02",
"Object 03"
)}
- Method removeLastObject removes from ordered set the last object:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 09:15:43.558 libtest[10687:2561724] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 09:15:43.559 libtest[10687:2561724] Ordered set count=3: {(
"Object 00",
"Object 01",
"Object 02"
)}
- Method removeObjectAtIndex: removes from ordered set the object at the specified index:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 09:53:53.227 libtest[10766:2579288] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 09:53:53.228 libtest[10766:2579288] Ordered set count=3: {(
"Object 00",
"Object 02",
"Object 03"
)}
- Method removeObjectsAtIndexes: removes from ordered set the objects at the indexes from the specified index set:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:3];
NSLog( @"%@", orderedSet);
2016-07-31 09:56:12.806 libtest[10791:2580745] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 09:56:12.806 libtest[10791:2580745] Ordered set count=2: {(
"Object 00",
"Object 02"
)}
- Method removeObjectsInRange: removes from the ordered set objects in the specified range:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSRange range = NSMakeRange( 1, 2);
NSLog( @"%@", orderedSet);
2016-07-31 09:59:20.185 libtest[10821:2583031] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 09:59:20.185 libtest[10821:2583031] Ordered set count=2: {(
"Object 00",
"Object 03"
)}
Replacing ordered set objects
Class SCOrderedSet declares the following methods for replacing objects in the ordered set:
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withObjects:(
id<
SCCollectioning>)object, ...;
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withCollection:(
id<
SCCollection>)collection;
- (void)replaceObjectsInRange:(NSRange)range withObjects:(
id<
SCCollectioning>)object, ...;
- (void)replaceObjectsInRange:(NSRange)range withCollection:(
id<
SCCollection>)collection;
- Method replaceObjectAtIndex:withObject: replaces the object at the specified index with a given object. From method setObject:atIndex: differs in that an error SCL-20052 occurs in the absence of an object at a specified index.
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 10:17:03.999 libtest[11005:2599915] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 10:17:03.999 libtest[11005:2599915] Ordered set count=4: {(
"Object 00",
"=========",
"Object 02",
"Object 03"
)}
- Method replaceObjectsAtIndexes:withObjects: replaces the objects in the receiving ordered set at specified locations with the objects from a given nil terminated list. Number of objects must be equal to the number of indexes.
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:3];
NSLog( @"%@", orderedSet);
2016-07-31 10:18:36.498 libtest[11028:2601079] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 10:18:36.499 libtest[11028:2601079] Ordered set count=4: {(
"=========",
"Object 01",
"Object 02",
"---------"
)}
- Method replaceObjectsAtIndexes:withCollection: replaces the objects in the receiving ordered set at specified locations with the objects from a given collection of any supported type. Number of indexes must be equal to the number of objects.
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", orderedSet);
2016-07-31 10:20:29.789 libtest[11059:2602638] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 10:20:29.789 libtest[11059:2602638] Ordered set count=4: {(
"Object 00",
"---------",
"=========",
"Object 03"
)}
- Method replaceObjectsInRange:withObjects: replaces the objects in the receiving ordered set specified by a given range with all of the objects from a specified nil terminated list:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSRange range = NSMakeRange( 2, 2);
NSLog( @"%@", orderedSet);
2016-07-31 10:22:37.616 libtest[11086:2604659] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 10:22:37.616 libtest[11086:2604659] Ordered set count=4: {(
"Object 00",
"Object 01",
"=========",
"---------"
)}
- Method replaceObjectsInRange:withCollection: replaces the objects in the receiving ordered set specified by a given range with all of the objects from a specified collection of any supported type:
[orderedSet addObject:@"Object 00"];
[orderedSet addObject:@"Object 01"];
[orderedSet addObject:@"Object 02"];
[orderedSet addObject:@"Object 03"];
NSLog( @"%@", orderedSet);
NSRange range = NSMakeRange( 0, 2);
NSArray *source = [NSArray arrayWithObjects:@"=========", @"---------", nil];
NSLog( @"%@", orderedSet);
2016-07-31 10:23:52.218 libtest[11111:2606214] Ordered set count=4: {(
"Object 00",
"Object 01",
"Object 02",
"Object 03"
)}
2016-07-31 10:23:52.218 libtest[11111:2606214] Ordered set count=4: {(
"=========",
"---------",
"Object 02",
"Object 03"
)}
- Method setObject:atIndexedSubscript: replaces an object at a given index with a specified new object and provides support of the operator []:
NSLog( @"%@", set);
set[2] = @"3000";
NSLog( @"%@", set);
2017-09-11 10:25:32.366982+0300 libtest[12189:385967] Ordered set count=4: {(
100,
200,
300,
400
)}
2017-09-11 10:25:32.367254+0300 libtest[12189:385967] Ordered set count=4: {(
100,
200,
3000,
400
)}
Moving ordered set objects
Class SCOrderedSet implemens the following methods for moving objects within ordered set:
- (void)exchangeObjectAtIndex:(
SCIndex)index withObjectAtIndex:(
SCIndex)destination;
- (void)moveObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)reverse;
- Method exchangeObjectAtIndex:withObjectAtIndex: exchanges the objects in the ordered set at given indices:
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 21:13:19.872 libtest[12438:2843276] Ordered set count=4: {(
"00",
"01",
"02",
"03"
)}
2016-07-31 21:13:19.872 libtest[12438:2843276] Ordered set count=4: {(
"03",
"01",
"02",
"00"
)}
- Method moveObjectAtIndex:toIndex: moves the object at the specified index to a given destination index:
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 21:17:26.065 libtest[12458:2844716] Ordered set count=4: {(
"00",
"01",
"02",
"03"
)}
2016-07-31 21:17:26.065 libtest[12458:2844716] Ordered set count=4: {(
"01",
"02",
"00",
"03"
)}
- Method reverse reverses the orderes set contents:
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 21:20:25.235 libtest[12487:2846893] Ordered set count=4: {(
"00",
"01",
"02",
"03"
)}
2016-07-31 21:20:25.235 libtest[12487:2846893] Ordered set count=4: {(
"03",
"02",
"01",
"00"
)}
Ordered set objects access
For accessing to the ordered set objects the class SCOrderedSet implements the following access properties and methods:
@property (nonatomic, readonly, assign)
SCOrderedSet *reversedOrderedSet;
@property (nonatomic, readonly, assign)
SCArray *allObjects;
@property (nonatomic, readonly, assign) id firstObject;
@property (nonatomic, readonly, assign) id lastObject;
- (id)objectAtIndex:(
SCIndex)index;
- (
SCArray *)objectsAtIndexes:(NSIndexSet *)indexes;
- (id)objectAtIndexedSubscript:(
SCIndex)index;
- Property reversedOrderedSet returns the ordered set with the reversed objects order:
2016-07-26 13:54:53.571 libtest[4083:552496] Ordered set count=5: {(
"04",
"03",
"02",
"01",
"00"
)}
- Property allObjects returns an array containing the ordered set's members:
2016-07-26 13:30:11.708 libtest[3953:541772] Array count=3: (
"00",
"02",
"01"
)
- Property firstObject returns one of the objects in the ordered set:
2016-07-26 13:40:59.909 libtest[3990:544807] 00
- Property lastObject returns the last object of the orderes set or nil if the orderes set is empty:
2016-07-26 13:46:09.258 libtest[4012:547211] 01
- Method objectAtIndex: returns the ordered set object at the specified index. If the index is incorrect, the error SCL-20052 is occurs.
NSLog( @"%@", [orderedSet objectAtIndex:1]);
2016-07-26 13:50:05.347 libtest[4035:549560] 02
- Method objectsAtIndexes: returns the array with ordered set objects at the indexes from the specified indexes set. If the indexes set is incorrect, the error 20054 is occurs.
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:2];
[indexSet addIndex:4];
NSLog( @"%@", [orderedSet objectsAtIndexes:indexSet]);
2016-07-26 13:53:23.937 libtest[4064:551396] Array count=3: (
"00",
"02",
"04"
)
- Method objectAtIndexedSubscript: returns an object which locates at a given index and provides support of operator []:
2017-09-11 10:37:54.160326+0300 libtest[12444:395366] 200
Search ordered set objects
For search objects in the ordered set class SCOrderedSet declares the following methods:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastObject;
- Method indexOfObject: returns the index of the specified object or values NSNotFound if the required object doesn not found in the ordered set:
NSLog( @"%d", [orderedSet indexOfObject:@"02"]);
NSLog( @"%d", [orderedSet indexOfObject:@"04"]);
2016-07-26 15:20:47.680 libtest[4490:608235] 2
2016-07-26 15:20:47.680 libtest[4490:608235] -1
- Property indexOfLastObject returns the index of the last object from the ordered set or value NSNotFound if the ordered set is empty:
NSLog( @"%d", [orderedSet indexOfLastObject]);
2016-07-26 15:21:59.854 libtest[4506:609242] 3
Combining and recombining ordered sets
Class SCOrderedSet declares the following methods for combining and recombining ordered sets:
- Method unionOrderedSet: adds each object from the specified ordered set to the receiving ordered set, if not present. This opeation also names the union sets. Method unionSet: works in an analogous, but can accepts the collection of any supported type.
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 11:16:16.240 libtest[11456:2642711] Ordered set count=3: {(
"00",
"02",
"04"
)}
2016-07-31 11:16:16.240 libtest[11456:2642711] Ordered set count=5: {(
"00",
"02",
"04",
"01",
"03"
)}
- Method minusOrderedSet: removes each object in another given ordered set from the receiving ordered set, if present. This operation also names the minus sets. Method minusSet: works in an analogous, but can accepts the collection of any supported type.
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 11:18:32.299 libtest[11487:2645000] Ordered set count=5: {(
"00",
"01",
"02",
"03",
"04"
)}
2016-07-31 11:18:32.299 libtest[11487:2645000] Ordered set count=3: {(
"00",
"02",
"04"
)}
- Method intersectOrderedSet: removes from the receiving ordered set each object that isn't a member of the specified ordered set. The method intersectSet: works in an analogous, but can accepts the collection of any supported type.
NSLog( @"%@", orderedSet);
NSLog( @"%@", orderedSet);
2016-07-31 11:24:04.137 libtest[11518:2649148] Ordered set count=5: {(
"00",
"01",
"02",
"03",
"04"
)}
2016-07-31 11:24:04.137 libtest[11518:2649148] Ordered set count=2: {(
"01",
"03"
)}
Dictionaries
Class SCDictionary defines the interface to the data storage of the records of type "key - value", accessed by the keys, which is a text strings. Values of dictionary is a instances of classes, which comply to the SCCollectioning protocol.
Creating dictionaries
For creating dictionaries using serialized files, data dictionaries, streams and data objects class SCDictionary declares the following class methods:
+ (instancetype)dictionaryWithCoder:(NSCoder *)coder;
+ (instancetype)dictionaryWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)dictionaryWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)dictionaryWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)dictionaryWithStream:(
SCStream *)stream;
+ (instancetype)dictionaryWithFileStream:(NSString *)path;
+ (instancetype)dictionaryWithData:(NSData *)data;
+ (instancetype)dictionaryWithContentsOfFile:(NSString *)path;
+ (instancetype)dictionaryWithContentsOfURL:(NSURL *)url;
+ (instancetype)dictionaryWithContentsOfURLString:(NSString *)urlString;
Class SCDictionary implements the following class methods for class instances creating:
+ (instancetype)dictionaryWithName:(NSString *)name;
+ (instancetype)dictionaryWithObject:(
id<
SCCollectioning>)object forKey:(NSString *)key;
+ (instancetype)dictionaryWithObjectsAndKeys:(
id<
SCCollectioning>)object, ...;
+ (instancetype)dictionaryWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)dictionaryWithDictionary:(
SCDictionary *)dictionary;
+ (instancetype)dictionary;
- Method dictionaryWithName: returns the empty dictionary created by using the specified dictionary name:
NSLog( @"%@", dictionary);
2016-07-31 22:29:31.434 libtest[12845:2892139] Dictionary "Sample Dictionary" count=0: {
}
- Method dictionaryWithObject:forKey: returns the dictionary created by using the specified object and key:
NSLog( @"%@", dictionary);
2016-07-31 22:31:19.190 libtest[12864:2893905] Dictionary count=1: {
"System" = "MacOS";
}
- Method dictionaryWithObject: returns the dictionary created by using the specified existing object with the automatically generated key:
NSLog( @"%@", dictionary);
2016-07-31 22:32:27.592 libtest[12892:2894987] Dictionary count=1: {
"Key 0" = "1.0.0";
}
- Method dictionaryWithObjects:forKeya: returns the dictionary created by using the specified objects and keys collections. As an objects and keys source can be used the collection of any supported type.
NSLog( @"%@", dictionary);
2016-07-31 22:36:07.013 libtest[12942:2896819] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Method dictionaryWithObjects: returns the dictionary created by using the specified nil terminated list of existing objects. Keys for objects generate automatically.
NSLog( @"%@", dictionary);
2016-07-31 22:38:11.019 libtest[12966:2898668] Dictionary count=3: {
"Key 0" = "FreeBSD";
"Key 1" = "3.2.0";
"Key 2" = "i386";
}
- Method dictionaryWithObjectsAndKeys: returns the dictionary created by using the objects and keys from the specified nil terminated list:
NSLog( @"%@", dictionary);
2016-07-31 22:40:06.682 libtest[12988:2900318] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Method dictionaryWithCollection: returns the dictionary created by using the specified existing collection of any supported type. If the source collection does not dictionary, the keys for objects are generated automatically.
NSLog( @"%@", dictionary);
2016-07-31 22:41:52.728 libtest[13012:2901574] Dictionary count=3: {
"Key 0" = "FreeBSD";
"Key 1" = "3.2.0";
"Key 2" = "i386";
}
- Method dictionaryWithDictionary: returns the dictionary created by using the existing dictionary:
NSLog( @"%@", dictionary);
2016-07-31 22:43:38.354 libtest[13033:2902816] Dictionary count=2: {
"Key 0" = "FreeBSD";
"Key 1" = "i386";
}
- Method dictionary returns the empty unnamed dictionary created by using the default settings:
NSLog( @"%@", dictionary);
2016-07-31 22:44:44.243 libtest[13049:2903800] Dictionary count=0: {
}
Initializing dictionaries
Class SCDictionary declares the following initialization methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithObject:(
id<
SCCollectioning>)object forKey:(NSString *)key;
- (instancetype)initWithCollection:(<
SCCollection>
id)collection;
- (instancetype)initWithDictionary:(
SCDictionary *)dictionary;
- (instancetype)init;
- Method initWithName: initializes the empty dictionary with the specified name.
- Method initWithObject:forKey: initializes the dictionary using the specified object and key.
- Method initWithObject: initializes the dictionary using the specified existing object with the automatically generated key.
- Method initWithObjects:forKeys: initializes the dictionary using the specified objects and keys collections. As an objects and keys source can be used the collection of any supported type.
- Method initWithObjects: initializes the dictionary using the specified nil terminated list of existing objects. Keys for objects generate automatically.
- Method initWithObjectsAndKeys: initializes the dictionary using the objects and keys from the specified nil terminated list.
- Method initWithCollection: initializes the dictionary using the specified existing collection of any supported type. If the source collection does not dictionary, the keys for objects are generated automatically.
- Method initWithDictionary: initializes the dictionary using the existing dictionary.
- Method init initializes the empty unnamed dictionary using the default settings.
Coping dictionaries
Class SCDictionary declares the following methods for dictionaries coping:
- Method setDictionary: removes the current settings and contents of the receiving dictionary and coping contents and settings from the specified existing dictionary:
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2017-03-28 16:41:05.324850 libtest[25097:616641] Dictionary count=2: {
Login = root;
UID = 0
}
2017-03-28 16:41:05.325553 libtest[25097:616641] Dictionary count=2: {
Home = /usr/home/root;
Active = 1
}
Comparing dictionaries
Class SCDictionary implements the following comparing methods:
- Method isEqualToDictionary: returns a boolean value that indicates whether the contents of the receiving dictionary is equals to the contents of another given dictionary.
Deriving New Dictionaries
Class SCDictionary implements the following methods for deriving new dictionaries by using entries from existing dictionaries:
- Method dictionaryByAddingObject:forKey: returns a new dictionary that contains all entries from the receiving dictionary and a new entry constructed from a given object and key:
NSLog( @"%@", [dictionary dictionaryByAddingObject:@"10.12.4" forKey:@"Version"]);
2017-06-16 16:10:52.996548+0300 libtest[18438:9863570] Dictionary count=2: {
Version = 10.12.4;
System = MacOS
}
- Method dictionaryByAddingObject: creates and returns a new dictionary that contains all entries from the receiving dictionary and a new antry constructed from a given object and an automatic generated key:
NSLog( @"%@", [dictionary dictionaryByAddingObject:@"root"]);
2017-06-16 16:47:54.457082+0300 libtest[18808:9891651] Dictionary count=2: {
"Key 1" = root;
System = MacOS
}
- Method dictionaryByAddingObjects:forKeys: returns a dictionary with entries from the receiving dictionary and entries constructed by using objects and keys from a given collections of any supported type:
NSLog( @"%@", [dictionary dictionaryByAddingObjects:@[ @"10.12.4", @"root"] forKeys:@[ @"Version", @"Login"]]);
2017-06-16 17:16:30.995951+0300 libtest[19184:9911573] Dictionary count=3: {
Version = 10.12.4;
System = MacOS;
Login = root
}
- Method dictionaryByAddingObjects: returns a new dictionary that contains entries from the receiving dictionary and new entries constructed by using objects from a given list and automatic generated keys:
NSLog( @"%@", [dictionary dictionaryByAddingObjects:@"10.12.4", @"root", nil]);
2017-06-16 17:49:08.709901+0300 libtest[19566:9934018] Dictionary count=3: {
"Key 1" = 10.12.4;
System = MacOS;
"Key 2" = root
}
- Method dictionaryByAddingObjectsAndKeys: creates a new dictionary that contains entries from the receiving dictoinary and new entries constructed by using objects and keys from a given list:
NSLog( @"%@", [dictionary dictionaryByAddingObjectsAndKeys:@"root", @"Login", @"10.12.4", @"Version", nil]);
2017-06-16 18:02:44.858796+0300 libtest[20169:9944024] Dictionary count=3: {
Login = root;
System = MacOS;
Version = 10.12.4
}
- Method dictionaryByAddingCollection: returns a dictionary with entries from the receiving dictionary and objects from a given collection of any supported type:
NSLog( @"%@", [dictionary dictionaryByAddingCollection:@{ @"Version":@"10.12.4", @"Mode":@"Verbose"}]);
2017-06-16 18:15:15.538356+0300 libtest[20519:9954000] Dictionary count=3: {
Version = 10.12.4;
System = MacOS;
Mode = Verbose
}
- Methods dictionaryByAddingObjectsFromArray: and dictionaryByAddingArray: return a new dictionary that contains entries from the receiving array and objects from a given array:
NSLog( @"%@", [dictionary dictionaryByAddingArray:array]);
2017-06-20 18:40:39.870908+0300 libtest[28845:11369225] Dictionary count=3: {
"Key 1" = root;
System = MacOS;
"Key 2" = daemon
}
- Methods dictionaryByAddingEntriesFromDictionary: and dictionaryByAddingDictionary: create a new dictionary with entries from the receiving dictionary and entries from a given another dictionary:
NSLog( @"%@", [dictionary dictionaryByAddingDictionary:source]);
2017-06-20 18:57:31.875307+0300 libtest[29292:11384867] Dictionary count=3: {
Version = 10.12.4;
System = MacOS;
Login = root
}
Adding and changing dictionary objects
For adding and changing objects and values class SCDictionary implements the following methods:
- (void)setObject:(
id<
SCCollectioning>)object forKeyedSubscript:(NSString *)key;
- (void)addObjectsFromArray:(
SCArray *)array;
- (void)addEntriesFromDictionary:(
SCDictionary *)dictionary;
- Method setObject:forKey: adds a given key-value pair to the receiving dictionary. If the dictionary already contains the object for the specified key, then method replaces existing object with the specified object.
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 00:15:33.482 libtest[21322:3849202] Dictionary count=0: {
}
2016-08-05 00:15:33.483 libtest[21322:3849202] Dictionary count=2: {
"Version" = "10.11.0";
"System" = "MacOS";
}
2016-08-05 00:15:33.483 libtest[21322:3849202] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Method setObject:forKeyedSubscript: works similar to a method setObject:forKey:, but provides the support of the operator []:
dictionary[@"100"] = @100;
dictionary[@"200"] = @200;
dictionary[@"300"] = @300;
dictionary[@"400"] = @400;
NSLog( @"%@", dictionary);
2017-09-11 11:22:58.003939+0300 libtest[13397:422268] Dictionary count=4: {
100 = 100;
200 = 200;
300 = 300;
400 = 400
}
- Method setObjects:forKeys: adds into the receiving dictionary the objects and keys from the specified collections of any supported types:
[dictionary setBool:YES forKey:@"Debug"];
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 12:24:33.413 libtest[21847:3956134] Dictionary count=2: {
"Debug" = "1";
"System" = "FreeBSD";
}
2016-08-05 12:24:33.414 libtest[21847:3956134] Dictionary count=3: {
"Debug" = "NO";
"System" = "MacOS";
"Version" = "10.11.6";
}
- Method setObjectsAndKeys: add into the receiving dictionary the objects and keys from the nil terminated list. This list must contains objects as odd items and keys as even items.
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 12:26:44.280 libtest[21886:3956999] Dictionary count=1: {
"System" = "FreeBSD";
}
2016-08-05 12:26:44.280 libtest[21886:3956999] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Method setValue:forKey: adds a given key-value pair to the dictionary. If the values for the specified key already exists, it replaces by the specified new value.
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 08:27:05.785 libtest[21648:3943305] Dictionary count=0: {
}
2016-08-05 08:27:05.785 libtest[21648:3943305] Dictionary count=2: {
"Version" = "10.11.0";
"System" = "MacOS";
}
2016-08-05 08:27:05.785 libtest[21648:3943305] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Method setValues:forKeys: add into the receiving dictionary the values and keys from the specified collections of any supported type:
[dictionary setBool:YES forKey:@"Debug"];
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 12:25:24.602 libtest[21864:3956609] Dictionary count=2: {
"Debug" = "1";
"System" = "FreeBSD";
}
2016-08-05 12:25:24.602 libtest[21864:3956609] Dictionary count=3: {
"Debug" = "NO";
"System" = "MacOS";
"Version" = "10.11.6";
}
- Method setValuesAndKeys: adds into the receiving dictionary the values and keys from the specified nil terminated list. This list must contains values as add items and keys as even items.
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 12:26:44.280 libtest[21886:3956999] Dictionary count=1: {
"System" = "FreeBSD";
}
2016-08-05 12:26:44.280 libtest[21886:3956999] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
- Methods addObjectsFromArray: and addArray: add into the receiving dictionary entries constructed by using objects from a given array and automatic generated keys:
NSLog( @"%@", dictionary);
2017-06-20 19:38:03.651093+0300 libtest[29803:11415636] Dictionary count=3: {
"Key 1" = /bin;
System = MacOS;
"Key 2" = /sbin
}
- Methods addEntriesFromDictionary: and addDictionary: add into the receiving dictionary entries from a given another dictionary:
NSLog( @"%@", dictionary);
2017-06-20 19:49:39.337625+0300 libtest[30137:11425212] Dictionary count=3: {
Version = 10.12.4;
System = MacOS;
Mode = Normal
}
- Method addObjects:forKeys: adds into the receiving dictionary objects from a given collection of any supported type with keys from the specified collection of any supported type:
[dictionary
addObjects:@[ @"root", @"System Administrator"]
forKeys:@[ @"Login", @"Name"]];
NSLog( @"%@", dictionary);
2017-06-20 20:07:50.529163+0300 libtest[30482:11438120] Dictionary count=3: {
Login = root;
System = MacOS;
Name = "System Administrator"
}
- Method addObjectsAndKeys: adds into the receiving dictionary objects and keys from a given list:
NSLog( @"%@", dictionary);
2017-06-20 20:25:08.484846+0300 libtest[31127:11452314] Dictionary count=3: {
Version = 10.12.4;
System = MacOS;
Login = root
}
Removing objects from dictionary
Class SCDictionary implements the following methods for removing objects and values:
- (void)removeObjectForKey:(NSString *)key;
- (void)removeObjectsForKeys:(id)keys;
- Method removeObjectForKey: removes from the receiving dictionary the object with the specified key:
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 16:55:23.917 libtest[22065:3974032] Dictionary count=4: {
"Version" = "10.11.6";
"Contact" = "samond@mac.com";
"System" = "MacOS";
"Debug" = "0";
}
2016-08-05 16:55:23.917 libtest[22065:3974032] Dictionary count=3: {
"Version" = "10.11.6";
"System" = "MacOS";
"Debug" = "0";
}
- Method removeObjectsForKeys: removes from the receiving dictionary objects for the keys from the specified nil terminated list:
NSLog( @"%@", dictionary);
NSLog( @"%@", dictionary);
2016-08-05 16:56:33.868 libtest[22085:3974528] Dictionary count=4: {
"Version" = "10.11.6";
"Contact" = "samond@mac.com";
"System" = "MacOS";
"Debug" = "0";
}
2016-08-05 16:56:33.868 libtest[22085:3974528] Dictionary count=2: {
"Version" = "10.11.6";
"System" = "MacOS";
}
Dictionary keys and values access
The following class SCDictionary properties and methods provide group access to keys and values within the dictionary:
@property (nonatomic, readonly, assign)
SCArray *allKeys;
@property (nonatomic, readonly, assign)
SCArray *allValues;
- Property allKeys returns an array containing the dictionary's keys or empty array if the dictionary is empty:
NSLog( @"%@", [dictionary allKeys]);
2016-08-04 12:51:33.814 libtest[20119:3757168] Array count=3: (
"Version",
"System",
"Contact"
)
- Property allValues returns an array containing the dictionary's values or empty array if the receiving dictionary is empty:
NSLog( @"%@", [dictionary allValues]);
2016-08-04 12:52:26.829 libtest[20138:3757749] Array count=3: (
"10.11.6",
"MacOS",
"samond@mac.com"
)
- Method allKeysForObject: returns an array containing the keys corresponding to all occurrences of a given object in the dictionary. If the required object does not found in the dictionary, this method returns an empty array.
NSLog( @"%@", [dictionary allKeysForObject:@"MacOS"]);
2016-08-04 12:53:49.544 libtest[20163:3758359] Array count=2: (
"System",
"HostName"
)
For accessing to objects and values assoicated with a keys the class declares the following methods:
- (id)objectForKey:(NSString *)key;
- (id)objectForKeyedSubscript:(NSString *)key;
- (id)valueForKey:(NSString *)key;
- Method objectForKey: returns the object associated with a given key or nil if the specified key does not found in the receiving dictionary:
NSLog( @"%@", [dictionary objectForKey:@"System"]);
NSLog( @"%@", [dictionary objectForKey:@"OS"]);
2016-08-04 13:16:01.573 libtest[20308:3766321] MacOS
2016-08-04 13:16:01.573 libtest[20308:3766321] (null)
- Method objectForKeyedSubscript: also returns an object, which is associate with a given key, but this method provides the support of the operator [];
NSLog( @"%@", dictionary[@"200"]);
2017-09-11 11:40:53.172334+0300 libtest[13682:438714] 200
- Method valueForKey: returns the value associated with a given key or a nil if the required key does not found in the receiving dictionary:
NSLog( @"%@", [dictionary valueForKey:@"System"]);
NSLog( @"%@", [dictionary valueForKey:@"OS"]);
2016-08-04 13:24:52.514 libtest[20402:3772023] MacOS
2016-08-04 13:24:52.514 libtest[20402:3772023] (null)
Search dictionary objects and keys
Class SCDictionary implements the following object searching methods:
- (BOOL)containsObjectForKey:(NSString *)key;
- (BOOL)containsStringForKey:(NSString *)key;
- (BOOL)containsNumberForKey:(NSString *)key;
- Method containsObjectForKey: returns a Boolean value that indicates whether an object for the given key is present in the receiving dictionary:
[dictionary setBool:NO forKey:@"Debug"];
NSLog( @"%d", [dictionary containsObjectForKey:@"System"]);
NSLog( @"%d", [dictionary containsObjectForKey:@"OS"]);
2016-08-04 13:57:18.504 libtest[20528:3780098] 1
2016-08-04 13:57:18.504 libtest[20528:3780098] 0
- Method containsStringForKey: returns a Boolean value that indicates whether a string for the given key is present in the receiving dictionary. If the requested key does not found or associated object does not string, then method returns value NO.
[dictionary setBool:NO forKey:@"Debug"];
NSLog( @"%d", [dictionary containsStringForKey:@"System"]);
NSLog( @"%d", [dictionary containsStringForKey:@"Debug"]);
NSLog( @"%d", [dictionary containsStringForKey:@"Verbose"]);
2016-08-04 13:58:04.605 libtest[20545:3780477] 1
2016-08-04 13:58:04.605 libtest[20545:3780477] 0
2016-08-04 13:58:04.606 libtest[20545:3780477] 0
- Method containsNumberForKey: returns a Boolean value that indicates whether a number for the given key is present in the receiving dictionary. If the required key does not found or associated object does not number, then method returns value NO.
[dictionary setBool:NO forKey:@"Debug"];
NSLog( @"%d", [dictionary containsNumberForKey:@"System"]);
NSLog( @"%d", [dictionary containsNumberForKey:@"Debug"]);
NSLog( @"%d", [dictionary containsNumberForKey:@"TimeStamp"]);
2016-08-04 14:03:12.392 libtest[20617:3782577] 0
2016-08-04 14:03:12.392 libtest[20617:3782577] 1
2016-08-04 14:03:12.392 libtest[20617:3782577] 0
- Method containsAnyObjectForKeys: returns a Boolean value that indicates whether an object for at least one key from the specified collection of any supported type is present in the receiving dictionary.
[dictionary setBool:NO forKey:@"Debug"];
NSLog( @"%d", [dictionary containsAnyObjectForKeys:keys]);
[keys removeObject:@"System"];
NSLog( @"%d", [dictionary containsAnyObjectForKeys:keys]);
2016-08-04 14:00:16.888 libtest[20573:3781382] 1
2016-08-04 14:00:16.888 libtest[20573:3781382] 0
- Method containsAllObjectsForKeys: returns a Boolean value that indicates whether an object for all keys from the specified collection of any supported type are present in the receiving dictionary.
[dictionary setBool:NO forKey:@"Debug"];
NSLog( @"%d", [dictionary containsAllObjectsForKeys:keys]);
[keys addObject:@"Verbose"];
NSLog( @"%d", [dictionary containsAllObjectsForKeys:keys]);
2016-08-04 14:01:25.290 libtest[20593:3781974] 1
2016-08-04 14:01:25.291 libtest[20593:3781974] 0
For finding keys within the dictionary, class SCDictionary declares following methods:
- (BOOL)containsKey:(NSString *)key;
- (BOOL)containsKeys:(NSString *)key, ...;
- (BOOL)containsKeysFromCollection:(
id<
SCCollection>)collection;
- (BOOL)containsAnyKey:(NSString *)key, ...;
- (BOOL)containsAnyKeyFromCollection:(
id<
SCCollection>)collection;
- Method containsKey: returns a boolean value that indicates whether the receiving dictionary contains an object for a specified key:
NSLog( @"%d", [dictionary containsKey:@"System"]);
NSLog( @"%d", [dictionary containsKey:@"Mode"]);
2017-05-04 11:59:56.436101+0300 libtest[53154:4582741] 1
2017-05-04 11:59:56.436121+0300 libtest[53154:4582741] 0
- Method containsKeys: returns a boolean value that indicates whether the receiving dictionary contains objects for all keys from the specified list:
NSLog( @"%d", [dictionary containsKeys:@"System", @"Mode", nil]);
NSLog( @"%d", [dictionary containsKeys:@"Version", @"Verbose", nil]);
2017-05-04 12:52:16.196625+0300 libtest[53828:4614790] 0
2017-05-04 12:52:16.196652+0300 libtest[53828:4614790] 1
- Method containsKeysFromCollection: returns a YES value if the dictionary contains objects for all keys from the specified collection of any supported type:
NSLog( @"%d", [dictionary containsKeysFromCollection:@[ @"System", @"Version"]]);
NSLog( @"%d", [dictionary containsKeysFromCollection:@[ @"System", @"Mode"]]);
2017-05-05 11:04:01.100954+0300 libtest[55442:5260349] 1
2017-05-05 11:04:01.101005+0300 libtest[55442:5260349] 0
- Method containsAnyKey: returns a boolean value that indicates whether the receiving dictionary contains objects for at least one key from the specified list:
NSLog( @"%d", [dictionary containsAnyKey:@"Mode", @"Name", nil]);
NSLog( @"%d", [dictionary containsAnyKey:@"System", @"Mode", nil]);
2017-05-05 11:54:31.398716+0300 libtest[55890:5289879] 0
2017-05-05 11:54:31.398756+0300 libtest[55890:5289879] 1
- Method containsAnyKeyFromCollection: returns a boolean value that indicates whether the receiving dictionary contains objects for at least one key from the specified collection of any supported type:
NSLog( @"%d", [dictionary containsAnyKeyFromCollection:@[ @"System", @"Mode" ]]);
NSLog( @"%d", [dictionary containsAnyKeyFromCollection:@[ @"Console", @"Mode" ]]);
2017-05-05 12:04:52.615989+0300 libtest[56316:5298144] 1
2017-05-05 12:04:52.616039+0300 libtest[56316:5298144] 0
Enumerating dictionary objects
Property keyEnumerator returns an enumerator object that lets you access each key in the dictionary:
@property (nonatomic, readonly, assign) NSEnumerator *keyEnumerator;
[dictionary setBool:NO forKey:@"Debug"];
NSString *key;
while ( ( key = keys.nextObject)) {
NSLog( @"%@: %@", key, object);
}
2016-08-04 14:45:46.853 libtest[20808:3795367] Version: 10.11.6
2016-08-04 14:45:46.853 libtest[20808:3795367] System: MacOS
2016-08-04 14:45:46.853 libtest[20808:3795367] Debug: 0
Stacks
Stack is a collection of objects with two principal operations: push, which adds an object to the stack, and pop, which removes the most recently added object that was not yet removed. The order in which objects come off a stack gives rise to its alternative name, LIFO (for last in, first out). Additionally, a get (peek) operation may give access to the top object without modifying the stack.
Creating stacks
Class SCStack declares the following class methods for creating stack by using the data from the serialized files, data dictionaries, streams, and data objects:
+ (instancetype)stackWithCoder:(NSCoder *)coder;
+ (instancetype)stackWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)stackWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)stackWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)stackWithStream:(
SCStream *)stream;
+ (instancetype)stackWithFileStream:(NSString *)path;
+ (instancetype)stackWithData:(NSData *)data;
+ (instancetype)stackWithContentsOfFile:(NSString *)path;
+ (instancetype)stackWithContentsOfURL:(NSURL *)url;
+ (instancetype)stackWithContentsOfURLString:(NSString *)urlString;
For creating class instancess class SCStack implements the following class methods:
+ (instancetype)stackWithName:(NSString *)name;
+ (instancetype)stackWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)stackWithArray:(
SCArray *)array;
+ (instancetype)stackWithStack:(
SCStack *)stack;
+ (instancetype)stack;
- Class method stackWithName: returns the empty stack created by using the specified stack name:
2016-08-07 10:22:11.523 libtest[45278:4351145] Stack "Advanced Stack" count=0: (
)
- Class method stackWithObject: returns the stack created by using the specified existing object:
2016-08-07 10:23:02.282 libtest[45295:4351565] Stack count=1: (
"Object 00"
)
- Class method stackWithObjects: returns the stack created by using the specified nil terminated list of existing objects. Objects adds into the stack in the source list order.
2016-08-07 10:23:46.577 libtest[45311:4351840] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
- Class method stackWithCollection: returns the stack created by using the specified collection of any supported types. Order of objects defines by the source collection type.
2016-08-07 10:25:00.898 libtest[45330:4352207] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
- Class method stackWithArray: returns the new stack that contains objects from a given array:
2017-06-20 21:01:31.808185+0300 libtest[32358:11481916] Stack count=3: (
400,
200,
800
)
- Class method stackWithStack: returns the stack created by using the existing stack:
2016-08-07 10:25:59.898 libtest[45348:4352568] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
- Class method stack returns the empty unnamed stack created by using the default settings:
2016-08-07 10:26:45.940 libtest[45364:4352857] Stack count=0: (
)
Initializing stacks
Class SCStack implements the following initialization methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)initWithStack:(
SCStack *)stack;
- (instancetype)init;
- Method initWithName: initializes the stack using the specified stack name.
- Method initWithObject: initializes the stack using the specified existing object.
- Method initWithObjects: initializes the stack using the specified nil terminated list of existing objects. Objects adds into the stack in the source list order.
- Method initWithCollection: initializes the stack using the specified collection of any supported type. Order of objects defines by the source collection type.
- Method initWithArray: initializes a newly allocates stack that contains objects from a given array.
- Method initWithStack: initializes the stack using the existing stack.
- Method stack initializes the empty unnamed stack using the default settings.
Coping stacks
Class SCStack declares the following methods for stacks coping:
- Method setStack: removes the current settings and contents of the receiving stack and coping contents and settings from the specified existing stack:
NSLog( @"%@", stack);
NSLog( @"%@", source);
NSLog( @"%@", stack);
2017-03-30 11:55:47.856062 libtest[55427:2008281] Stack count=3: (
300,
200,
100
)
2017-03-30 11:55:47.856277 libtest[55427:2008281] Stack count=2: (
500,
400
)
2017-03-30 11:55:47.856515 libtest[55427:2008281] Stack count=2: (
500,
400
)
Comparing stacks
Class SCStack implements the following comparing methods:
- (BOOL)isEqualToStack:(
SCStack *)stack;
- Method isEqualToStack: returns a boolean value that indicates whether the contents of the receiving stack is equals to the contents of another given stack.
Deriving new stacks
Class SCStack declares the following methods for deriving new stacks:
- Method stackByPushingObject: returns a stack that contains objects from the receiving stack and a given object:
NSLog( @"%@", [stack stackByPushingObject:@600]);
2017-06-20 21:55:51.524664+0300 libtest[32890:11519697] Stack count=4: (
600,
800,
200,
400
)
- Method stackByPushingObjects: returns a new stack with objects from the receiving stack and objects from a given list:
NSLog( @"%@", [stack stackByPushingObjects:@600, @200, nil]);
2017-06-20 22:18:12.170789+0300 libtest[33242:11535259] Stack count=4: (
200,
600,
800,
400
)
- Method stackByPushingCollection: creates a stack that contains objects from the receiving stack and objects from a given collection of any supported type:
NSLog( @"%@", [stack stackByPushingCollection:@[ @100, @500]]);
2017-06-20 22:33:58.981348+0300 libtest[33600:11547823] Stack count=4: (
500,
100,
800,
600
)
- Methods stackByPushingObjectsFromArray: and stackByPushingArray: return a new stack with objects from the receiving stack and objects from a given array:
NSLog( @"%@", [stack stackByPushingArray:array]);
2017-06-20 23:00:38.666588+0300 libtest[34079:11568222] Stack count=4: (
300,
200,
800,
600
)
- Methods stackByPushingObjectsFromStack: and stackByPushingStack: create a new stack that contains objects from the receiving stack and objects from a given another stack:
NSLog( @"%@", [stack stackByPushingStack:source]);
2017-06-20 23:13:37.773127+0300 libtest[34548:11579411] Stack count=4: (
700,
500,
800,
600
)
Adding objects to stack
Class SCStack declares the following methods for adding object into the stack:
- (void)pushObjectsFromArray:(
SCArray *)array;
- (void)pushArray:(
SCArray *)array;
- (void)pushObjectsFromStack:(
SCStack *)stack;
- (void)pushStack:(
SCStack *)stack;
- Method pushObject: pushes into the receiving stack the specified object:
NSLog( @"%@", stack);
NSLog( @"%@", stack);
2016-08-08 13:59:53.763 libtest[47019:4678950] Stack count=2: (
"Object 01",
"Object 00"
)
2016-08-08 13:59:53.763 libtest[47019:4678950] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
- Method pushObjects: pushes into the receiving stack the objects from the specified nil terminated list. Order of objects within the stack is the same as in the source list.
NSLog( @"%@", stack);
NSLog( @"%@", stack);
2016-08-08 14:02:00.911 libtest[47048:4679594] Stack count=2: (
"Object 01",
"Object 00"
)
2016-08-08 14:02:00.911 libtest[47048:4679594] Stack count=4: (
"Object 14",
"Object 12",
"Object 01",
"Object 00"
)
- Method pushCollection: pushes into the receiving stack the objects from the specified collection of any supported type:
NSLog( @"%@", stack);
NSLog( @"%@", stack);
2016-08-08 14:08:10.340 libtest[47111:4681475] Stack count=2: (
"Object 01",
"Object 00"
)
2016-08-08 14:08:10.340 libtest[47111:4681475] Stack count=4: (
"Object 22",
"Object 21",
"Object 01",
"Object 00"
)
- Methods pushObjectsFromArray: and pushArray: push into the receiving stack objects from a given array:
2017-06-20 23:44:48.382432+0300 libtest[34996:11603056] Stack count=4: (
400,
200,
800,
600
)
- Methods pushObjectsFromStack: and pushStack: push into the receiving stack objects from a given another stack:
2017-06-21 00:03:45.714208+0300 libtest[35367:11617600] Stack count=4: (
500,
100,
800,
600
)
Poping objects from stack
Class SCStack implements the following methods for poping objects from the stack:
- (void)pop;
- (id)popObject;
- Method pop removes the object from the top of the receiving stack without returning the poped object:
NSLog( @"%@", stack);
NSLog( @"%@", stack);
2016-08-08 15:28:01.178 libtest[47442:4709867] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
2016-08-08 15:28:01.178 libtest[47442:4709867] Stack count=2: (
"Object 01",
"Object 00"
)
- Method popObject returns and removes the object from the top of the receiving stack. If the receiving stack is empty, method returns the nil pointer.
NSLog( @"%@", stack);
NSLog( @"%@", [stack popObject]);
NSLog( @"%@", stack);
2016-08-08 15:29:48.354 libtest[47465:4710481] Stack count=3: (
"Object 02",
"Object 01",
"Object 00"
)
2016-08-08 15:29:48.354 libtest[47465:4710481] Object 02
2016-08-08 15:29:48.354 libtest[47465:4710481] Stack count=2: (
"Object 01",
"Object 00"
)
Removing objects from stack
Additionally to the method pop class SCStackimplements the method removeTopObject, which is a synomym of method pop. This method is designed for logical compatibility with the other collection classes and categories.
Coping stack objects
Method duplicateTopObject duplicates the object from the top of the receiving stack:
- (void)duplicateTopObject;
NSLog( @"%@", stack);
NSLog( @"%@", stack);
2016-08-08 16:13:06.619 libtest[47645:4720857] Stack count=2: (
"Object 01",
"Object 00"
)
2016-08-08 16:13:06.619 libtest[47645:4720857] Stack count=3: (
"Object 01",
"Object 01",
"Object 00"
)
Stack objects access
Stacks allow direct access only to the last added object (top object). Class SCStack implements the following properties for direct access to stack top object:
@property (nonatomic, readonly, assign) id topObject;
- Property topObject returns the object from the top of the receiving stack without deleting or nil if the stack is empty:
NSLog( @"%@", [stack topObject]);
2016-08-07 13:58:44.040 libtest[45607:4375547] Object 02
Queues
Queue is a collection in which the objects in collection are kept in order and the principal (or only) operations on the collection are the addition of objects to the rear terminal position, known as enqueue, and removal of objects from the front terminal position, known as desqueue.
This makes the queue a First-In-First-Out (FIFO) collection. In a queue, the first object added to the queue will be the first one to be removed. This is equivalnet to the requirement that once a new object is added, all objects that were added before have to be removed before the new object can be removed.
Often a peek, front or get operation is also enetered, returning the value of the front object without dequeuing it. A queue is an example of a abstractly a sequantial collection.
Library supports queue by the class SCQueue, which is a child of the class SCCollection. For adding objects to the queue class instances using the methods from the parent class SCCollection. This inherited methods are described in the Programming Guide section Adding objects.//###
Creating queues
For creating queues by using the data from the serialzied files, data dictionaries, streams and data objects class SCQueue declares the following class methods:
+ (instancetype)queueWithCoder:(NSCoder *)coder;
+ (instancetype)queueWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)queueWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)queueWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)queueWithStream:(
SCStream *)stream;
+ (instancetype)queueWithFileStream:(NSString *)path;
+ (instancetype)queueWithData:(NSData *)data;
+ (instancetype)queueWithContentsOfFile:(NSString *)path;
+ (instancetype)queueWithContentsOfURL:(NSURL *)url;
+ (instancetype)queueWithContentsOfURLString:(NSString *)urlString;
Class SCQueue implements the following methods for creating class instances:
+ (instancetype)queueWithName:(NSString *)name;
+ (instancetype)queueWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)queueWithArray:(
SCArray *)array;
+ (instancetype)queueWithQueue:(
SCQueue *)queue;
+ (instancetype)queue;
- Class method queueWithName: returns the empty queue created by using the specified queue name:
2016-08-08 16:54:15.731 libtest[47909:4739817] Queue "Messages Queue" count=0:
)
- Class method queueWithObject: returns the queue created by using the specified existing object:
2016-08-08 16:54:50.815 libtest[47924:4740064] Queue count=1: (
"Object 00"
)
- Class method queueWithObjects: returns the queue created by using the specified nil terminated list of existing objects:
2016-08-08 16:56:01.790 libtest[47948:4740963] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
- Class method queueWithCollection: returns the queue created by using the objects from the specified collection of any supported type:
2016-08-08 16:56:56.096 libtest[47967:4741510] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
- Class method queueWithArray: creates a new queue with objects from a given array:
2017-06-21 00:31:16.742717+0300 libtest[35741:11638305] Queue count=2: (
800,
200
)
- Class method queueWithQueue: returns the queue created by using the specified existing queue:
2016-08-08 16:57:55.687 libtest[47987:4742229] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
- Class method queue returns the empty unnamed queue created by using the default settings:
2016-08-08 16:58:41.636 libtest[48005:4742776] Queue count=0:
)
Initializing queues
Class SCQueue declares the following initialization methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)initWithQueue:(
SCQueue *)queue;
- (instancetype)init;
- Method initWithName: initializes the queue using the specified queue name.
- Method initWithObject: initializes the queue using the specified existing object.
- Method initWithObjects: initializes the queue using the specified nil terminated list of existing objects.
- Method initWithCollection: initializes the queue using the objects from the specified collection of any supported type.
- Method initWithArray: initializes a queue with objects from a given array.
- Method initWithQueue: initializes the queue using the specified existing queue.
- Method init initializes the empty unnamed queue using the default settings.
Coping queues
Class SCQueue declares the following methods for queues coping:
- Method setQueue: removes the current settings and contents of the receiving queue and coping contents and settings from the specified existing queue:
NSLog( @"%@", queue);
NSLog( @"%@", source);
NSLog( @"%@", queue);
2017-03-30 14:01:59.326567 libtest[59102:2087306] Queue count=3: (
100,
200,
300
)
2017-03-30 14:01:59.326707 libtest[59102:2087306] Queue count=2: (
400,
500
)
2017-03-30 14:01:59.326899 libtest[59102:2087306] Queue count=2: (
400,
500
)
Comparing queues
Class SCQueue implements the following comparing methods:
- (BOOL)isEqualToQueue:(
SCQueue *)queue;
- Method isEqualToQueue: returns a boolean value that indicates whether the contents of the receiving queue is equals to the contents of another given queue.
Deriving New Queues
Class SCQueue implements the following methods for deriving new queues by using existing queues:
- Method queueByAddingObject: returns a new queue that contains objects from the receiving queue and a given object:
NSLog( @"%@", [queue queueByAddingObject:@400]);
2017-06-21 01:26:02.345845+0300 libtest[37111:11680692] Queue count=3: (
800,
200,
400
)
- Method queueByAddingObjects: creates a queue that contains objects from the receiving queue and objects from a given list:
NSLog( @"%@", [queue queueByAddingObjects:@100, @500, nil]);
2017-06-21 01:51:41.603834+0300 libtest[37586:11700535] Queue count=4: (
800,
200,
100,
500
)
- Method queueByAddingCollection: returns a queue that contains objects from the receiving queue and objects from a given collection of any supported type:
NSLog( @"%@", [queue queueByAddingCollection:@[ @600, @400]]);
2017-06-21 02:06:08.085238+0300 libtest[37937:11711712] Queue count=4: (
800,
200,
600,
400
)
- Methods queueByAddingObjectsFromArray: and queueByAddingArray: create a queue that contains objects from the receiving queue and a given array:
NSLog( @"%@", [queue queueByAddingArray:array]);
2017-06-21 02:18:28.984392+0300 libtest[38277:11721659] Queue count=4: (
800,
200,
700,
300
)
- Methods queueByAddingObjectsFromQueue: and queueByAddingQueue: return a queue that contains objects from the receiving queue and a given another queue:
NSLog( @"%@", [queue queueByAddingQueue:source]);
2017-06-21 02:28:13.549075+0300 libtest[38619:11730409] Queue count=4: (
800,
200,
500,
900
)
Adding objects
Class SCQueue implements the following methods for adding objects:
- (void)addObjectsFromArray:(
SCArray *)array;
- (void)addObjectsFromQueue:(
SCQueue *)queue;
- Methods addObjectsFromArray: and addArray: (SCQueue) "addArray:" add into the receiving queue objects from a given array:
2017-06-21 02:55:50.998484+0300 libtest[39101:11752419] Queue count=4: (
800,
200,
100,
500
)
- Methods addObjectsFromQueue: and addQueue: (SCQueue) "addQueue" add into the receiving queue objects from a given another queue:
2017-06-21 03:06:26.851383+0300 libtest[39441:11761564] Queue count=4: (
800,
200,
600,
400
)
Getting queue objects
Method getObject removes first object from the queue and returns this object. If the queue is empty, method returns the nil pointer.
NSLog( @"%@", queue);
NSLog( @"=====");
id object;
while ( ( object = [queue getObject])) NSLog( @"=> %@", object);
NSLog( @"=====");
NSLog( @"%@", queue);
2016-08-08 17:01:45.115 libtest[48091:4744307] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
2016-08-08 17:01:45.115 libtest[48091:4744307] =====
2016-08-08 17:01:45.115 libtest[48091:4744307] => Object 00
2016-08-08 17:01:45.115 libtest[48091:4744307] => Object 01
2016-08-08 17:01:45.116 libtest[48091:4744307] => Object 02
2016-08-08 17:01:45.116 libtest[48091:4744307] =====
2016-08-08 17:01:45.116 libtest[48091:4744307] Queue count=0:
)
Removing objects from queue
Class SCQueue implements the following methods for removing objects from the queue:
- (void)removeFirstObject;
- (void)removeLastObject;
- Method removeFirstObject removes the first object from the receiving queue:
NSLog( @"%@", queue);
NSLog( @"%@", queue);
2016-08-08 17:02:37.092 libtest[48110:4744887] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
2016-08-08 17:02:37.093 libtest[48110:4744887] Queue count=2: (
"Object 01",
"Object 02"
)
- Method removeLastObject removes the last object from the receiving queue:
NSLog( @"%@", queue);
NSLog( @"%@", queue);
2016-08-08 17:03:27.404 libtest[48128:4745607] Queue count=3: (
"Object 00",
"Object 01",
"Object 02"
)
2016-08-08 17:03:27.404 libtest[48128:4745607] Queue count=2: (
"Object 00",
"Object 01"
)
Coping queue objects
Class SCQueue implements the following methods for coping queue objects:
- (void)duplicateFirstObject;
- (void)duplicateLastObject;
- Method duplicateFirstObject duplicates the first object within the receiving queue:
NSLog( @"%@", queue);
NSLog( @"%@", queue);
2016-08-08 17:04:19.267 libtest[48146:4746333] Queue count=2: (
"Object 00",
"Object 01"
)
2016-08-08 17:04:19.267 libtest[48146:4746333] Queue count=3: (
"Object 00",
"Object 00",
"Object 01"
)
- Method duplicateLastObject duplicates the last object within the receiving queue:
NSLog( @"%@", queue);
NSLog( @"%@", queue);
2016-08-08 17:05:14.758 libtest[48165:4747135] Queue count=2: (
"Object 00",
"Object 01"
)
2016-08-08 17:05:14.758 libtest[48165:4747135] Queue count=3: (
"Object 00",
"Object 01",
"Object 01"
)
Queue objects access
For accessing to the queue objects class SCQueue implements the following properties:
@property (nonatomic, readonly, assign) id firstObject;
- Property firstObject returns the first object from the receiving queue:
NSLog( @"%@", [queue firstObject]);
2016-08-08 16:59:36.435 libtest[48023:4743141] Object 00
Unidirectional lists
Unidirectional list is a collection, which contains object nodes which have a data field as a "next" field, which points to the next object node in line of object nodes. Operations that can be performed on unidirectional lists include insertion, deletion and travesal.
New objects can be added into the end of unidirectional list. For access to the object you must process the all previous objects from the begin of the list. Unidirectional list supports only one direction of objects processing - from previous to the next object.
Unidirectional list allows direct access only to the first object and to the current object.
Creating lists
Class SCUnidirectionalList inherits from the class SCList the following methods for creating unidirectional lists by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)listWithCoder:(NSCoder *)coder;
+ (instancetype)listWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)listWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)listWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)listWithStream:(
SCStream *)stream;
+ (instancetype)listWithFileStream:(NSString *)path;
+ (instancetype)listWithData:(NSData *)data;
+ (instancetype)listWithContentsOfFile:(NSString *)path;
+ (instancetype)listWithContentsOfURL:(NSURL *)url;
+ (instancetype)listWithContentsOfURLString:(NSString *)urlString;
Class SCUnidirectionalList inherits from the class SCList the following methods for creating class instances:
+ (instancetype)listWithName:(NSString *)name;
+ (instancetype)listWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)listWithArray:(
SCArray *)array;
+ (instancetype)listWithList:(
SCList *)list;
+ (instancetype)list;
- Class method listWithName: returns the empty list created by using the specified name:
2016-08-17 16:48:55.745 libtest[1257:72812] List "Users List" count=0:
)
Current object: "(null)"
- Class method listWithObject: returns the list created by using the specified existing object. Current object pointer sets to the specified object.
2016-08-17 16:49:29.233 libtest[1272:73184] List count=1: (
"00"
)
Current object: "00"
- Class method listWithObjects: returns the list created by using the specified list of existing objects. Current object pointer sets to the first object from the list.
2016-08-17 16:50:24.808 libtest[1289:73611] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
- Class method listWithCollection: returns the list created by using the specified existing collection of any supported type. Objects order defined by ths source collection type. Current object pointer sets to the collection first object.
2016-08-17 16:51:42.754 libtest[1321:74808] List count=3: (
"00",
"02",
"04"
)
Current object: "00"
- Class method listWithArray: creates an unidirectional list that contains objects from a given array:
2017-06-21 04:25:03.918416+0300 libtest[43997:11836422] List count=2: (
400,
800
)
Current object:400
- Class method listWithList: returns the list created by using the existing list:
2016-08-17 17:03:20.879 libtest[1482:79592] List count=3: (
"01",
"03",
"05"
)
Current object: "01"
- Class method list returns the empty unnamed unidirectional list:
2016-08-17 17:04:07.385 libtest[1502:80085] List count=0:
)
Current object: "(null)"
Initializing lists
Class SCUnidirectionalList inherits from the class SCList the following initializing methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)initWithList:(
SCList *)list;
- (instancetype)init;
- Method initWithName: initializes the list using the specified name.
- Method initWithObject: initializes the list using the specified existing object.
- Method initWithObjects: initializes the list using the specified list of existing objects.
- Method initWithCollection: initializes the list using the specified existing collection of any supported type.
- Method initWithArray: initializes an unidirectional list that contains objects from a given array.
- Method initWithList: initializes the list using the existing list.
- Method list initializes the empty unnamed list using the default settings.
List objects access
Class SCUnidirectionalList inherits from the class SCList the following properties for access to the list objects:
@property (nonatomic, readonly, assign) id currentObject;
@property (nonatomic, readonly, assign) id firstObject;
- Property currentObject returns the current object from the receiving list. If the list is empty, returns the nil pointer.
NSLog( @"%@", [list currentObject]);
2016-08-17 17:08:08.890 libtest[1546:81133] 00
- Property firstObject returns the first object from the receiving list. If the list is empty, then returns the nil pointer.
NSLog( @"%@", [list firstObject]);
2016-08-17 17:09:39.822 libtest[1569:81681] 00
Coping lists
Class SCUnidirectionalList inherits from the SCList the following methods for lists coping:
- (void)setList:(
SCList *)list;
- Method setList: removes the current settings and contents of the receiving list and coping contents and settings from the specified existing list:
NSLog( @"%@", list);
NSLog( @"%@", source);
NSLog( @"%@", list);
2017-03-30 16:27:39.024150 libtest[64020:2189070] List count=3: (
100,
200,
300
)
Current object:100
2017-03-30 16:27:39.024301 libtest[64020:2189070] List count=2: (
400,
500
)
Current object:400
2017-03-30 16:27:39.024467 libtest[64020:2189070] List count=2: (
400,
500
)
Current object:400
Comparing lists
Class SCUnidirectionalList inherits from the class SCList the following comparing methods:
- (BOOL)isEqualToList:(
SCList *)list;
- Method isEqualToList: returns a boolean value that indicates whether the contents of the receiving list is equals to the contents of another given list.
Deriving new lists
Class SCUnidirectionalList inherits from the class SCList the following methods for deriving new lists by using existing lists:
- (instancetype)listByAddingCollection:(
id<
SCCollection>)collection;
- (instancetype)listByAddingObjectsFromArray:(
SCArray *)array;
- (instancetype)listByAddingArray:(
SCArray *)array;
- (instancetype)listByAddingObjectsFromList:(
SCList *)list;
- (instancetype)listByAddingList:(
SCList *)list;
- Method listByAddingObject: returns a new list that contains objects from the receiving list and a given object:
NSLog( @"%@", [list listByAddingObject:@100]);
2017-06-21 15:43:43.408173+0300 libtest[47666:12302863] List count=3: (
400,
600,
100
)
Current object:400
- Method listByAddingObjects: creates a new list that contains objects from the receiving list and objects from a given list:
NSLog( @"%@", [list listByAddingObjects:@100, @500, nil]);
2017-06-21 15:59:47.570787+0300 libtest[48095:12319578] List count=4: (
400,
600,
100,
500
)
Current object:400
- Method listByAddingCollection: returns a list that contains objects from the receiving list and a given collection of any supported type:
NSLog( @"%@", [list listByAddingCollection:@[ @300, @700]]);
2017-06-21 16:08:46.336686+0300 libtest[48447:12327747] List count=4: (
400,
600,
300,
700
)
Current object:400
- Methods listByAddingObjectsFromArray: and listByAddingArray: return a new list that contains objects from the receiving list and a given array:
NSLog( @"%@", [list listByAddingArray:array]);
2017-06-21 16:20:59.586020+0300 libtest[48821:12339479] List count=4: (
400,
600,
200,
800
)
Current object:400
- Methods listByAddingObjectsFromList: and listByAddingList: create a list that contains objects from the receiving list and a given another list:
NSLog( @"%@", [list listByAddingList:source]);
2017-06-21 16:32:06.555094+0300 libtest[49181:12349092] List count=4: (
400,
600,
300,
100
)
Current object:400
Controlling lists
Class SCUnidirectionalList inherits from the class SCList the following control methods:
Method nextObject shifts the current object pointer to the next object in the receiving list and return a pointer to the next object. If the cuurent object is a last list object, then method does not change the current object.
NSLog( @"%@", [list currentObject]);
NSLog( @"%@", [list nextObject]);
NSLog( @"%@", [list currentObject]);
2016-08-17 17:30:22.533 libtest[1619:86864] 00
2016-08-17 17:30:22.533 libtest[1619:86864] 01
2016-08-17 17:30:22.533 libtest[1619:86864] 01
Adding objects to list
Class SCUnidirectionalList inherits from the class SCList the following methods for inserting objects before the current object:
- (void)insertCurrentCollection:(
id<
SCCollection>)collection;
- Method insertCurrentObject: inserts the specified object before current object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:37:10.634 libtest[1687:88990] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 17:37:10.635 libtest[1687:88990] List count=4: (
"00",
"03",
"01",
"02"
)
Current object: "03"
- Method insertCurrentObjects: inserts into the receiving list before current object the objects from the specified objects list. Current object pointer sets to the last object from the specified list.
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:38:58.348 libtest[1712:89680] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 17:38:58.348 libtest[1712:89680] List count=5: (
"00",
"04",
"03",
"01",
"02"
)
Current object: "04"
- Method insertCurrentCollection: inserts into the receiving list before current object the objects from the specified collection of any supported type. Current object pointer sets to the last added object.
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:40:19.814 libtest[1734:90084] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 17:40:19.815 libtest[1734:90084] List count=5: (
"00",
"06",
"05",
"01",
"02"
)
Current object: "06"
Class SCUnidirectionalList inherits from the class SCList the following methods for inserting objects into the begin of the list:
- Method insertFirstObject: inserts the specified object before the first object into the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:47:38.927 libtest[1814:92616] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 17:47:38.927 libtest[1814:92616] List count=4: (
"04",
"00",
"01",
"02"
)
Current object: "00"
- Method insertFirstObjects: inserts into the receiving list before first object the objects from the specified objects list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:49:19.917 libtest[1834:93303] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 17:49:19.917 libtest[1834:93303] List count=5: (
"06",
"05",
"00",
"01",
"02"
)
Current object: "00"
- Method insertFirstCollection: inserts into the receiving list before first object the objects from the specified collection of any supported type:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:50:48.104 libtest[1857:93743] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 17:50:48.105 libtest[1857:93743] List count=5: (
"08",
"07",
"00",
"01",
"02"
)
Current object: "00"
Also class SCUnidirectionalList inherits from the class SCList the following methods for adding objects:
- (void)addObjectsFromArray:(
SCArray *)array;
- (void)addObjectsFromList:(SList *)list;
- (void)addList:(SList *)list;
- Methods addObjectsFromArray: and addArray: adds into the receiving list objects from a given array:
2017-06-21 16:47:10.268393+0300 libtest[49828:12362966] List count=4: (
400,
600,
100,
500
)
Current object:400
- Methods addObjectsFromList: and addList: adds into the receiving list objects from a given another list:
2017-06-21 16:56:05.833368+0300 libtest[50202:12373259] List count=4: (
400,
600,
300,
700
)
Current object:400
Removing objects from list
For removing objects class SCUnidirectionalList inherits the following methods:
- (void)removeCurrentObject;
- (void)removeFirstObject;
- Method removeCurrentObject removes the current object from the receiving list and moves the current pointer object to the next object. If the removed object is a last object of the list, then current object pointer sets to the previous object.
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:54:09.801 libtest[1897:94758] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 17:54:09.801 libtest[1897:94758] List count=2: (
"00",
"02"
)
Current object: "02"
- Method removeFirstObject removes the first object from the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 17:55:02.735 libtest[1913:95019] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 17:55:02.735 libtest[1913:95019] List count=2: (
"01",
"02"
)
Current object: "01"
Replacing list objects
Class SCUnidirectionalList ibherits from the class SCList the following methods for replacing objects:
- Method replaceCurrentObjectWithObject: replaces the first object of receiving collection with the specified object:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 18:00:11.420 libtest[1960:96364] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 18:00:11.420 libtest[1960:96364] List count=3: (
"00",
"==",
"02"
)
Current object: "=="
- Method replaceFirstObjectWithObject: replaces the first object of receiving collection with the specified object:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 18:02:52.234 libtest[1992:97171] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 18:02:52.234 libtest[1992:97171] List count=3: (
"==",
"01",
"02"
)
Current object: "01"
Coping list objects
Class SCUnidirectionalList inherits from the class SCList the following objects removing methods:
- (void)duplicateCurrentObject;
- (void)duplicateFirstObject;
- Method duplicateCurrentObject duplicates the current object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 18:19:10.908 libtest[2046:103631] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 18:19:10.908 libtest[2046:103631] List count=4: (
"00",
"01",
"01",
"02"
)
Current object: "01"
- Methods duplicateFirstObject duplicates the first object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 18:20:06.287 libtest[2064:103904] List count=3: (
"00",
"01",
"02"
)
Current object: "01"
2016-08-17 18:20:06.287 libtest[2064:103904] List count=4: (
"00",
"00",
"01",
"02"
)
Current object: "01"
Bidirectional lists
In the bidirectional list each object node contains, besides the next-node link, a second link field pointing to the previous object node in the sequence. The two links may be called forwards and backwards, or next and prev,
Class SCBidirectionalList provides changing the current object pointer in two directions - from current object to the next object and from current to the previous object. Additionally, class SCBidirectionalList declares the methods for accessing to the list last object.
List objects access
Class SCBidirectionalList implements the following properties for list objects accessing:
@property (nonatomic, readonly, assign) id lastObject;
Property lastObject returns the last object from the receiving list. If the list is empty, then method returns the nil pointer.
Controlling list
Class SCBidirectionalList implements the following methods for list controlling:
Method previousObject shifts the current object pointer to the previous object in the receiving list and return a pointer to the previous object. If the current object is a first object, then the method does not changes the current object and returns a nil pointer.
do { } while ( [list nextObject]);
do {
NSLog( @"%@", [list currentObject]);
} while ( [list previousObject]);
2016-08-17 21:07:59.306 libtest[3279:182111] 02
2016-08-17 21:07:59.306 libtest[3279:182111] 01
2016-08-17 21:07:59.306 libtest[3279:182111] 00
Adding objects to list
Class SCBidirectionalList implements the following methods for adding objects into the bidirectional list:
- Method insertLastObject: inserts the specified object before the last object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:10:08.437 libtest[3308:182901] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:10:08.437 libtest[3308:182901] List count=4: (
"00",
"01",
"==",
"02"
)
Current object: "00"
- Method insertLastObjects: inserts the specified objects before the last object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:11:11.681 libtest[3326:183211] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:11:11.681 libtest[3326:183211] List count=5: (
"00",
"01",
"==",
"--",
"02"
)
Current object: "00"
- Method insertLastCollection: inserts the objects from the specified collection of any supported type before the last object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:12:22.054 libtest[3347:183566] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:12:22.055 libtest[3347:183566] List count=5: (
"00",
"01",
"XX",
"ZZ",
"02"
)
Current object: "00"
Removing objects from list
Class SCBidirectionalList implements the following methods for removing objects:
- (void)removeLastObject;
Method removeLastObject emoves the last objects of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:15:38.556 libtest[3382:184602] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:15:38.557 libtest[3382:184602] List count=2: (
"00",
"01"
)
Current object: "00"
Replacing list objects
For replacing objects class SCBidirectionalList implements the following methods:
Method replaceLastObjectWithObject: replaces the last object of receiving collection with the specified object:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:20:48.686 libtest[3422:186097] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:20:48.686 libtest[3422:186097] List count=3: (
"00",
"01",
"=="
)
Current object: "00"
Coping list objects
Class SCBidirectionalList implements the following methods for coping objects within the list:
- (void)duplicateLastObject;
Method duplicateLastObject duplicates the last object of the receiving list:
NSLog( @"%@", list);
NSLog( @"%@", list);
2016-08-17 21:22:27.623 libtest[3448:186559] List count=3: (
"00",
"01",
"02"
)
Current object: "00"
2016-08-17 21:22:27.623 libtest[3448:186559] List count=4: (
"00",
"01",
"02",
"02"
)
Current object: "00"
Sorters
Collections, which support the direct access to the objects (arrays and ordered sets), also support the objects sorting. But the collections does not have the algorithms for sorting own objects. This approach related to the fact that it is now known many such algorithms, and can be developed in the future, new, and there is no sense to spend time and resources for the implementation of the library all of them. But at the same time we need to be able to add new sorting algorithms.
That is why the implementation of sorting algorithms made in separate classes called sorters. Instances of this classes perform all data sorting.
Protocol and class SCSorter
Any sorter class must comply with the SCSorter protocol, which declares the following mandatory methods:
- (void)descendingSortText:(
SCStrings *)text;
The last two methods does not work with collections. They work with strings lists, texts and text files, which described in the Programming Guide section String lists, texts and text files. This methods have been developed beacause sorting of text data is different from the sorting of regular data.
Class SCSorter implements all methods of protocol SCSorter, but these methods are abstract and must be reimplemented in all child classes. The main purpose of the class SCSorter is grouping of library supported real sorting algorithms. Now in the library implement the following sorting algorithms as a children of class SCSorter:
These classes describe in the next sections of Programming Guide.
Sorter SCBubbleSorter
Class SCBubbleSorter implements one of the simplest and well-known sorting algorithms. This algorithm is known as "bubble" or "bubble sorting". Although the algorithm is simple, it is too slow. Class SCBubbleSorter implements only one class method for creating the class instances:
Sorter SCFastSorter
Class SCFastSorter implements the well-known sorting algorithm, which is known as a "fast sorting". This sorter is a default library sorter. Class SCFastSorter implements only one class method for creating the class instances:
Collections and standard classes
SCL implements a partial compatibility between collections and Objective-C standard classes. This compatibility can be devided into the following groups:
- Using class instances as the arguments. Some methods of library classes can accept instances as an arguments. For example, you can create the queue with using objects from the existing foundation (standard) array or set:
NSArray *source = [NSArray arrayWithObjects:@"000", @"002", @"003", nil];
NSLog( @"%@", array);
2016-08-17 23:50:45.767 libtest[4470:259649] Array count=3: (
"000",
"002",
"003"
)
- Converting to instances of the standard classes. Many of standard and third-party libraries does not accept instances of out classes as a method arguments, but allow using the standard classes instances as an arguments. Therefore, out classes support methods for converting collections into the standard classes instances. For more details see the Programming Guide section Converting collections. Here we present a simple example of this convertion:
2016-08-17 23:59:26.107 libtest[4538:263509] (
000,
002,
003
)
- Expanding standard classes functionality. Several methods of library classes are implemented in the standard classes by using the categories. Made it that the programmers had a choice between the use of library classes and standard classes. See the Programming Guide section Standard classes extentions for more details.
All library classes have some common opposed to the standard classes:
- library classes support named and unnamed collections, but the standard classes support only unnamed collections:
NSLog(
@"%@", array.
name);
array.
name =
@"Special Array";
NSLog(
@"%@", array.
name);
2016-08-18 00:30:18.210 libtest[4688:276318] Sample Array
2016-08-18 00:30:18.210 libtest[4688:276318] Special Array
- library classes support read only flag, which determines the possibility of changes in the collections. This flag allows to control the access to the collections. If you can change the read only collection, then error SCL-20043 is occurs.
Collection error processing
When using the collections a variety of errors may occur. In this section, we describe the process of error handling by the collections unit.
If the collection detects the occurrence of an error, it is first of all checks the delegate object (described in the Programming Guide section Delegation protocol SCCollectionDelegate). If delegate object is not assigned, the collection is performed the exception SCCollectionException throwing.
If the delegate object is assigned, then collection calls his method collection:didDetectException:. If the method returns value YES, then collection ignores the error that occurred. Otherwise, it throws a class SCCollectionException instance.
For details on specific collection errors see Collection errors. Now we describe only the primary collection errors:
- Error SCL-20042 occurs when the collection method detects non-collection class instance instead pointer to the collection of any supported type.
- Error SCL-20043 occurs then the read only collection detects attempt of changing its contents. This functionality allows does not devide functions between multiple classes (such as standard classes NSArray and NSMutableArray).
- Error SCL-20046 occurs if the collection detects the object without compliance of the protocol SCCollectioning. We want to draw attention to the fact that the simple addition of such objects does not result to the immediate generation of this error. It generated only when the collection unit attempts to call methods of the procotol SCCollectioning, for example when attempting to copy the object or during collection sorting.
Delegation protocol SCCollectionDelegate
In order to responding to various events in the collections programmer can assign a delegate object by using property delegate.
As a delegate object you can using instance of the class, which compiances to the protocol SCCollectionDelegate. Also may be used the instance of any child of class SCCollectionDelegate (this class is implements all methods of SCCollectionDelegate protocol).
Now we examine the different methods of protocol and describe events, at approach of which they are called:
Collection error processing
Protocols SCCollectionDelegate declares the following methods for collection error handling:
- Method collection:didDetectException: is called when an error is detected during the working with collections. If method returns the value YES, then collection ignores the detected error, otherwise collection throws the corresponding exception. Therefore, the library gives programmers the ability to control the error handling process.
Object adding events
Protocol SCCollectionDelegate declares the following methods for processing adding objects events:
- (void)collection:(
SCCollection *)collection willAddObject:(
id)object;
- (void)collection:(
SCCollection *)collection willInsertObject:(
id)object atIndex:(
SCIndex)index;
- (void)collection:(
SCCollection *)collection willSetObject:(
id)object forKey:(NSString *)key;
- (void)collection:(
SCCollection *)collection willSetValue:(
id)value forKey:(NSString *)key;
- (void)collection:(
SCCollection *)collection didFinishAddingObject:(
id)object;
- (void)collection:(
SCCollection *)collection didFinishInsertingObject:(
id)object atIndex:(
SCIndex)index;
- (void)collection:(
SCCollection *)collection didFinishSettingObject:(
id)object forKey:(NSString *)key;
- (void)collection:(
SCCollection *)collection didFinishSettingValue:(
id)value forKey:(NSString *)key;
Object removing events
For processing the object removing events protocol SCCollectionDelegate declares the following methods:
- (void)willRemoveAllObjectsFromCollection:(
SCCollection *)collection;
- (void)collection:(
SCCollection *)collection willRemoveObjectsOfClassName:(NSString *)name;
- (void)collection:(
SCCollection *)collection willRemoveObject:(
id)object;
- (void)collection:(
SCCollection *)collection willRemoveObjectForKey:(NSString *)key;
- (void)didFinishRemovingAllObjectsFromCollection:(
SCCollection *)collection;
- (void)collection:(
SCCollection *)collection didFinishRemovingObjectsOfClassName:(NSString *)name;
- (void)collection:(
SCCollection *)collection didFinishRemovingObject:(
id)object;
- (void)collection:(
SCCollection *)collection didFinishRemovingObjectForKey:(NSString *)key;
Object processing events
Protocol SCCollectionDelegate declares the following methods for collection objects processing:
- (void)processObject:(
id)object collection:(
SCCollection *)collection;
Data sorting events
When the collection sorts its contents, the following methods of protocol SCCollectionDelegate are called for the delegate object:
- (void)collection:(
SCCollection *)collection willSortAscending:(BOOL)ascending sorter:(
id<
SCSorter>)sorter;
- (void)collection:(
SCCollection *)collection didFinishSortingAscending:(BOOL)ascending sorter:(
id<
SCSorter>)sorter;
Object replacing events
Protocol SCCollectionDelegate declares the following methods for object replacing events processing:
- (void)collection:(
SCCollection *)collection willReplaceObjectAtIndex:(
SCIndex)index withObject:(
id)object;
- (void)collection:(
SCCollection *)collection willReplaceObjectsInRange:(NSRange)range withCollection:(
id)source;
- (void)collection:(
SCCollection *)collection willReplaceObject:(
id)replaced withObject:(
id)object;
- (void)collection:(
SCCollection *)collection didFinishReplacingObjectAtIndex:(
SCIndex)index withObject:(
id)object;
- (void)collection:(
SCCollection *)collection didFinishReplacingObjectsInRange:(NSRange)range withCollection:(
id)source;
- (void)collection:(
SCCollection *)collection didFinishReplacingObject:(
id)replaced withObject:(
id)object;
Coping and moving object events
Coping and moving object events are processed by calling the following methods of protocol SCCollectionDelegate:
withObjectAtIndex:(
SCIndex)destination;
withObjectAtIndex:(
SCIndex)destination;
String lists, texts and text files
Samond Classes Library includes the group of classes for processing text information:
The following diagram displays the text classes hierarchy.
- Class SCStrings implements the sample string lists with methods for strings processing. This is a based class for other text processing classes.
- Class SCUniqueStrings extends the class SCStrings functionality by implements the special type of strings lists - unique strings list, which does not contains the duplicated strings. Unique strings list can contains only unique strings.
- Class SCText adds into the strings list the support for text blocks processing. Text processing is a functionality, which upgrades the sample string list to the text - orginized strings data.
- Class SCTextFile supports the text read and write operations.
Separate chapters are also described the additional text components:
String lists
String list is an aggregate of text strings, which are combined into the single instance of class SCStrings. Additionally to storing strings, string list supports basic methods for string processing - adding, removing, changing, moving within the list and so on.
Class SCStrings is a based (parent) class for all other text processing classes. Each child class extends the class SCStrings functionality. This Programming Guide chapter describes the class SCStrings. Other text processing classes are described in the next sections of Programming Guide.
Creating lists
For creating string lists by using the data from the serialized files, data dictionaries, streams and data objects class SCStrings declares the following class methods:
+ (instancetype)stringsWithCoder:(NSCoder *)coder;
+ (instancetype)stringsWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)stringsWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)stringsWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)stringsWithStream:(
SCStream *)stream;
+ (instancetype)stringsWithFileStream:(NSString *)path;
+ (instancetype)stringsWithData:(NSData *)data;
+ (instancetype)stringsWithContentsOfFile:(NSString *)path;
+ (instancetype)stringsWithContentsOfURL:(NSURL *)url;
+ (instancetype)stringsWithContentsOfURLString:(NSString *)urlString;
Class SCStrings implements the following class method for class instances creating:
+ (instancetype)stringsWithName:(NSString *)name;
+ (instancetype)stringsWithString:(NSString *)string;
+ (instancetype)stringsWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)stringsWithArray:(
SCArray *)array;
+ (instancetype)stringsWithStrings:(
SCStrings *)strings;
+ (instancetype)strings;
- Class method stringsWithName: returns an empty strings list created by using the specified list name:
2016-08-21 01:05:14.873 libtest[1859:144664] Strings list "Strings List" count=0, case sensitive: (
)
- Class method stringsWithString: returns a strings list created by using the specified existing string. If method gets the nil pointer, then error SCL-20064 is occurs.
2016-08-21 01:07:29.829 libtest[1874:145195] Strings list count=1, case sensitive: (
Sample string
)
- Class method stringsWithCollection: returns a strings list created by using the strings from the specified existing collection of any supported type. If the source collection contains non-string objects, then error SCL-20066 is occurs. Also this method may throws the exception SCCollectionException.
2016-08-21 01:09:01.129 libtest[1896:145616] Strings list count=3, case sensitive: (
String 00
String 01
String 02
)
- Class method stringsWithArray: creates a new strings list that contains strings from a given array. If the array contains non-string objects, then the error SCL-20066 is occurs.
2017-06-21 18:28:50.875417+0300 libtest[51884:12444324] Strings list count=2, case sensitive: (
String 00
String 10
)
- Class method stringsWithStrings: returns a strings list created by using the specified existing strings list:
2016-08-21 01:10:51.787 libtest[1923:146645] Strings list count=1, case sensitive: (
Source string
)
- Class method strings returns an empty unnamed strings list created by using the default settings:
2016-08-21 01:11:36.688 libtest[1938:146933] Strings list count=0, case sensitive: (
)
Initializing lists
Class SCStrings implements the following initialization methods:
- (instancetype)initWithName:(NSString *)name;
- (instancetype)initWithString:(NSString *)string;
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithArray:(
SCArray *)array;
- (instancetype)initWithStrings:(
SCStrings *)strings;
- (instancetype)init;
- Method initWithName: initializes an empty strings list using the specified list name.
- Method initWithString: initializes a strings list using the specified existing string. If the method receives the nil pointer as an argument, then error SCL-20064 is occurs.
- Method initWithCollection: initializes a strings list using the strings from the specified existing collection of any supported type. If the collection contains the non-string objects, then error SCL-20066 is occurs. Also this method may throws the SCCollectionException exception.
- Method initWithArray: initializes a strings list using the strings from a given array. If the array contains the non-string objects, then error SCL-20066 is occurs.
- Method initWithStrings: initializes a strings list using the speified existing strings list.
- Method init initializes an empty unnamed strings list using the default strings.
Class instance properties
Class SCStrings declares the following instance properties:
@property (nonatomic, readwrite, retain) NSString *name;
@property (nonatomic, readonly, assign)
SCIndex count;
@property (nonatomic, readwrite, assign) BOOL readOnly;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL modified;
@property (nonatomic, readwrite, assign) BOOL caseInsensitive;
@property (nonatomic, readwrite, retain) id<SCTextDelegate> delegate;
- Property name gets access to the strings list name. The value of this property can be changed at any time.
- Read only propery count returns the count of string which stored in the receiving strings list:
NSLog(
@"Strings count: %qu", strings.
count);
2016-08-21 19:30:32.486 libtest[2810:366491] Strings count: 3
- Property readOnly can manage protection from unauthorized changes the contents of a string list. If the strings list detects the attempt of contents changing (removing, adding, changing and so on) then the error SCL-20063 is occurs.
2016-08-21 19:31:24.657 libtest[2824:366802] SCL-20063: Text is read only
2016-08-21 19:31:24.657 libtest[2824:366802] ================================================
- Read only property empty determines whether the receiving strings list is empty or contains at least one item:
NSLog(
@"%d", strings.
empty);
NSLog(
@"%d", strings.
empty);
2016-08-21 19:32:11.699 libtest[2843:367123] 1
2016-08-21 19:32:11.699 libtest[2843:367123] 0
- Read only property modified determines whether the receiving strings list has uncommitted changes. This property allows detecting the any changes after loading it from any source.
2016-08-21 19:32:38.729 libtest[2856:367277] 0
2016-08-21 19:32:38.730 libtest[2856:367277] 1
- Property caseInsensitive determines whether the search and comparison operations are case insensitive. If value of this property is equal to NO (default property values), then strings list is case sensitive (for example, characters 'A' and 'a' does not equal), otherwise (property set to the value YES) the strings list is case insensitive (for example, word "text" is equal to word "Text").
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-21 19:33:21.610 libtest[2872:367616] Strings list count=0, case sensitive: (
)
2016-08-21 19:33:21.610 libtest[2872:367616] Strings list count=0, case insensitive: (
)
Copying lists
Class SCStrings implements the following methods for copying strings lists:
- (void)setString:(NSString *)string;
- Method setStrings: replaces the content and settings of the receiving strings list by using the specified existing strings list. If the receiving list is read only, then error SCL-20063 is occurs. For nil pointer instead source list error SCL-20061 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-21 21:08:27.273 libtest[3353:407433] Strings list count=2, case sensitive, modified: (
Line 00
Line 01
)
2016-08-21 21:08:27.273 libtest[3353:407433] Strings list "Sample Strings" count=3, case sensitive, modified: (
String 00
String 10
String 20
)
- Method setCollection: replaces the content and settings of the receiving strings list by using the specified existing collection of any supported type:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-21 21:10:08.923 libtest[3377:408072] Strings list count=2, case sensitive, modified: (
Line 00
Line 01
)
2016-08-21 21:10:08.923 libtest[3377:408072] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
When calling this method may cause the following errors:
- SCL-20061 - nil pointer instead source collection
- SCL-20063 - receiving list is read only
- SCL-20066 - source collection contains the non-string objects
- Method setString: replaces the content of the receiving strings list by using the specified existing string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-21 21:11:14.668 libtest[3396:408402] Strings list count=2, case sensitive, modified: (
Line 00
Line 01
)
2016-08-21 21:11:14.668 libtest[3396:408402] Strings list count=1, case sensitive, modified: (
Sample String
)
This method may cause the following errors:
Comparing lists
Class SCStrings implements the following comparing methods:
- (BOOL)isEqualToStrings:(
SCStrings *)strings;
- Method isEqualToStrings: returns a boolean value that indicates whether the contents of the receiving strings list are equal to the contents of another given strings list.
- Method isEqualToCollection: returns a boolean value that indicates whether the contents of the receiving strings list are equal to the contents of given collection of any supported type. If the specified collection contains the non-string objects, the error SCL-20066 is occurs.
Deriving new strings lists
Class SCStrings declares the following methods for deriving new strings lists by using an existing strings lists:
- (instancetype)stringsByAddingString:(NSString *)string;
- (instancetype)stringsByAddingCollection:(
id<
SCCollection>)collection;
- (instancetype)stringsByAddingStrings:(
SCStrings *)strings;
- (instancetype)stringsByAddingStringsFromArray:(
SCArray *)array;
- (instancetype)stringsByAddingArray:(
SCArray *)array;
- Method stringsByAddingString: returns a strings list that contains strings from the receiving strings list and a given string:
NSLog( @"%@", [strings stringsByAddingString:@"New String"]);
2017-06-21 19:22:20.341841+0300 libtest[52442:12483210] Strings list count=3, case sensitive, modified: (
String 00
String 10
New String
)
- Method stringsByAddingCollection: creates a strings list that contains strings from the receiving list and a given collection of any supported type. If the collection contains non-string objects then error SCL-20066 is occurs.
NSLog( @"%@", [strings stringsByAddingCollection:@[ @"Line 20", @"Line 30"]]);
2017-06-21 19:43:55.404920+0300 libtest[52807:12500326] Strings list count=4, case sensitive, modified: (
String 00
String 10
Line 20
Line 30
)
- Method stringsByAddingStrings: returns a list that contains strings from the receiving strings list and a given another strings list:
NSLog( @"%@", [strings stringsByAddingStrings:source]);
2017-06-21 21:23:27.759849+0300 libtest[53429:12572136] Strings list count=4, case sensitive, modified: (
String 00
String 10
String 50
String 60
)
- Methods stringsByAddingStringsFromArray: and stringsByAddingArray: create a strings list that contains strings from the receiving strings list and a given array. If the array contains non-string objects then error SCL-20066 is occurs.
NSLog( @"%@", [strings stringsByAddingArray:array]);
2017-06-21 23:18:57.135783+0300 libtest[53953:12650631] Strings list count=4, case sensitive, modified: (
String 00
String 10
Line 40
Line 80
)
Enumerating strings
Class SCStrings implements the following enumerating strings methods:
@property (nonatomic, readonly, assign) NSEnumerator *stringEnumerator;
@property (nonatomic, readonly, assign) NSEnumerator *reverseStringEnumerator;
- (void)enumerate;
- (void)reverseEnumerate;
- Property stringEnumerator return an enumerator object that lets you access each string in the strings list:
NSString *string;
while ( ( string = enumerator.nextObject)) NSLog( @"%@", string);
2016-08-21 22:35:39.603 libtest[3755:446891] String 00
2016-08-21 22:35:39.603 libtest[3755:446891] String 10
2016-08-21 22:35:39.603 libtest[3755:446891] String 20
- Property reverseStringEnumerator returns an enumerator object that lets you access each string in the strings list, in reverse order:
NSString *string;
while ( ( string = enumerator.nextObject)) NSLog( @"%@", string);
2016-08-21 22:36:26.230 libtest[3771:447145] String 20
2016-08-21 22:36:26.230 libtest[3771:447145] String 10
2016-08-21 22:36:26.230 libtest[3771:447145] String 00
- Methods enumerate and enumerateWithDelegate: for each string from the list call the method processString:text: of the delegate object. The difference between the methods is that enumerateWithDelegate: operates with the specified delegate object, whereas method enumerate uses the receiving list delegate object.
@end
@implementation SCTestDelegate
- (void)processString:(NSString *)string text:(
SCStrings *)text {
NSLog( @"=> %@ <=", string);
}
@end
strings.
delegate = [[[SCTestDelegate alloc] init] autorelease];
2016-08-21 22:39:13.846 libtest[3829:448245] => String 00 <=
2016-08-21 22:39:13.846 libtest[3829:448245] => String 01 <=
2016-08-21 22:39:13.846 libtest[3829:448245] => String 02 <=
- Methods reverseEnumerate and reverseEnumerateWithDelegate: are similar to methods enumerate and enumerateWithDelegate: that only call delegate object method are carried out in the reverse order:
strings.
delegate = [[[SCTestDelegate alloc] init] autorelease];
2016-08-21 22:40:29.470 libtest[3853:448743] => String 02 <=
2016-08-21 22:40:29.470 libtest[3853:448743] => String 01 <=
2016-08-21 22:40:29.470 libtest[3853:448743] => String 00 <=
Also for support of operator for..in class SCStrings implements the following method:
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id *)buffer count:(NSUInteger)count;
for ( NSString *string in list) NSLog( @"%@", string);
2017-09-10 21:48:48.625693+0300 libtest[5836:158623] First string
2017-09-10 21:48:48.625713+0300 libtest[5836:158623] Second string
2017-09-10 21:48:48.625725+0300 libtest[5836:158623] Last string
Converting lists
Class SCStrings implements the following converting properties:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, retain) NSArray *foundationArray;
- Property array returns the array with the copy of all receiving strings list strings:
NSLog(
@"%@", strings.
array);
2016-08-21 23:21:44.308 libtest[4105:471168] Array "Sample List" count=3: (
"String 00",
"String 01",
"String 02"
)
- Property foundationArray returns the foundation array with the copy of all receiving strings list strings:
NSLog( @"%@", [strings foundationArray]);
2016-08-21 23:22:20.280 libtest[4120:471382] (
"String 00",
"String 01",
"String 02"
)
Sorting lists
Class SCStrings implements the following sorting properties and methods:
- (void)sortAscendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortDescendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortWithSorter:(
id<
SCSorter>)sorter;
- (void)sortAscending;
- (void)sortDescending;
- (void)sort;
@property (nonatomic, readonly, assign)
SCStrings *ascendingSortedStrings;
@property (nonatomic, readonly, assign)
SCStrings *descendingSortedStrings;
@property (nonatomic, readonly, assign)
SCStrings *sortedStrings;
- Method sortAscendingWithSorter: sorts lexicographically ascending the receiving strings list using the specified sorter instance.
- Method sortDescendingWithSorter: sorts lexicographically descending the receiving strings list using the specified sorter instance.
- Method sortAscending sorts ascending the receiving strings list using the default sorter instance:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 00:24:00.530 libtest[4485:507068] Strings list count=3, case sensitive, modified: (
String 04
String 02
String 06
)
2016-08-22 00:24:00.530 libtest[4485:507068] Strings list count=3, case sensitive, modified: (
String 02
String 04
String 06
)
- Method sortDescending sorts descending the receiving strings list using the default sorter instance:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 00:26:16.441 libtest[4510:507965] Strings list count=3, case sensitive, modified: (
String 04
String 02
String 06
)
2016-08-22 00:26:16.441 libtest[4510:507965] Strings list count=3, case sensitive, modified: (
String 06
String 04
String 02
)
- Attention
- If any of these methods are calling for the read only strings list, then error SCL-20063 is occurs.
- Property ascendingSortedStrings returns the strings list with ascending sorted using the default sorting instance strings from the receving strings list. Synonyms of this property is property sortedStrings.
- Property descendingSortedStrings returns the strings list with descending sorted using the default sorter instance strings from the receving strings list.
- Property sortedStrings returns the strings list with ascending sorted using the default sorter instance strings from the receving strings list. This property is a synonyms of the property ascendingSortedStrings.
2016-08-22 18:36:38.411 libtest[4953:619805] Strings list count=3, case sensitive, modified: (
String 02
String 04
String 06
)
- Attention
- Strings sort depends on the value of the property caseInsensitive.
During the sorting operation strings list calls the methods text:willSortAscending:sorter: and text:didFinishSortingAscending:sorter: of the delegate object.
Adding strings to list
If the described methods calls for the read only strings list, then the error SCL-20063 is occurs.
Class SCStrings implements the following methods for adding strings:
- (void)addString:(NSString *)string;
- (void)addLine;
- (void)addStringsFromArray:(
SCArray *)array;
- Method addString: adds into the receiving strings list the specified string. If the method receives the nil pointer instead the added string, then the error SCL-20064 is occurs.
2016-08-22 18:54:19.351 libtest[5093:629449] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
- Method addCollection: adds into the receiving strings list the strings from the specified existing collection of any supported type:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 18:56:10.014 libtest[5119:630064] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-22 18:56:10.014 libtest[5119:630064] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 10
String 11
)
When using this method, the following exceptions may occur:
- SCL-20061 - nil pointer instead the source collection
- SCL-20063 - receiving list is read only
- SCL-20066 - source collection contains non-string objects
- Method addStrings: adds into the receiving strings list the strings from the specified existing strings list. If the method receives the nil pointer, then the error SCL-20061 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 18:58:01.724 libtest[5142:630607] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-22 18:58:01.724 libtest[5142:630607] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
- Method addLine adds into the receiving strings list the empty string. Empty is a string that contains no characters. In this case an empty string - is an existing object and has no relationship to the nil pointer to a string.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 18:59:46.092 libtest[5160:631400] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-22 18:59:46.093 libtest[5160:631400] Strings list count=3, case sensitive, modified: (
String 00
String 01
)
- Methods addStringsFromArray: and addArray: add into the receiving strings list strings from a given array. If the array contains non-string objects then the error SCL-20066 is occurs.
2017-06-22 01:42:40.523465+0300 libtest[54546:12740251] Strings list count=4, case sensitive, modified: (
String 00
String 10
String 50
String 60
)
During execution of this methods strings list calls the events text:willAddString: and text:didFinishAddingString: of the delegate object.
Additionally to adding methods class SCStrings implements the methods for inserting strings at the specified indexes:
- (void)insertString:(NSString *)string atIndex:(
SCIndex)index;
- (void)insertStrings:(
SCStrings *)strings atIndexes:(NSIndexSet *)indexes;
- (void)insertCollection:(
id<
SCCollection>)collection atIndexes:(NSIndexSet *)indexes;
- (void)insertLineAtIndex:(
SCIndex)index;
- Method insertString:atIndex: inserts a given string into the contents at a given index:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 19:04:09.935 libtest[5186:633910] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:04:09.935 libtest[5186:633910] Strings list count=4, case sensitive, modified: (
String 00
String 01
==========
String 02
)
The following errors can occur when using method:
- Method insertStrings:atIndex: adds into the receiving strings list the strings from the specified existing strings list:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 19:06:57.335 libtest[5214:634866] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:06:57.335 libtest[5214:634866] Strings list count=5, case sensitive, modified: (
String 00
String 01
Line 00
Line 01
String 02
)
The following errors can occur when using method:
- Method insertCollection:atIndex: inserts the strings from a given collection of any supported type into the receiving strings list at the specified indexes:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 19:20:02.227 libtest[5243:639086] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:20:02.227 libtest[5243:639086] Strings list count=5, case sensitive, modified: (
String 00
String 01
000
010
String 02
)
The following errors can occur when using method:
- SCL-20061 - nil pointer instead source collection
- SCL-20063 - receiving list is read only
- SCL-20066 - source collection contains non-string objects
- SCL-20072 - incorrect destination index
- Method insertStrings:atIndexes: inserts the strings from a given strings list into the receiving strings list at the specified indexes. Number of strings must be equal to the number of indexes.
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:2];
NSLog( @"%@", strings);
2016-08-22 19:24:46.145 libtest[5303:640632] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:24:46.145 libtest[5303:640632] Strings list count=5, case sensitive, modified: (
=========
String 00
=========
String 01
String 02
)
The following errors can occur when using method:
- SCL-20061 - nil pointer instead source strings list
- SCL-20063 - receiving list is read only
- SCL-20074 - incorrect destination indexes set
- SCL-20075 - number of strings does not match to number of indexes
- Method insertCollection:atIndexes: inserts the strings from a given collection of any supported type into the receiving strings list at the specified indexes.Number of strings must be equal to the number of indexes.
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:2];
NSLog( @"%@", strings);
2016-08-22 19:26:22.878 libtest[5327:641164] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:26:22.878 libtest[5327:641164] Strings list count=5, case sensitive, modified: (
000
String 00
010
String 01
String 02
)
Execution the method may cause the following errors:
- SCL-20061 - nil pointer instead source collection
- SCL-20063 - receiving list is read only
- SCL-20066 - source collection contains non-string objects
- SCL-20074 - incorrect destination indexes set
- SCL-20075 - number of strings does not match to number of indexes
- Method insertLineAtIndex: inserts into the receiving strings list empty line at the specified index:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 19:28:24.407 libtest[5351:641841] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 19:28:24.407 libtest[5351:641841] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
)
During the methods execution the strings list calls the event handlers text:willInsertString:atIndex: and text:didFinishInsertingString:atIndex: of list delegation object.
Removing strings from list
Class SCStrings implements the following methods for removing strings from the list:
- (void)removeAllStrings;
- (void)removeFirstString;
- (void)removeLastString;
- (void)removeStringAtIndex:(
SCIndex)index;
- (void)removeStringsAtIndexes:(NSIndexSet *)indexes;
- (void)removeString:(NSString *)string;
- (void)removeStringsWithSubstring:(NSString *)substring;
- (void)removeStringsNotAtIndexes:(NSIndexSet *)indexes;
- (void)removeStringsNotEqualTo:(NSString *)string;
- (void)removeStringsNotInStrings:(
SCStrings *)strings;
- (void)removeStringsNotInCollection:(
id<
SCCollection>)collection;
- (void)removeStringsWithoutSubstring:(NSString *)substring;
- (void)removeDuplicatedStrings;
If any method calls for the read only list, then error SCL-20063 is occurs.
- Method removeFirstString removes from strings list the first string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 21:42:19.234 libtest[5965:708191] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 21:42:19.235 libtest[5965:708191] Strings list count=2, case sensitive, modified: (
String 01
String 02
)
- Method removeLastString removes from strings list the last string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 21:44:02.899 libtest[5987:709225] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 21:44:02.899 libtest[5987:709225] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
- Method removeStringAtIndex: removes from strings list the string at the specified index. If the method receives the incorrect index, then error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 21:47:44.866 libtest[6019:711494] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 21:47:44.866 libtest[6019:711494] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
- Method removeStringsAtIndexes: removes from strings list the strings at the indexes from the specified index set. If the specified index set is incorrect, then the error SCL-20074 is occurs.
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:3];
NSLog( @"%@", strings);
2016-08-22 21:51:04.216 libtest[6048:713775] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-22 21:51:04.217 libtest[6048:713775] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
This methods call the event handlers text:willRemoveStringAtIndex: and text:didFinishRemovingStringAtIndex: of the list delegate object.
- Method removeString: removes all occurrences in the strings list of a given string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 21:53:58.476 libtest[6074:716014] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 21:53:58.476 libtest[6074:716014] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
- Method removeStrings: removes all occurrences in the strings list of the strings from the specified strings list:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
NSLog( @"%@", strings);
NSLog( @"%@", strings);
- Method removeCollection: removes from the receiving strings list the strings in the specified collection of any supported type. If the collection contains non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 22:04:54.229 libtest[6152:720528] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-22 22:04:54.230 libtest[6152:720528] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
- Method removeStringsWithSubstring: removes all occurrences in the strings list of the strings which contain the specified substring:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 22:09:28.118 libtest[6177:723112] Strings list count=4, case sensitive, modified: (
String 00
Line 01
String 02
Line 03
)
2016-08-22 22:09:28.118 libtest[6177:723112] Strings list count=2, case sensitive, modified: (
Line 01
Line 03
)
These methods call the event handlers text:willRemoveString: and text:didFinishRemovingString: of the delegate object.
- Method removeStringsNotAtIndexes: removes from the receiving strings list strings which not present in the specified index set:
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:1];
NSLog( @"%@", strings);
2016-08-22 22:14:21.487 libtest[6219:726403] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 22:14:21.488 libtest[6219:726403] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
Method calls the event handlers text:willRemoveStringAtIndex: and text:didFinishRemovingStringAtIndex: of the delegate object.
- Method removeStringsNotEqualTo: removes from the receiving strings list all strings which not equal to the specified string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 22:32:17.875 libtest[6332:735443] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-22 22:32:17.875 libtest[6332:735443] Strings list count=1, case sensitive, modified: (
String 00
)
- Method removeStringsNotInStrings: removes from the receiving strings list all strings which not present in the specified strings list:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 22:36:32.866 libtest[6368:739263] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-22 22:36:32.866 libtest[6368:739263] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
- Method removeStringsNotInCollection: removes from the receiving strings list all strings which not present in the specified collection of any supported type. If the specified collection contains the non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 22:58:11.895 libtest[6442:754405] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-22 22:58:11.895 libtest[6442:754405] Strings list count=2, case sensitive, modified: (
String 01
String 03
)
- Method removeStringsWithoutSubstring: removes all occurrences in the strings list of the strings which not contain the specified substring:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 23:05:31.458 libtest[6496:761256] Strings list count=4, case sensitive, modified: (
String 00
Line 01
String 02
Line 03
)
2016-08-22 23:05:31.459 libtest[6496:761256] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
- Method removeDuplicatedStrings removes all duplicated strings:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-22 23:14:02.184 libtest[6525:768751] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 01
String 00
)
2016-08-22 23:14:02.184 libtest[6525:768751] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
These methods call the event handlers text:willRemoveStringAtIndex: and text:didFinishRemovingStringAtIndex: of the delegate object.
Replacing strings
Class SCStrings implements the following methods for replacing strings within list:
- (void)replaceStringAtIndex:(
SCIndex)index withString:(NSString *)string;
- (void)replaceStringsAtIndexes:(NSIndexSet *)indexes withStrings:(
SCStrings *)strings;
- (void)replaceStringsAtIndexes:(NSIndexSet *)indexes withCollection:(
id<
SCCollection>)collection;
- (void)replaceString:(NSString *)string withString:(NSString *)newString;
If any of these methods calls for a read only strings list, then the error SCL-20063 is occurs.
- Method replaceStringAtIndex:withString: replaces the string at the specified index with a given string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-23 23:26:24.102 libtest[1628:99073] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-23 23:26:24.102 libtest[1628:99073] Strings list count=3, case sensitive, modified: (
String 00
=========
String 02
)
Method can throws the following exceptions:
- SCL-20063 - receiving list is read only
- SCL-20064 - nil pointer instead replacement string
- SCL-20072 - incorrect index of the repleceable line
- Method replaceStringsAtIndexes:withStrings: replaces the strings in the receiving list at specified locations with the strings from a given strings list. Number of strings must be equal to the number of indexes.
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:3];
NSLog( @"%@", strings);
2016-08-24 01:04:48.486 libtest[2171:180542] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 01:04:48.486 libtest[2171:180542] Strings list count=4, case sensitive, modified: (
=========
String 01
String 02
---------
)
During the method execution can occur the following errors:
- SCL-20061 - nil pointer instead of replacement strings list
- SCL-20063 - receiving list is read only
- SCL-20074 - indexes set is incorrect
- SCL-20075 - number of indexes does not match to the number of strings
- Method replaceStringsAtIndexes:withCollection: replaces the strings in the receiving strings list at specified locations with the strings from a given collection of any supported type. Number of indexes must be equal to the number of strings within the collection.
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", strings);
NSLog( @"%@", strings);
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:1];
[indexSet addIndex:2];
NSLog( @"%@", strings);
Method can occur the following errors:
- SCL-20061 - nil pointer instead collection or replacement strings
- SCL-20063 - receiving list is read only
- SCL-20066 - collection contains a non-string objects
- SCL-20074 - incorrect indexes set
- SCL-20075 - number of indexes does not match the number of strings within collection
These methods call the event handlers text:willReplaceStringAtIndex:withString: and text:didFinishReplacingStringAtIndex:withString: delegate object.
- Method replaceString:withString: replaces the all occurrences in the strings list of a given string with the specified string:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 01:19:18.207 libtest[2247:189321] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 01
)
2016-08-24 01:19:18.208 libtest[2247:189321] Strings list count=4, case sensitive, modified: (
String 00
=========
String 02
=========
)
Method calls the event handlers text:willReplaceString:withString: and text:didFinishReplacingString:withString: of the delegate object.
Also a class SCStrings provides the support of the operator [] for replacing strings by using its indexes:
NSLog( @"%@", strings);
strings[1] = @"New string";
NSLog( @"%@", strings);
2017-09-11 12:47:49.626863+0300 libtest[15505:479454] Strings list count=3, case sensitive, modified: (
First string
Second string
Last string
)
2017-09-11 12:47:49.626967+0300 libtest[15505:479454] Strings list count=3, case sensitive, modified: (
First string
New string
Last string
)
Coping and moving strings
Class SCStrings is not just a container for storing a variety of strings, but also offers enough powerful tools for line by line content processing. These tools contain the following methods:
- (void)exchangeStringAtIndex:(
SCIndex)index withStringAtIndex:(
SCIndex)destination;
- (void)duplicateStringAtIndex:(
SCIndex)index;
- (void)duplicateAllStrings;
- (void)duplicate;
- (void)copyStringAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)moveStringAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)forwardMoveStringAtIndex:(
SCIndex)index;
- (void)backwardMoveStringAtIndex:(
SCIndex)index steps:(
SCIndex)steps;
- (void)backwardMoveStringAtIndex:(
SCIndex)index;
- (void)moveToFirstPositionStringAtIndex:(
SCIndex)index;
- (void)moveToLastPositionStringAtIndex:(
SCIndex)index;
If you attempt calling any of these methods for the read only strings list, then the error SCL-20063 is occurs. In addition to this error may cause other errors, typical for the whole group of methods and specific method. When considering the methods we will indicate the exceptions that may occur during operations.
- Method exchangeStringAtIndex:withStringAtIndex: exchanges the strings in the receiving list at given indices. If one or both indexes are incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 13:38:16.972 libtest[6326:491362] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 13:38:16.972 libtest[6326:491362] Strings list count=4, case sensitive, modified: (
String 03
String 01
String 02
String 00
)
Method calls the event handlers text:willExchangeStringAtIndex:withStringAtIndex: and text:didFinishExchangingStringAtIndex:withStringAtIndex: of the delegate object.
- Method duplicateStringAtIndex: duplicates the string at the specified index. If the method receives the incorrect index, then the error SCL-20072 is occurs. Method calls the event handlers text:willDuplicateStringAtIndex: and text:didFinishDuplicatingStringAtIndex: of the delegate object.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 13:43:58.127 libtest[6393:495594] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-24 13:43:58.127 libtest[6393:495594] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 01
String 02
)
- Method duplicateAllStrings duplicates all strings within receiving strings list. After the execution of the method, each string will appear in the list twice.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 13:48:49.083 libtest[6422:499466] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-24 13:48:49.083 libtest[6422:499466] Strings list count=4, case sensitive, modified: (
String 00
String 00
String 01
String 01
)
- Method duplicate duplicates content of the receving strings list. After the method execution, the resulting list will contents the two consecutive source lists. Also method calls the event handlers willDuplicateText: and didFinishDuplicatingText:.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 13:53:55.418 libtest[6496:502939] Strings list count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-24 13:53:55.419 libtest[6496:502939] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 00
String 01
)
- Method copyStringAtIndex:toIndex: copies the string at the specified index to a given destination index. If one of the specified indexes is incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:12:07.287 libtest[6593:512651] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-24 14:12:07.287 libtest[6593:512651] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 00
)
- Method moveStringAtIndex:toIndex: moves the string at the specified index to a given destination index. If any of the specified indexes is incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:17:59.595 libtest[6650:516640] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-24 14:17:59.595 libtest[6650:516640] Strings list count=3, case sensitive, modified: (
String 01
String 00
String 02
)
- Method forwardMoveStringAtIndex:steps: moves the string at the specified index to a given count of positions to the top of the list. If the string index is incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:20:22.611 libtest[6676:518826] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:20:22.611 libtest[6676:518826] Strings list count=4, case sensitive, modified: (
String 00
String 03
String 01
String 02
)
- Method forwardMoveStringAtIndex: moves the string at the specified index to an one position to the top of the strings list. If the method detects the incorrect index, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:21:37.611 libtest[6698:519861] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:21:37.611 libtest[6698:519861] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 03
String 02
)
- Method backwardMoveStringAtIndex:steps: moves the string at the specified index to a given count of positions to the top of the list. If the index is incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:23:00.079 libtest[6724:521210] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:23:00.080 libtest[6724:521210] Strings list count=4, case sensitive, modified: (
String 01
String 02
String 00
String 03
)
- Method backwardMoveStringAtIndex: moves the string at the specified index to an one position to the bottom of the strings list. If the method receives the incorrect index, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:24:30.016 libtest[6749:522972] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:24:30.016 libtest[6749:522972] Strings list count=4, case sensitive, modified: (
String 01
String 00
String 02
String 03
)
- Method moveToFirstPositionStringAtIndex: moves the string at the specified index to the first position within the strings list. If the index is incorrect, then the error SCL-20072 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:27:06.722 libtest[6780:525408] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:27:06.723 libtest[6780:525408] Strings list count=4, case sensitive, modified: (
String 02
String 00
String 01
String 03
)
- Method moveToLastPositionStringAtIndex: moves the string at the specified index to the last position within the strings list:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:29:06.049 libtest[6808:527087] Strings list count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-24 14:29:06.049 libtest[6808:527087] Strings list count=4, case sensitive, modified: (
String 00
String 02
String 03
String 01
)
Into the moving and copying properties and methods also include the reverse properties and methods:
@property (nonatomic, readonly, assign)
SCStrings *reversedStrings;
- (void)reverse;
- Property reversedStrings returns the strings list with the all strings from the receiving strings list in reverse order:
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:42:51.731 libtest[6870:534026] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-24 14:42:51.732 libtest[6870:534026] Strings list count=3, case sensitive, modified: (
String 02
String 01
String 00
)
2016-08-24 14:42:51.732 libtest[6870:534026] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
- Method reverse reverses the order of all strings in the receiving array. If the receiving list is read only, then the error SCL-20063 is occurs.
NSLog( @"%@", strings);
NSLog( @"%@", strings);
2016-08-24 14:40:51.589 libtest[6841:532216] Strings list count=3, case sensitive, modified: (
String 00
String 01
String 02
)
2016-08-24 14:40:51.589 libtest[6841:532216] Strings list count=3, case sensitive, modified: (
String 02
String 01
String 00
)
Strings access
Class SCStrings implements the following properties and methods for accessing to the strings:
@property (nonatomic, readonly, assign) NSString *firstString;
@property (nonatomic, readonly, assign) NSString *lastString;
- (NSString *)firstString;
- (NSString *)lastString;
- (NSString *)stringAtIndex:(
SCIndex)index;
- (
SCStrings *)stringsAtIndexes:(NSIndexSet *)indexes;
- Properties firstString and lastString return the first or last string from the receiving strings list or nil pointer if the list is empty:
NSLog( @"Last string: %@", [strings lastString]);
2016-08-24 16:57:05.557 libtest[8024:633793] First string: String 00
2016-08-24 16:57:05.557 libtest[8024:633793] Last string: String 02
- Method stringAtIndex: returns the string located at the specified index. If the index is incorrect, then the error SCL-20072 is incorrect.
NSLog( @"String #1: %@", [strings stringAtIndex:1]);
2016-08-24 16:58:22.969 libtest[8056:634576] String #1: String 01
- Methods stringsAtIndexes: returns a strings list containing the strings in the receiving list at the indexes specified by a given index set. Incorrect indexes are ignored.
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:0];
[indexSet addIndex:2];
NSLog( @"%@", [strings stringsAtIndexes:indexSet]);
2016-08-24 17:12:52.958 libtest[8093:640827] Strings list count=2, case sensitive, modified: (
String 00
String 02
)
Also the class SCStrings provides a support of the operator [] for accessing a direct access to strings by using indexes:
NSLog( @"%@", strings[1]);
2017-09-11 12:58:11.386036+0300 libtest[15714:487455] Second string
Search strings
Class SCStrings implements the many methods for searching and selecting strings within the strings list by using the various criteria. This methods can be devided into the following groups, which are desribed in this section:
- check for strings
- string indexes detection
- strings fetching
- count the number of strings
During search operations class SCStrings allows for value of the property caseInsensitive. If this value is equal to NO, then class instance ignores the characters case.
Class SCStrings declares the following methods of checking for strings:
- (BOOL)containsString:(NSString *)string;
- (BOOL)containsStrings:(
SCStrings *)strings;
- (BOOL)containsAnyString:(
SCStrings *)strings;
- (BOOL)containsAnyStringFromCollection:(
id<
SCCollection>)collection;
- (BOOL)containsSubstring:(NSString *)substring;
- (BOOL)containsSubstrings:(
SCStrings *)substrings;
- (BOOL)containsSubstringsFromCollection:(
id<
SCCollection>)collection;
- (BOOL)containsAnySubstring:(
SCStrings *)substrings;
- (BOOL)containsAnySubstringFromCollection:(
id<
SCCollection>)collection;
- (BOOL)containsDuplicatedStrings;
- Method containsString: returns a Boolean value that indicates whether a given string is present in the receiving strings list:
NSLog( @"String 02: %d", [strings containsString:@"String 02"]);
NSLog( @"String 04: %d", [strings containsString:@"String 04"]);
2016-08-24 17:44:57.417 libtest[8372:666502] String 02: 1
2016-08-24 17:44:57.417 libtest[8372:666502] String 04: 0
- Method containsStrings: returns a Boolean value that indicates whether the receiving strings list contains the all strings from the specified strings list. If at least one string from the specified list does not presents in the receiving strings list, then the method returns th NO value.
NSLog( @"%d", [strings containsStrings:list]);
NSLog( @"%d", [strings containsStrings:list]);
2016-08-24 17:46:33.611 libtest[8398:667740] 1
2016-08-24 17:46:33.611 libtest[8398:667740] 0
- Method containsCollection: is equal to the method containsStrings:, but accepts the collection of any supported type instead the strings list. If the specified collection contains non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%d", [strings containsCollection:array]);
[array removeObject:@"String 04"];
NSLog( @"%d", [strings containsCollection:array]);
2016-08-24 17:48:20.922 libtest[8427:668985] 0
2016-08-24 17:48:20.922 libtest[8427:668985] 1
- Method containsAnyString: returns a Boolean value that indicates whether the receiving strings list contains at least one string from the specified strings list:
NSLog( @"%d", [strings containsAnyString:list]);
NSLog( @"%d", [strings containsAnyString:list]);
2016-08-24 17:50:06.494 libtest[8459:670543] 0
2016-08-24 17:50:06.494 libtest[8459:670543] 1
- Method containsAnyStringFromCollection: is equal to the method containsAnyString:, but accepts the collection of any supported type instead the strings list. If the specified collection contains non-string objects then the error SCL-20066 is occurs.
NSLog( @"%d", [strings containsAnyStringFromCollection:array]);
[array removeObject:@"String 02"];
NSLog( @"%d", [strings containsAnyStringFromCollection:array]);
2016-08-24 17:51:26.539 libtest[8485:671299] 1
2016-08-24 17:51:26.539 libtest[8485:671299] 0
- Method containsSubstring: returns a Boolean value that indicates whether the receiving strings list contains the specified substring:
NSLog( @"%d", [strings containsSubstring:@"ing 0"]);
NSLog( @"%d", [strings containsSubstring:@"ing 1"]);
2016-08-24 17:52:47.962 libtest[8506:672089] 1
2016-08-24 17:52:47.962 libtest[8506:672089] 0
- Method containsSubstrings: returns a Boolean value that indicates whether the receiving strings list contains all of substrings from the specified strings list. If at least one string from the specified list does not presents in the receiving list, then method returns the NO value.
NSLog( @"%d", [strings containsSubstrings:substrings]);
NSLog( @"%d", [strings containsSubstrings:substrings]);
2016-08-24 17:55:11.683 libtest[8540:673775] 1
2016-08-24 17:55:11.683 libtest[8540:673775] 0
- Method containsSubstringsFromCollection: returns a Boolean value that indicates whether the receiving strings list contains all of substrings from the specified collection. If the specified collection contains the non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%d", [strings containsSubstringsFromCollection:array]);
[array removeObject:@"ing 1"];
NSLog( @"%d", [strings containsSubstringsFromCollection:array]);
2016-08-24 17:58:32.496 libtest[8571:675866] 0
2016-08-24 17:58:32.497 libtest[8571:675866] 1
- Method containsAnySubstring: returns a Boolean value that indicates whether the receiving strings list contains at least one substring from the specified strings list:
NSLog( @"%d", [strings containsAnySubstring:substrings]);
NSLog( @"%d", [strings containsAnySubstring:substrings]);
2016-08-24 18:08:59.204 libtest[8614:680443] 1
2016-08-24 18:08:59.204 libtest[8614:680443] 0
- Method containsAnySubstringFromCollection: is equals to the method containsAnySubstring:, but accepts the collection of any supported type instead the strings list. If the specified collection contains non-strings objects, then the error SCL-20066 is occurs.
NSLog( @"%d", [strings containsAnySubstringFromCollection:array]);
[array addObject:@"ing 0"];
NSLog( @"%d", [strings containsAnySubstringFromCollection:array]);
2016-08-24 18:10:31.861 libtest[8643:681782] 0
2016-08-24 18:10:31.861 libtest[8643:681782] 1
- Method containsDuplicatedStrings returns a Boolean value that indicates whether the receiving strings list contains at least one duplicated string:
NSLog( @"%d", [strings containsDuplicatedStrings]);
NSLog( @"%d", [strings containsDuplicatedStrings]);
2016-08-24 18:11:27.468 libtest[8663:682395] 0
2016-08-24 18:11:27.469 libtest[8663:682395] 1
For indexes detection class SCStrings implements the following properties and methods:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastString;
- (
SCIndex)indexOfString:(NSString *)string;
- (
SCIndex)indexOfSubstring:(NSString *)substring;
- Property indexOfLastString returns the index of the last string within the receiving strings list:
2016-08-24 18:13:19.890 libtest[8704:683568] 2
- Method indexOfString: returns the lowest index whose corresponding strings list item is equal to a given string. If the required string does not exists, method returns the value NSNotFound.
NSLog( @"Index of String 02: %d", [strings indexOfString:@"String 02"]);
NSLog( @"Index of String 04: %d", [strings indexOfString:@"String 04"]);
2016-08-24 18:12:42.969 libtest[8688:683112] Index of String 02: 2
2016-08-24 18:12:42.969 libtest[8688:683112] Index of String 04: -1
- Method indexOfSubstring: returns the lowest index whose corresponding list string contains a given substrin. If the required substring does not exists, then method returns the value NSNotFound.
NSLog( @"%d", [strings indexOfSubstring:@"ing 0"]);
NSLog( @"%d", [strings indexOfSubstring:@"ing 1"]);
2016-08-24 18:14:16.863 libtest[8724:684339] 0
2016-08-24 18:14:16.863 libtest[8724:684339] -1
Strings selection is a process of creating new strings list based on selection criteria from the source list. Class SCStrings declares a wide range of selection methods:
- (
SCStrings *)stringsWithSubstring:(NSString *)substring;
- (
SCStrings *)stringsWithoutSubstring:(NSString *)substring;
- Method stringsWithSubstring: returns a list of strings that contain the specified substring:
NSLog( @"%@", [strings stringsWithSubstrings:substrings]);
NSLog( @"%@", [strings stringsWithSubstrings:substrings]);
2016-08-24 18:27:24.137 libtest[8957:693111] Strings list count=2, case sensitive, modified: (
String 010
String 012
)
2016-08-24 18:27:24.137 libtest[8957:693111] Strings list count=0, case sensitive: (
)
- Method stringsWithSubstrings: returns a list of strings that contain all substrings from the specified strings list:
NSLog( @"%@", [strings stringsWithSubstrings:substrings]);
NSLog( @"%@", [strings stringsWithSubstrings:substrings]);
2016-08-24 18:27:24.137 libtest[8957:693111] Strings list count=2, case sensitive, modified: (
String 010
String 012
)
2016-08-24 18:27:24.137 libtest[8957:693111] Strings list count=0, case sensitive: (
)
- Method stringsWithSubstringsFromCollection: is equals to the method stringsWithSubstrings:, but uses the collection of any supported type instead strings list. If the collection with substrings contains the non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%@", [strings stringsWithSubstringsFromCollection:array]);
[array addObject:@"2"];
NSLog( @"%@", [strings stringsWithSubstringsFromCollection:array]);
2016-08-24 18:29:19.441 libtest[8995:694772] Strings list count=2, case sensitive, modified: (
String 100
String 110
)
2016-08-24 18:29:19.441 libtest[8995:694772] Strings list count=0, case sensitive: (
)
- Method stringsWithAnySubstring: returns a list of strings that contain any substring from the specified strings list:
NSLog( @"%@", [strings stringsWithAnySubstring:substrings]);
2016-08-24 18:37:24.801 libtest[9060:699391] Strings list count=2, case sensitive, modified: (
String 00
String 20
)
- Method stringsWithAnySubstringFromCollection: returns a list of strings that contain any substring from the specified collection of any supported type. If the collection contains non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%@", [strings stringsWithAnySubstringFromCollection:array]);
2016-08-24 18:39:29.433 libtest[9089:700616] Strings list count=2, case sensitive, modified: (
String 10
String 30
)
- Method stringsWithoutSubstring: returns a list of strings that do not contain the specified substring:
NSLog( @"%@", [strings stringsWithoutSubstring:@"Line"]);
2016-08-24 18:40:50.606 libtest[9114:701616] Strings list count=2, case sensitive, modified: (
String 00
String 10
)
- Method stringsWithoutSubstrings: returns a list of strings that do not contain the substrings from the specified strings list:
NSLog( @"%@", [strings stringsWithoutSubstrings:substrings]);
2016-08-24 18:43:40.661 libtest[9149:703742] Strings list count=2, case sensitive, modified: (
Message 40
Message 50
)
- Method stringsWithoutSubstringsFromCollection: returns a list of strings that do not dontain the substring from the specified collection of any supported type. If the collection contains a non-string objects, then the error SCL-20066 is occurs.
NSLog( @"%@", [strings stringsWithoutSubstringsFromCollection:array]);
2016-08-24 18:45:09.315 libtest[9175:705009] Strings list count=4, case sensitive, modified: (
String 00
String 10
Message 40
Message 50
)
Class SCStrings implements the following methods for strings counting:
- (
SCULong)countOfString:(NSString *)string;
- (
SCULong)countOfSubstring:(NSString *)substring;
- (
SCULong)countOfStringsWithSubstring:(NSString *)substring;
- Method countOfString: returns a count of strings from the receiving list which are equal to the specified string:
NSLog( @"Count of String 00: %d", [strings countOfString:@"String 00"]);
NSLog( @"Count of String 02: %d", [strings countOfString:@"String 02"]);
NSLog( @"Count of String 04: %d", [strings countOfString:@"String 04"]);
2016-08-24 18:47:24.808 libtest[9206:706918] Count of String 00: 2
2016-08-24 18:47:24.808 libtest[9206:706918] Count of String 02: 1
2016-08-24 18:47:24.808 libtest[9206:706918] Count of String 04: 0
- Method countOfSubstring: returns a count of substrings from the receiving list which are equal to the specified substring:
NSLog( @"%d", [strings countOfSubstring:@"0"]);
NSLog( @"%d", [strings countOfSubstring:@"1"]);
NSLog( @"%d", [strings countOfSubstring:@"4"]);
2016-08-24 18:49:38.833 libtest[9253:708280] 6
2016-08-24 18:49:38.833 libtest[9253:708280] 1
2016-08-24 18:49:38.833 libtest[9253:708280] 0
- Method countOfStringsWithSubstring: returns a count of strings from the receiving list which are contains at least one occurrency of the specified substring. Unlike the method countOfSubstring: is that it returns the number of strings, regardless of how many times the string contains the desired substring.
NSLog( @"%d", [strings countOfStringsWithSubstring:@"ing 00"]);
NSLog( @"%d", [strings countOfStringsWithSubstring:@"ing 02"]);
NSLog( @"%d", [strings countOfStringsWithSubstring:@"ing 04"]);
2016-08-24 18:54:11.586 libtest[9278:710720] 2
2016-08-24 18:54:11.586 libtest[9278:710720] 1
2016-08-24 18:54:11.586 libtest[9278:710720] 0
Unique strings lists
Class SCUniqueStrings inherits from the class SCStrings all strings list functionality, extending it with the features for control the uniqueness added information - the unique strings list do not allow duplicate strings stored in them. Trying to add an already presented string into the list, depending on the property strongMode value leads either to ignore the added string or causes the trowing the exception SCL-20069, indicating what of the existing strings of the new duplicates.
Accordingly, inherited from the class SCStrings methods to copy and duplicate strings are overloaded and ignore the duplicated strings or throw the exception SCL-20069.
We note in particular that, as an ancesor class, SCUniqueStrings depends on the value of the property caseInsensitive. The important point is an instance behavior when you change the property value from NO to YES. With this switching can be a situation when the previously considered differnt strings in the new mode will be recognized as the same and a string with large index well be removed or exception SCL-20069 will be throwing.
[strings addString:@"String 00"];
[strings addString:@"string 00"];
2016-08-25 11:30:46.520 libtest[12212:1075882] SCL-20069: Duplicate string "string 00" at index 1
2016-08-25 11:30:46.520 libtest[12212:1075882] ==================================================
Therefore, we recommend caution with change the case insensitive mode for non-empty unique strings lists.
When you copy strings from the existing collections of any supported type duplicate string will be either removed or the error is occurs.
Class instance properties
Class SCUniqueStrings extends the class SCStrings by implements the following properties:
@property (nonatomic, readwrite, assign) BOOL strongMode;
- Property strongMode determines the mandatory exception generating when duplicate string detected. If the property contains the value NO, then the list ignores the duplicated strings, otherwise the error SCL-20066 is occurs.
Creating lists
Class SCUniqueStrings declares the following class methods for creating class instances by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)uniqueStringsWithCoder:(NSCoder *)coder;
+ (instancetype)uniqueStringsWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)uniqueStringsWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)uniqueStringsWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)uniqueStringsWithStream:(
SCStream *)stream;
+ (instancetype)uniqueStringsWithFileStream:(NSString *)path;
+ (instancetype)uniqueStringsWithData:(NSData *)data;
+ (instancetype)uniqueStringsWithContentsOfFile:(NSString *)path;
+ (instancetype)uniqueStringsWithContentsOfURL:(NSURL *)url;
+ (instancetype)uniqueStringsWithContentsOfURLString:(NSString *)urlString;
For creating lists class SCUniqueStrings implements the following class methods:
+ (instancetype)uniqueStringsWithName:(NSString *)name;
+ (instancetype)uniqueStringsWithString:(NSString *)string;
+ (instancetype)uniqueStringsWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)uniqueStringsWithArray:(
SCArray *)array;
+ (instancetype)uniqueStringsWithStrings:(
SCStrings *)strings;
+ (instancetype)uniqueStringsWithUniqueStrings:(
SCUniqueStrings *)uniqueStrings;
+ (instancetype)uniqueStrings;
- Class method uniqueStringsWithName: returns an unique strings list created by using the specified list name:
2016-08-25 11:54:17.175 libtest[12416:1086458] Unique strings list "Secret List" count=0, case sensitive, strong mode: (
)
- Class method uniqueStringsWithString: returns an uniaue strings list created by using the specified existing string:
2016-08-25 11:54:50.474 libtest[12431:1086670] Unique strings list count=1, case sensitive, strong mode: (
Sample String
)
- Class method uniqueStringsWithCollection: returns an unique strings list created by using the specified existing collection of any supported type. If the collection contains the duplicated strings, the repeated strings will be ignored. If the collection contains the non-string objects, then the error SCL-20066 is occurs.
2016-08-25 11:57:51.089 libtest[12486:1087829] Unique strings list count=2, case sensitive, strong mode: (
String 00
String 01
)
- Class method uniqueStringsWithArray: creates a new unique strings list by using strings from a given array. Duplicated strings from a source array will be ignored. If the array contains a non-string objects then the error SCL-20066 is occurs.
2017-06-22 16:43:15.929824+0300 libtest[57634:13280827] Unique strings list count=2, case sensitive, strong mode: (
String 10
String 20
)
- Class method uniqueStringsWithStrings: returns an unique strings list created by using the specified existing strings list. Duplicated strings from the source list will be ignored.
2016-08-25 11:57:08.451 libtest[12470:1087551] Unique strings list count=2, case sensitive, modified: (
String 00
String 10
)
- Class method uniqueStringsWithUniqueStrings: returns an unique strings list created by using the specified existing unique strings list:
[source addString:@"String 00"];
[source addString:@"String 02"];
NSLog( @"%@", strings);
2016-08-25 11:59:00.013 libtest[12506:1088434] Unique strings list count=2, case sensitive, strong mode, modified: (
String 00
String 02
)
- Class method uniqueStrings returns am empty unnamed unique strings list created by using the default settings:
2016-08-25 11:59:41.193 libtest[12521:1088767] Unique strings list count=0, case sensitive, strong mode: (
)
Initializing lists
Class SCUniqueStrings declares the following initializing methods:
Coping lists
Class SCUniqueStrings implements the following advanced methods for coping class instances:
- Method setUniqueStrings: replaces the content and settings of the receiving unique strings list by using the specified existing unique strings list:
[strings addString:@"Line 00"];
[strings addString:@"Line 01"];
NSLog( @"%@", strings);
[source addString:@"String 00"];
[source addString:@"String 10"];
[source addString:@"String 20"];
NSLog( @"%@", strings);
2016-08-25 12:01:07.514 libtest[12548:1089323] Unique strings list count=2, case sensitive, strong mode, modified: (
Line 00
Line 01
)
2016-08-25 12:01:07.514 libtest[12548:1089323] Unique strings list count=3, case sensitive, strong mode, modified: (
String 00
String 10
String 20
)
Comparing lists
Class SCUniqueStrings extends the parent class SCStrings by declaring the following comparing methods:
- Method isEqualToUniqueStrings: returns a boolean value that indicates whether the contents of the receiving unique strings list are equal to the contents of another given unique strings list:
Converting lists
Class SCUniqueStrings implements the following advanced converting properties:
@property (nonatomic, readonly, assign)
SCStrings *strings;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
- Property strings returns the class SCStrings instance with the copy of all receiving unique strings list strings.
- Property orderedSet returns the library ordered set (class SCOrderedSet instance) with the copy of all receiving unique strings list strings.
- Property foundationOrderedSet returns the standard ordered set (class NSOrderedSet instance) with the copy of all receiving unique strings list strings.
Deriving new unique strings lists
Class SCUniqueStrings implements the following methods for creating new unique strings lists by using existing unique strings lists:
- (instancetype)uniqueStringsByAddingString:(NSString *)string;
- (instancetype)uniqueStringsByAddingCollection:(
id<
SCCollection>)collection;
- (instancetype)uniqueStringsByAddingStringsFromArray:(
SCArray *)array;
- (instancetype)uniqueStringsByAddingArray:(
SCArray *)array;
- (instancetype)uniqueStringsByAddingStrings:(
SCStrings *)strings;
- (instancetype)uniqueStringsByAddingUniqueStrings:(
SCUniqueStrings *)uniqueStrings;
- Method uniqueStringsByAddingString: returns a new unique strings list that contains strings from the receiving unique strings list and a given string:
NSLog( @"%@", [strings uniqueStringsByAddingString:@"New String"]);
2017-06-23 15:31:46.434592+0300 libtest[60277:14116924] Unique strings list count=2, case sensitive, strong mode, modified: (
Source String
New String
)
- Method uniqueStringsByAddingCollection: creates a new unique strings list that contains strings from the receiving unique strings list and a given collection of any supported type. If a collection contains non-string objects then error SCL-20066 is occurs.
NSLog( @"%@", [strings uniqueStringsByAddingCollection:@[ @"String 00", @"String 10"]]);
2017-06-23 21:00:41.294122+0300 libtest[61185:14379816] Unique strings list count=3, case sensitive, strong mode, modified: (
Source String
String 00
String 10
)
- Methods uniqueStringsByAddingStringsFromArray: and uniqueStringsByAddingArray: return unique strings list that contains strings from the receiving unique strings list and a given array. If an array contains non-string objects then error SCL-2006 is occurs.
NSLog( @"%@", [strings uniqueStringsByAddingArray:array]);
2017-06-23 21:36:29.901442+0300 libtest[61594:14430406] Unique strings list count=3, case sensitive, strong mode, modified: (
Source String
String 30
String 40
)
- Method uniqueStringsByAddingStrings: creates an unique strings list that contains strings from the receiving unique strings list and a given strings list:
NSLog( @"%@", [strings uniqueStringsByAddingStrings:source]);
2017-06-23 22:09:20.311124+0300 libtest[61960:14454098] Unique strings list count=2, case sensitive, strong mode, modified: (
Source String
Advanced String
)
- Method uniqueStringsByAddingUniqueStrings: returns unique strings list that contains strings from the receiving unique strings list and a given another unique strings list:
NSLog( @"%@", [strings uniqueStringsByAddingUniqueStrings:source]);
2017-06-26 22:01:53.136475+0300 libtest[66204:17052550] Unique strings list count=2, case sensitive, strong mode, modified: (
Source String
New String
)
Texts
Class SCText extends the parent class SCStrings functionality by adding to a strings list methods for working with text blocks - continuous groups of strings within the list. Class SCText provides the operations such as add, insert, delete, copy, move text blocks and so on. This functionality is a standard features set of the modern text processing software.
This section describes the methods of work with texts and text blocks on the assumption that you are already familiar with basic functionality, implemented in the class SCStrings.
Creating texts
Class SCText declares the following class methods for creating class instances by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)textWithCoder:(NSCoder *)coder;
+ (instancetype)textWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)textWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)textWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)textWithStream:(
SCStream *)stream;
+ (instancetype)textWithFileStream:(NSString *)path;
+ (instancetype)textWithData:(NSData *)data;
+ (instancetype)textWithContentsOfFile:(NSString *)path;
+ (instancetype)textWithContentsOfURL:(NSURL *)url;
+ (instancetype)textWithContentsOfURLString:(NSString *)urlString;
For creating texts class SCText implements the following class methods:
+ (instancetype)textWithName:(NSString *)name;
+ (instancetype)textWithString:(NSString *)string;
+ (instancetype)textWithStrings:(
SCStrings *)strings;
+ (instancetype)textWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)textWithArray:(
SCArray *)array;
+ (instancetype)textWithText:(
SCText *)text;
+ (instancetype)text;
- Class method textWithName: returns an empty text created by using the specified text name:
2016-08-25 15:46:06.093 libtest[13585:1207335] Text "libtest.m" count=0, case sensitive: (
)
- Class method textWithString: returns a text created by using the specified existing string:
2016-08-25 15:54:55.634 libtest[13621:1214447] Text count=1, case sensitive: (
#import <unistd.h>
)
- Class method textWithStrings: returns a text created by using the specified existing strings list:
[strings
addString:@"#import <Foundation/Foundation.h>"];
NSLog( @"%@", text);
2016-08-25 15:57:28.111 libtest[13655:1215774] Text "libtest.m" count=5, case sensitive, modified: (
#import <unistd.h>
#import <fcntl.h>
#import <stdio.h>
#import <Foundation/Foundation.h>
#import <scl/scl.h>
)
- Class method textWithCollection: returns a text created by using the specified existing collection of any supported type. If the source collection contains non-string objects, then the error SCL-20066 is occurs.
[array addObject:@"#define SN @\"/tmp/stream.dat\""];
[array addObject:@"#define SF @\"/tmp/serial.plist\""];
[array addObject:@"#define DF @\"/tmp/data.plist\""];
NSLog( @"%@", text);
2016-08-25 16:02:27.150 libtest[13694:1217695] Text "libtest.m" count=3, case sensitive: (
#define SN @"/tmp/stream.dat"
#define SF @"/tmp/serial.plist"
#define DF @"/tmp/data.plist"
)
- Class method textWithArray: returns a new text that contains strings from a given array. If an array contains non-string objects then error SCL-20066 is occurs.
2017-06-27 00:01:35.398922+0300 libtest[66698:17127012] Text count=2, case sensitive: (
String 30
String 40
)
- Class method textWithText: returns a text created by using the specified existing text:
[source
addString:@"int main (int argc, const char * argv[]) {"];
[source
addString:@" NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];"];
NSLog( @"%@", text);
2016-08-25 16:04:34.483 libtest[13731:1218850] Text "libtest.m" count=3, case sensitive, modified: (
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
}
)
- Class method text returns an empty unnamed text created by using the default settings:
2016-08-25 16:05:20.724 libtest[13746:1219175] Text count=0, case sensitive: (
)
Initializing texts
Class SCText extends the parent class by declaring the following initialization methods:
- (instancetype)initWithText:(
SCText *)text;
- Method initWithText: initializes a text using the specified existing text:
Coping texts
Class SCText declares the following additional coping methods:
- (void)setText:(
SCText *)text;
- Method setText: replaces the content and settings of the receiving text by using the specified existing text:
Comparing texts
Class SCText implements the following comparing methods:
- (BOOL)isEqualToText:(
SCText *)text;
- Method isEqualToText: returns a boolean value that indicates whether the contents of the receiving text are equal to the contents of another given text.
Deriving new texts
Class SCText declares the following methods for deriving new texts by using existing texts:
- (instancetype)textByAddingString:(NSString *)string;
- (instancetype)textByAddingCollection:(
id<
SCCollection>)collection;
- (instancetype)textByAddingStringsFromArray:(
SCArray *)array;
- (instancetype)textByAddingArray:(
SCArray *)array;
- (instancetype)textByAddingStrings:(
SCStrings *)strings;
- (instancetype)textByAddingText:(
SCText *)text;
- Method textByAddingString: returns a text that contains strings from the receiving text and a given string:
NSLog( @"%@", [text textByAddingString:@"New string"]);
2017-06-28 13:49:28.869424+0300 libtest[69644:18425058] Text count=3, case sensitive, modified: (
First string
Second string
New string
)
- Method textByAddingCollection: creates a text that contains strings from the receiving text and a given collection of any supported type. If a collection contains non-string objects then error SCL-20066 is occurs.
NSLog( @"%@", [text textByAddingCollection:@[ @"Advanced string", @"New string"]]);
2017-06-28 15:18:07.538840+0300 libtest[70065:18483791] Text count=4, case sensitive, modified: (
First string
Second string
Advanced string
New string
)
- Methods textByAddingStringsFromArray: and textByAddingArray: return new text that contains strings from the receiving text and a given array. If an array contains non-string objects then error SCL-20066 is occurs. SCL-20066.
NSLog( @"%@", [text textByAddingArray:array]);
2017-06-28 15:56:43.597651+0300 libtest[70451:18512950] Text count=4, case sensitive, modified: (
First string
Second string
String 30
String 40
)
- Method textByAddingStrings: creates a new text that contains strings from the receiving text and a given strings list:
NSLog( @"%@", [text textByAddingStrings:source]);
2017-06-28 16:45:53.254867+0300 libtest[70910:18550263] Text count=4, case sensitive, modified: (
First string
Second string
Line 10
Line 20
)
- Method textByAddingText: returns a text that contains strings from the receiving and a given texts:
NSLog( @"%@", [text textByAddingText:source]);
NSLog( @"%@", [text textByAddingText:source]);
Converting texts
Class SCText implements the following advanced converting properties:
@property (nonatomic, readonly, assign)
SCStrings *strings;
- Property strings returns the strings list with the copy of all receiving text strings.
- Property uniqueStrings returns the unique strings list with the copy of all receiving text strings. If the receiving text contains the duplicated strings, this strings do not include in the result list.
Adding text blocks
Class SCText declares the following methods for adding text blocks:
- Method addText: adds into the receiving text the strings from the specified existing text:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:29:36.666 libtest[14254:1266732] Text count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-25 17:29:36.666 libtest[14254:1266732] Text count=5, case sensitive, modified: (
String 00
String 01
=========
String 10
String 11
)
- Method insertText:atIndex: inserts the strings from a given text into the receiving text at a given index:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:30:48.243 libtest[14277:1267118] Text count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-25 17:30:48.243 libtest[14277:1267118] Text count=6, case sensitive, modified: (
String 00
=========
String 10
String 11
=========
String 01
)
Removing text blocks
Class SCText implements the following methods for removing text blocks from the text:
- (void)removeAllText;
- (void)removeTextInRange:(NSRange)range;
- (void)removeTextWithSubstring:(NSString *)substring;
- (void)removeTextWithoutSubstring:(NSString *)substring;
- (void)removeSubstring:(NSString *)substring;
- (
SCText *)cutTextInRange:(NSRange)range;
- Method removeAllText removes all strings from the receving text:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:46:39.848 libtest[14387:1275208] Text count=2, case sensitive, modified: (
String 00
String 01
)
2016-08-25 17:46:39.849 libtest[14387:1275208] Text count=0, case sensitive, modified: (
)
- Method removeTextInRange: removes strings in the specified range from the receiving text. If the method detects the incorrect strings range, then the error SCL-20073 is occurs. Если методу передан некорректный диапазон, генерируется исключительная ситуация SCL-20073.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:47:29.378 libtest[14403:1275561] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-25 17:47:29.378 libtest[14403:1275561] Text count=2, case sensitive, modified: (
String 00
String 03
)
- Method removeTextWithSubstring: removes all occurrences in the text of the strings which contain the specified substring:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:49:04.118 libtest[14426:1276155] Text count=4, case sensitive, modified: (
String 00
String 10
String 11
String 20
)
2016-08-25 17:49:04.118 libtest[14426:1276155] Text count=2, case sensitive, modified: (
String 00
String 20
)
- Method removeTextWithoutSubstring: removes all occurrences in the text of the strings which not contain the specified substring:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:50:16.963 libtest[14445:1276545] Text count=4, case sensitive, modified: (
String 00
String 10
String 11
String 20
)
2016-08-25 17:50:16.963 libtest[14445:1276545] Text count=2, case sensitive, modified: (
String 10
String 11
)
- Method removeSubstring: removes all occurences in the text of the specified substring:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-25 17:58:06.016 libtest[14486:1279995] Text count=4, case sensitive, modified: (
File 00 Line 04
File 00 Line 08
Unit 10
Unit 10
)
2016-08-25 17:58:06.016 libtest[14486:1279995] Text count=4, case sensitive, modified: (
Line 04
Line 08
Unit 10
Unit 10
)
- Method cutTextInRange: returns the text in the specified range and removes this text. If the incorrect strings range is detected, then the error SCL-20073 is occurs.
NSLog( @"%@", text);
NSLog( @"%@", text);
NSLog( @"%@", block);
2016-08-26 11:46:09.630 libtest[5117:300164] Text count=4, case sensitive, modified: (
String 00
String 10
String 20
String 30
)
2016-08-26 11:46:09.630 libtest[5117:300164] Text count=2, case sensitive, modified: (
String 00
String 30
)
2016-08-26 11:46:09.630 libtest[5117:300164] Text count=2, case sensitive, modified: (
String 10
String 20
)
- Method removeText: removes all occurrences in the receiving text of a given text block:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 11:49:48.523 libtest[5156:302760] Text count=6, case sensitive, modified: (
String 01
String 02
String 03
String 04
String 02
String 03
)
2016-08-26 11:49:48.523 libtest[5156:302760] Text count=2, case sensitive, modified: (
String 01
String 04
)
Replacing text blocks
Class SCText declares the following replacing methods:
- (void)replaceTextInRange:(NSRange)range withText:(
SCStrings *)text;
- (void)replaceTextInRange:(NSRange)range withCollection:(
id<
SCCollection>)collection;
- Method replaceTextInRange:withText: replaces the text in the specified range with the specified new text. If the method detects the incorrect strings range, then the SCL-20073 is occurs.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 13:15:53.283 libtest[5522:345794] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 13:15:53.283 libtest[5522:345794] Text count=4, case sensitive, modified: (
String 00
Line A
Line B
String 03
)
- Method replaceTextInRange:withCollection: replaces the text in the specified range with the strings from the specified collection of any supported type:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 13:17:29.744 libtest[5548:346447] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 13:17:29.745 libtest[5548:346447] Text count=4, case sensitive, modified: (
String 00
Message 01
Message 02
String 03
)
During the method execution can be occurs the following errors:
- Method replaceText:withText: replaces the all occurrences in the text of a given text block with the specified text block:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 13:40:55.037 libtest[5690:358097] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 13:40:55.037 libtest[5690:358097] Text count=4, case sensitive, modified: (
String 00
Code 01
Code 02
String 03
)
Coping and moving text blocks
Class SCText extends the parent class coping and moving methods by implements the following own methods:
- (void)exchangeTextInRange:(NSRange)source withTextInRange:(NSRange)destination;
- (void)duplicateTextInRange:(NSRange)range;
- (void)duplicateStringsInRange:(NSRange)range;
- (void)copyTextInRange:(NSRange)range toIndex:(
SCIndex)destination;
- (void)moveTextInRange:(NSRange)range toIndex:(
SCIndex)destination;
- (void)forwardMoveTextInRange:(NSRange)range steps:(
SCIndex)steps;
- (void)forwardMoveTextInRange:(NSRange)range;
- (void)backwardMoveTextInRange:(NSRange)range steps:(
SCIndex)steps;
- (void)backwardMoveTextInRange:(NSRange)range;
- (void)moveToFirstPositionTextInRange:(NSRange)range;
- (void)moveToLastPositionTextInRange:(NSRange)range;
- Method exchangeTextInRange:withTextInRange: swaps the specified text ranges. If one or both strings ranges are incorrect, then the error SCL-20073 is occurs. If the specified ranges are intersected (one range includes all or part of other range), then the exception SCL-20076 is throwing.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 13:58:47.563 libtest[5889:370805] Text count=5, case sensitive, modified: (
String 00
String 01
String 02
String 03
String 04
)
2016-08-26 13:58:47.563 libtest[5889:370805] Text count=5, case sensitive, modified: (
String 03
String 04
String 02
String 00
String 01
)
- Method duplicateTextInRange: duplicates the text with the specified text range. If the method detects the incorrect strings range, then the error SCL-20073 is occurs.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:00:57.326 libtest[5917:371953] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:00:57.326 libtest[5917:371953] Text count=6, case sensitive, modified: (
String 00
String 01
String 02
String 01
String 02
String 03
)
- Method duplicateStringsInRange: duplicates the strings in the specified range. Error SCL-20073 is occurs if the specified strings range is incorrect.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:11:54.670 libtest[5947:376372] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:11:54.670 libtest[5947:376372] Text count=6, case sensitive, modified: (
String 00
String 01
String 01
String 02
String 02
String 03
)
- Method copyTextInRange:toIndex: copies the text in the specified range to the specified index:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:13:42.945 libtest[5969:377490] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:13:42.945 libtest[5969:377490] Text count=6, case sensitive, modified: (
String 00
String 01
String 02
String 00
String 01
String 03
)
Method can throwing the following exceptions:
- Method moveTextInRange:toIndex: moves the text in the specified range to the specified index:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:14:40.893 libtest[5991:378346] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:14:40.894 libtest[5991:378346] Text count=4, case sensitive, modified: (
String 02
String 00
String 01
String 03
)
During method execution can be occured the following errors:
- Method forwardMoveTextInRange:steps: moves the text in the specified range on the specified number of lines up. If during moving the block reached the beginning of the text, movement operation stops. Error SCL-20073 may be occurs if the specified strings range is incorrect.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:16:55.120 libtest[6069:380309] Text count=5, case sensitive, modified: (
String 00
String 01
String 02
String 03
String 04
)
2016-08-26 14:16:55.120 libtest[6069:380309] Text count=5, case sensitive, modified: (
String 00
String 03
String 04
String 01
String 02
)
- Method forwardMoveTextInRange: (SCText) moves the text in the specified range up one line. If the specified strings range is incorrect, then the error SCL-20073 is occurs.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:17:47.431 libtest[6087:381042] Text count=5, case sensitive, modified: (
String 00
String 01
String 02
String 03
String 04
)
2016-08-26 14:17:47.431 libtest[6087:381042] Text count=5, case sensitive, modified: (
String 00
String 01
String 03
String 04
String 02
)
- Method backwardMoveTextInRange:steps: moves the text in the specified range to the specified number of lines down. Upon reaching the end of the text movement process stops. If the specified strings range is incorrect, then the error SCL-20073 is occurs.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:18:47.713 libtest[6109:382063] Text count=5, case sensitive, modified: (
String 00
String 01
String 02
String 03
String 04
)
2016-08-26 14:18:47.714 libtest[6109:382063] Text count=5, case sensitive, modified: (
String 02
String 03
String 00
String 01
String 04
)
- Method backwardMoveTextInRange: moves the text in the specified range to the one line down. Error SCL-20073 may be occurs if the specified strings range is incorrect.
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:19:44.506 libtest[6129:382844] Text count=5, case sensitive, modified: (
String 00
String 01
String 02
String 03
String 04
)
2016-08-26 14:19:44.507 libtest[6129:382844] Text count=5, case sensitive, modified: (
String 02
String 00
String 01
String 03
String 04
)
- Method moveToFirstPositionTextInRange: moves the text in the specified range to the top of the text:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:22:47.602 libtest[6158:384433] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:22:47.602 libtest[6158:384433] Text count=4, case sensitive, modified: (
String 01
String 02
String 00
String 03
)
- Method moveToLastPositionTextInRange: moves the text in the specified range to the bottom of the text:
NSLog( @"%@", text);
NSLog( @"%@", text);
2016-08-26 14:24:30.248 libtest[6179:385644] Text count=4, case sensitive, modified: (
String 00
String 01
String 02
String 03
)
2016-08-26 14:24:30.248 libtest[6179:385644] Text count=4, case sensitive, modified: (
String 00
String 03
String 01
String 02
)
Text access
Class SCText implements the following methods for accessing to the text:
- (
SCText *)textInRange:(NSRange)range;
- Method textInRange: returns a text containing the strings from the receiving text in the specified range. If the range is incorrect, then the error SCL-20073 is occurs.
NSLog( @"%@", [text textInRange:NSMakeRange(1, 2)]);
2016-08-26 15:44:52.005 libtest[6677:432494] Text count=2, case sensitive, modified: (
String 01
String 02
)
Finding and selecting text
Class SCText implemens the following methods for finding and selecting texts:
- (
SCTextIndex *)textIndexOfSubstring:(NSString *)substring;
- (
SCArray *)textIndexesOfSubstring:(NSString *)substring;
Please note that the work of these methods depends on the value of the property caseInsensitive.
- Method containsText: returns a Boolean value that indicates whether a given text is present in the receiving text:
NSLog( @"%d", [text containsText:block]);
NSLog( @"%d", [text containsText:block]);
2016-08-29 13:07:35.722 libtest[3822:832971] 1
2016-08-29 13:07:35.722 libtest[3822:832971] 0
- Method rangeOfText: returns the range of the specified text. If the required text does not exists in the receiving text, then method returns empty range (0, 0).
NSLog( @"(%d, %d)", [text rangeOfText:block]);
NSLog( @"(%d, %d)", [text rangeOfText:block]);
2016-08-29 13:09:51.106 libtest[3847:834973] (1, 2)
2016-08-29 13:09:51.106 libtest[3847:834973] (0, 0)
- Method indexOfText: returns the index of the first occurrence of the specified text into the receiving text. If the required text not found, then the method returns value NSNotFound.
NSLog( @"%d", [text indexOfText:block]);
NSLog( @"%d", [text indexOfText:block]);
2016-08-29 13:12:43.591 libtest[3870:837964] 1
2016-08-29 13:12:43.591 libtest[3870:837964] -1
- Method countOfText: returns the count of occurrences of the specified text into the receiving text:
NSLog( @"%d", [text countOfText:block]);
NSLog( @"%d", [text countOfText:block]);
2016-08-29 13:16:13.767 libtest[3899:842027] 2
2016-08-29 13:16:13.767 libtest[3899:842027] 0
- Method countOfCollection: returns the count of occurrences of the the strings from the specified collection of any supported type into the receiving list. This method is equals to the method countOfText:.
- Method indexesOfText: returns an array with the indexes of the all occurrences of the specified text into the receiving text:
NSLog( @"%@", [text indexesOfText:block]);
NSLog( @"%@", [text indexesOfText:block]);
2016-08-29 13:19:15.702 libtest[3939:845663] Array count=2: (
"1",
"4"
)
2016-08-29 13:19:15.702 libtest[3939:845663] Array count=0:
)
- Method textIndexOfSubstring: returns a text index of the first occurrence of the specified substring:
NSLog( @"%@", [text textIndexOfSubstring:@"ing 02"]);
NSLog( @"%@", [text textIndexOfSubstring:@"ing 04"]);
2016-08-29 13:25:29.845 libtest[3970:853405] (2, 3)
2016-08-29 13:25:29.845 libtest[3970:853405] (null)
- Method textIndexesOfSubstring: returns an array with text indexes of the all occurrences of the specified substring:
NSLog( @"%@", [text textIndexesOfSubstring:@"ing 02"]);
NSLog( @"%@", [text textIndexesOfSubstring:@"ing 04"]);
2016-08-29 13:40:10.715 libtest[3997:865041] Array count=2: (
"(2, 3)",
"(5, 3)"
)
2016-08-29 13:40:10.715 libtest[3997:865041] Array count=0:
)
Class SCText extends the strings selecting features of the parent class SCStrings by implementing the following own methods:
- (
SCText *)textWithSubstring:(NSString *)substring;
- (
SCText *)textWithoutSubstring:(NSString *)substring;
Please note that the work of these methods depends on the value of the property caseInsensitive.
- Method textWithSubstring: returns a text with the strings from the receiving text which contains the specified substring:
NSLog( @"%@", [text textWithSubstring:@"ing 0"]);
2016-08-29 13:52:03.303 libtest[4047:873961] Text count=2, case sensitive, modified: (
String 00
String 01
)
- Method textWithoutSubstring: returns a text with the strings from the receiving text which not contains the specified substring:
NSLog( @"%@", [text textWithoutSubstring:@"ing 0"]);
2016-08-29 14:13:54.307 libtest[4093:893355] Text count=2, case sensitive, modified: (
String 10
String 11
)
Text files
Class SCTextFile extends the parent class SCText functionality by adding methods for working with disk files. Text files allow reading text from files, writing text to the files and text blocks reading and writing operations. As a child of classes SCText and SCStrings, instances of class SCTextFile allows all parent classes functionality.
Class instance properties
Class SCTextFile declares the following most important properties:
@property (nonatomic, readonly, retain) NSString *path;
@property (nonatomic, readonly, assign) BOOL modified;
- Property path returns the path to the loaded text file. Class instance changes value of this property after text file reading or writing. Note: property path does not equals to the property name, which contains the text name instead the name of the text file.
- Class SCTextFile inherits from the classes SCStrings and SCText the property modified. But in the parent classes this property uses only for text modification indicator.
In the class SCTextFile instances the property modified can be used for tracking modifications of loaded text files. After successfully writing operation text file sets the value of this property to the NO. Also the value NO assignes to the property by using the reset methods, which discards any changes in the text after loading from disk file. See details in the reading and writing methods section.
Creating text files
Class SCTextFile declares the following class methods for creating class instances by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)textFileWithCoder:(NSCoder *)coder;
+ (instancetype)textFileWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)textFileWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)textFileWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)textFileWithStream:(
SCStream *)stream;
+ (instancetype)textFileWithFileStream:(NSString *)path;
+ (instancetype)textFileWithData:(NSData *)data;
+ (instancetype)textFileWithContentsOfFile:(NSString *)path;
+ (instancetype)textFileWithContentsOfURL:(NSURL *)url;
+ (instancetype)textFileWithContentsOfURLString:(NSString *)urlString;
For creating text files class SCTextFile implements the following class methods:
+ (instancetype)textFileWithName:(NSString *)name;
+ (instancetype)textFileWithString:(NSString *)string;
+ (instancetype)textFileWithStrings:(
SCStrings *)strings;
+ (instancetype)textFileWithCollection:(
id<
SCCollection>)collection;
+ (instancetype)textFileWithArray:(
SCArray *)array;
+ (instancetype)textFileWithText:(
SCText *)text;
+ (instancetype)textFileWithTextFile:(
SCTextFile *)textFile;
+ (instancetype)textFileWithName:(NSString *)name stream:(
SCStream *)stream;
+ (instancetype)textFileFromStream:(
SCStream *)stream;
+ (instancetype)textFileWithName:(NSString *)name path:(NSString *)path;
+ (instancetype)textFileWithPath:(NSString *)path;
+ (instancetype)textFile;
- Class method textFileWithName: returns an empty text file created by using the specified text file name. The class instance is not linked to the disk file.
- Class method textFileWithString: returns a text file created by using the specified existing string. The class instance is not linked to the disk file.
- Class method textFileWithStrings: returns a text file created by using the specified existing text. The instance is not linked to the disk file.
- Class method textFileWithCollection: returns a text file created by using the specified existing collection of any supported type. Created class instance is not link to the disk file.
- Class method textFileWithArray: returns a new text file created by using strings from a given array. If an array contains non-string objects then error SCL-20066 is occurs.
- Class method textFileWithText: returns a text file created by using the specified existing text. Created instace is not link to the disk file.
- Class method textFileWithTextFile: returns a text file created by using the specified existing text file:
2016-08-30 10:54:27.015 libtest[2178:260503] Text file "paths" with path /etc/paths, strings=5, case sensitive: (
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
)
- Class method textFileWithName:stream: returns a text file created by using the specified text file name and input stream:
2016-08-30 10:57:33.962 libtest[2205:262097] Text file "networks" with path /etc/networks, strings=4, case sensitive: (
##
# Networks Database
##
loopback 127 loopback-net
)
- Class method textFileFromStream: returns a text file created by using the specified input stream:
2016-08-30 11:12:08.944 libtest[2255:268444] Text file with path /etc/networks, strings=4, case sensitive: (
##
# Networks Database
##
loopback 127 loopback-net
)
- Class method textFileWithName:path: returns a text file created by using the specified text file name and file path:
2016-08-30 11:14:58.937 libtest[2279:269946] Text file "paths" with path /etc/paths, strings=5, case sensitive: (
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
)
- Class method textFileWithPath: returns a text file created by using the specified file path:
2016-08-30 11:17:55.231 libtest[2301:271717] Text file with path /etc/paths, strings=5, case sensitive: (
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
)
- Class method textFile returns an empty unnamed text file without linking to the disk file.
Initializing text files
Class SCTextFile implements the following initialization methods (additionally to initialization methods of the parent classes SCText and SCStrings):
- (instancetype)initWithTextFile:(
SCTextFile *)textFile;
- (instancetype)initWithName:(NSString *)name stream:(
SCStream *)stream;
- (instancetype)initFromStream:(
SCStream *)stream;
- (instancetype)initWithName:(NSString *)name path:(NSString *)path;
- (instancetype)initWithPath:(NSString *)path;
- Method initWithTextFile: initializes a text file using the speified existing text file.
- Method initWithName:stream: initializes a text file using the specified text file name and input stream.
- Method initFromStream: initializes a text file using the specified input stream.
- Method initWithName:path: initializes a text file using the specified text file name and file path.
- Method initWithPath: initializes a text file using the specified file path.
Coping text files
Class SCTextFile declares the following methods for coping class instances:
- Method setTextFile: replaces the content and settings of the receiving text by using the specified existing text.
Deriving New Text Files
Class SCTextFile implements the following methods for creating new text files by using strings from the existing text files:
- (instancetype)textFileByAddingString:(NSString *)string;
- (instancetype)textFileByAddingCollection:(
id<
SCCollection>)collection;
- (instancetype)textFileByAddingStringsFromArray:(
SCArray *)array;
- (instancetype)textFileByAddingArray:(
SCArray *)array;
- (instancetype)textFileByAddingStrings:(
SCStrings *)strings;
- (instancetype)textFileByAddingText:(
SCText *)text;
- (instancetype)textFileByAddingTextFile:(
SCTextFile *)textFile;
- (instancetype)textFileByAddingTextFileWithPath:(NSString *)path;
- Method textFileByAddingString: returns a text file that contains strings from the receiving text file and a given string:
NSLog( @"%@", [textFile textFileByAddingString:@"Additional string"]);
2017-06-28 23:07:11.849495+0300 libtest[73142:18769203] Text file without path, strings=3, case sensitive, modified: (
First string
Second string
Additional string
)
- Method textFileByAddingCollection: creates a text file that contains strings from the receiving text file and a given collection of any supported type. If a collection contains non-string objects, then error SCL-20066 is occurs.
NSLog( @"%@", [textFile textFileByAddingCollection:@[ @"New string", @"Advanced string"]]);
2017-06-28 23:33:14.288261+0300 libtest[73649:18790814] Text file without path, strings=4, case sensitive, modified: (
First string
Second string
New string
Advanced string
)
- Methods textFileByAddingStringsFromArray: and textFileByAddingArray: return a new text file that contains strings from the receiving text file and a given array. If an array contains non-string objects then error SCL-20066 is occurs.
NSLog( @"%@", [textFile textFileByAddingArray:array]);
2017-06-29 09:41:25.690001+0300 libtest[74510:19109223] Text file without path, strings=4, case sensitive, modified: (
First string
Second string
String 10
String 20
)
- Method textFileByAddingStrings: creates a new text file that contains strings from the receiving text file and a given strings list:
NSLog( @"%@", [textFile textFileByAddingStrings:strings]);
2017-06-29 09:56:18.324103+0300 libtest[74884:19119375] Text file without path, strings=3, case sensitive, modified: (
First string
Second string
New string
)
- Method textFileByAddingText: returns a text file that contains strings from the receiving text file and a given text:
NSLog( @"%@", [textFile textFileByAddingText:text]);
2017-06-29 10:46:51.246168+0300 libtest[75256:19151372] Text file without path, strings=3, case sensitive, modified: (
First string
Second string
Advanced string
)
- Method textFileByAddingTextFile: creates a text file that contains strings from the receiving and a given text files:
NSLog( @"%@", [textFile textFileByAddingTextFile:source]);
2017-06-29 11:01:31.631964+0300 libtest[75595:19165192] Text file without path, strings=3, case sensitive, modified: (
First string
Second string
Additional string
)
- Method textFileByAddingTextFileWithPath: returns a new text file that contains strings from the receiving text file and a text file with a given path:
NSLog( @"%@", [textFile textFileByAddingTextFileWithPath:@"/etc/nanorc"]);
2017-06-29 11:22:07.543742+0300 libtest[75970:19180361] Text file without path, strings=3, case sensitive, modified: (
First string
Second string
set nowrap
)
Converting text files
Class SCTextFile implements the following converting properties:
@property (nonatomic, readonly, assign)
SCStrings *strings;
@property (nonatomic, readonly, assign)
SCText *text;
- Property strings returns the strings list with the copy of all receiving text file strings.
- Property uniqueStrings returns the unique strings list with the copy of receiving text file strings with ignoring the duplicated strings.
- Property text returns the text with the copy of all receiving text file strings.
Reading and writing text files
Class SCTextFile declares the following methods for reading text files:
- (BOOL)readFromStream:(
SCStream *)stream;
- (BOOL)readWithPath:(NSString *)path;
- (BOOL)read;
- (BOOL)reset;
All methods return the value YES if the reading operation is successfully complited, otherwise return the value NO.
- Method readFromStream: erases the current content and loads the content of the specified stream into the receiving text file. During execution the method calls the event handlers text:willReadFromStream: and text:didFinishReadingFromStream: of the delegate object. If the reading operation is successfully, the value of the property modified sets to NO.
2016-08-30 14:43:39.760 libtest[3433:395093] Text file with path /etc/paths, strings=5, case sensitive: (
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
)
Method can occurs the following errors:
- SCL-20062 - incorrect input stream (stream does not exists or does not support read operations)
- SCL-20063 - receiving class instance is read only
- SCL-20065 - stream does not open
- SCL-20067 - stream reading error
- Method readWithPath: removes the current content and loads the content of the file with the specified path into the receiving text file. Method calls the event handlers text:willReadWithPath: and text:didFinishReadingWithPath: of the delegate object. If the reading operation is successfully complited, then the class instance property modified sets to the value NO.
2016-08-30 14:47:04.004 libtest[3455:397299] Text file with path /etc/networks, strings=4, case sensitive: (
##
# Networks Database
##
loopback 127 loopback-net
)
Method can throws the following exceptions:
- Method read loads the content of the text file from the file with path from the property path.
- Method reset discards all receiving text changes and reload content of the file. If the operations is successfully complited, the property modified sets to the value NO. Also this method calls the event handlers willResetText: and didFinishResettingText: of the delegate object.
NSLog( @"%@", textFile);
[textFile
addString:@"## Advanced Settings"];
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-08-30 14:55:15.946 libtest[3489:402189] Text file with path /etc/networks, strings=4, case sensitive: (
##
# Networks Database
##
loopback 127 loopback-net
)
2016-08-30 14:55:15.946 libtest[3489:402189] Text file with path /etc/networks, strings=5, case sensitive, modified: (
##
# Networks Database
##
loopback 127 loopback-net
## Advanced Settings
)
2016-08-30 14:55:15.946 libtest[3489:402189] Text file with path /etc/networks, strings=4, case sensitive: (
##
# Networks Database
##
loopback 127 loopback-net
)
Class SCTextFile implements the following writing methods:
- (BOOL)writeTextToStream:(
SCStream *)stream;
- (BOOL)writeWithPath:(NSString *)path;
- (BOOL)write;
- (BOOL)appendToFileWithPath:(NSString *)path;
- Method writeTextToStream: saves the content of the receiving instance to the specified output stream. Method calls the event handlers text:willWriteToStream: and text:didFinishWritingToStream: of the delegate object. After the finishing the class instance property modified is set to value NO.
NSLog( @"Writing to stream: %d", [textFile writeTextToStream:stream]);
2016-08-30 15:01:52.872 libtest[3560:405779] Writing to stream: 1
After execution of this sample the file /tmp/text.txt will be contains the following strings: String 00
String 01
String 02
Method can occurs the following errors:
- SCL-20065 - stream does not open
- SCL-20071 - stream does not exists or does not supports writing operations
- SCL-20077 - stream writing error
- Method writeWithPath: saves the receiving text file content into the file with specified path. If the specified file already exists, its current contents erased, otherwise the specified file is created. Method calls the event handlers text:willWriteWithPath: and text:didFinishWritingWithPath: of the delegate object. If the method successfully completes the operation, the class instance property modified sets to the value NO.
NSLog( @"Writing to file: %d", [textFile writeWithPath:@"/tmp/strings.txt"]);
2016-08-30 15:16:32.425 libtest[3661:411369] Writing to file: 1
If you execute this sample, then the file /tmp/strings.txt will be contains the following strings: String 10
String 20
String 30
Method can throws the following exceptions:
- Method write saves the content of the receiving instance to the disk file with the path from the property path. Class instance assignes the value NO for the property modified if the writing operation is successfully completed.
Before execution of the example the file /tmp/strings.txt contains the following strings: String 10
String 20
String 30
NSLog( @"Writing to file: %d", [textFile write]);
2016-08-30 15:19:40.110 libtest[3689:413340] Writing to file: 1
After example execution the target file /tmp/strings.txt will be contains the following strings: String 10
String 20
String 30
String 40
- Method appendToFileWithPath: writes the receiving text file content to the end of the file with the specified path. If the target file does not exists, it will be created.
Content of the target file before sample execution: String 00
String 01
String 02
NSLog( @"Appending to file: %d", [textFile appendToFileWithPath:@"/tmp/text.txt"]);
2016-08-30 15:26:01.108 libtest[3739:416977] Appending to file: 1
Target file after example execution: String 00
String 01
String 02
=========
Committed
Reading and writing text blocks
Class SCTextFile declares the following methods for reading the text blocks:
- (BOOL)addTextFromStream:(
SCStream *)stream;
- (BOOL)addTextWithPath:(NSString *)path;
- (BOOL)insertTextWithPath:(NSString *)path atIndex:(
SCIndex)index;
Examples of this section use the test file /tmp/sample.txt with the following contents:
- Method addTextFromStream: adds into the receiving text file strings from the specified stream:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-05 13:41:14.239 libtest[2357:257266] Text file without path, strings=2, case sensitive, modified: (
String 00
String 01
)
2016-09-05 13:41:14.240 libtest[2357:257266] Text file without path, strings=4, case sensitive, modified: (
String 00
String 01
String 10
String 11
)
- Method addTextWithPath: adds into the receiving text file strings from the file with the specified path:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-05 13:43:54.061 libtest[2393:259125] Text file without path, strings=2, case sensitive, modified: (
String 20
String 21
)
2016-09-05 13:43:54.061 libtest[2393:259125] Text file without path, strings=4, case sensitive, modified: (
String 20
String 21
String 10
String 11
)
- Method insertTextFromStream:atIndex: loads the text from the specified stream and inserts it into the receiving text file at the specified index:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-05 13:55:55.000 libtest[2450:266126] Text file without path, strings=2, case sensitive, modified: (
String 00
String 01
)
2016-09-05 13:55:55.001 libtest[2450:266126] Text file without path, strings=4, case sensitive, modified: (
String 00
String 10
String 11
String 01
)
- Method insertTextWithPath:atIndex: loads the text from file with the specified path and inserts it into the receiving text file at the specified index:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-05 14:46:44.553 libtest[2542:293686] Text file without path, strings=2, case sensitive, modified: (
String 20
String 21
)
2016-09-05 14:46:44.554 libtest[2542:293686] Text file without path, strings=4, case sensitive, modified: (
String 10
String 11
String 20
String 21
)
Class SCTextFile implements the following methods for text blocks replacement:
- (BOOL)replaceTextInRange:(NSRange)range withTextFromStream:(
SCStream *)stream;
- (BOOL)replaceTextInRange:(NSRange)range withTextWithPath:(NSString *)path;
- (BOOL)replaceText:(
SCStrings *)text withTextWithPath:(NSString *)path;
- Method replaceTextInRange:withTextFromStream: replaces the text in the specified range with text loaded from the specified stream:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-06 10:54:41.543 libtest[2786:375288] Text file without path, strings=4, case sensitive, modified: (
String 01
String 02
String 03
String 04
)
2016-09-06 10:54:41.544 libtest[2786:375288] Text file without path, strings=4, case sensitive, modified: (
String 01
String 10
String 11
String 04
)
- Method replaceTextInRange:withTextWithPath: replaces the text in the specified range with text loaded from the file with the specified path:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-06 11:05:17.113 libtest[2835:379332] Text file without path, strings=4, case sensitive, modified: (
String 21
String 22
String 23
String 24
)
2016-09-06 11:05:17.114 libtest[2835:379332] Text file without path, strings=4, case sensitive, modified: (
String 21
String 10
String 11
String 24
)
- Method replaceText:withTextFromStream: replaces all occurrences of the specified text with the text readed from the specified stream:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-06 11:40:46.735 libtest[2915:393195] Text file without path, strings=4, case sensitive, modified: (
String 01
String 02
String 03
String 04
)
2016-09-06 11:40:46.736 libtest[2915:393195] Text file without path, strings=4, case sensitive, modified: (
String 10
String 11
String 03
String 04
)
- Method replaceText:withTextWithPath: replaces all occurrences of the specified text with text readed from the file with the specified path:
NSLog( @"%@", textFile);
NSLog( @"%@", textFile);
2016-09-06 11:48:05.730 libtest[2943:396110] Text file without path, strings=4, case sensitive, modified: (
String 01
String 02
String 03
String 04
)
2016-09-06 11:48:05.732 libtest[2943:396110] Text file without path, strings=4, case sensitive, modified: (
String 01
String 02
String 10
String 11
)
Class SCTextFile implements the following methods for text blocks writing:
- (BOOL)writeTextInRange:(NSRange)range toStream:(
SCStream *)stream;
- (BOOL)writeTextInRange:(NSRange)range withPath:(NSString *)path;
- (BOOL)appendTextInRange:(NSRange)range toFileWithPath:(NSString *)path;
- (
SCText *)cutTextInRange:(NSRange)range toStream:(
SCStream *)stream;
- (
SCText *)cutTextInRange:(NSRange)range withPath:(NSString *)path;
- (
SCText *)cutAndAppendTextInRange:(NSRange)range toFileWithPath:(NSString *)path;
- Method writeTextInRange:toStream: saves the text in the specified range to the specified stream. If the operation successfully completed, method returns the value YES, otherwise NO.
- Method writeTextInRange:withPath: saves the text in the specified range to the file with the specified path. If the target file already exists, it contents is removed. Method returns the value YES if the writing operation is successfully completed, otherwise returns value NO.
- Method appendTextInRange:toFileWithPath: returns the value YES if the operation of appending the text block in the specified range into the file with the specified path. If the target file does not exists, it will be created. If error is occurs, the method returns the value NO.
Before operation the sample output file contains the following strings: =================
String 10
String 12
- Method cutTextInRange:toStream: cuts the text in the specified range and save it to the specified stream:
NSLog( @"%@", textFile);
NSLog( @"%@", text);
NSLog( @"%@", textFile);
2016-09-06 14:18:26.778 libtest[3363:448620] Text file without path, strings=4, case sensitive, modified: (
String 01
String 02
String 03
String 04
)
2016-09-06 14:18:26.778 libtest[3363:448620] Text count=2, case sensitive, modified: (
String 01
String 02
)
2016-09-06 14:18:26.779 libtest[3363:448620] Text file without path, strings=2, case sensitive, modified: (
String 03
String 04
)
- Method cutTextInRange:withPath: cuts the text in the specified range and save it to the file with the specified path. If the target file already exists, the method removes the previously file contents.
NSLog( @"%@", textFile);
NSLog( @"%@", text);
NSLog( @"%@", textFile);
2016-09-06 14:22:08.930 libtest[3401:451083] Text file without path, strings=4, case sensitive, modified: (
String 11
String 22
String 33
String 44
)
2016-09-06 14:22:08.931 libtest[3401:451083] Text count=2, case sensitive, modified: (
String 22
String 33
)
2016-09-06 14:22:08.931 libtest[3401:451083] Text file without path, strings=2, case sensitive, modified: (
String 11
String 44
)
- Method cutAndAppendTextInRange:toFileWithPath: cuts the text in the specified range and append it to the end of the file with the specified path:
NSLog( @"%@", textFile);
NSLog( @"%@", text);
NSLog( @"%@", textFile);
2016-09-06 14:30:32.322 libtest[3468:456547] Text file without path, strings=4, case sensitive, modified: (
String 00
String 10
String 20
String 30
)
2016-09-06 14:30:32.323 libtest[3468:456547] Text count=2, case sensitive, modified: (
String 20
String 30
)
2016-09-06 14:30:32.323 libtest[3468:456547] Text file without path, strings=2, case sensitive, modified: (
String 00
String 10
)
#########
String 20
String 30
Additionally, class SCTextFile implements the methods for writing strings, which selected by using the various criteria:
- (BOOL)writeTextWithSubstring:(NSString *)substring toStream:(
SCStream *)stream;
- (BOOL)writeTextWithSubstring:(NSString *)substring withPath:(NSString *)path;
- (BOOL)writeTextWithoutSubstring:(NSString *)substring toStream:(
SCStream *)stream;
- (BOOL)writeTextWithoutSubstring:(NSString *)substring withPath:(NSString *)path;
- Method writeTextWithSubstring:toStream: saves into the specified stream strings from the receiving text file which contains the specified substring:
- Method writeTextWithSubstring:withPath: saves into the file with the specified path strings from the receiving text file which contains the specified substring:
- Method writeTextWithoutSubstring:toStream: saves into the specified stream strings from the receiving text file which not contains the specified substring:
- Method writeTextWithoutSubstring:withPath: saves into the file with the specified path strings from the receiving text file which not contains the specified substring:
Text error processing
Text classes implement the tools for processing errors, which can occur in the instances of class SCStrings and his children. These tools are based on the exception class SCTextException.
This section describes the error processing algorithm and errors decriptions, which are grouping by classes, which can occur these errors:
Error processing algorithm
The basic error processing algorithm is implemented in the class SCStrings. His children extends this algorith for processing the own errors (class specific errors).
When an error is detected, the class SCStrings instance comes the following:
- If the instance has an assigned delegate object, then it calls a method text:didDetectException:, passing it the pointers to the erroneous class instance and error related information as a exception class SCTextException instance.
- If the delegate object method text:didDetectException: returns the value YES, then the class instance ignores the detected error, but stops the erroneous method execution.
- If the method text:didDetectException: returns the value NO or the delegate object does not assigned, then the erroneous class instance creates and throws the exception class SCTextException instance which contains the error specific data.
Strings list errors
Instances of the class SCStrings and its children classes can detect the following errors:
- Exception SCL-20061 may be generated when the any method receives the nil pointer instead of the required source object. For example, the method initialization method, which initializes the strings list using the existing strings list, receives nil pointer instead the class SCStrings instance.
- If you attempt to make any changes into the read only strings list (property readOnly is set to value YES), then the class instance throws the exception SCL-20063.
- Error SCL-20064 occurs when you try to add or insert into the strings list the nil pointer instead the string.
- When the strings list works with the collections, it can detect, that the collection contains objects that are not strings. In this case the exception SCL-20066 is thrown. Exception property unsupported contains a name of class, an instance of which has caused the error. Currently, this error causes instances of any class other than NSString. We are considering the possibility of automatic convertion class NSNumber instances into the string format, but this task is still open.
- Exception SCL-20070 is throwing when trying to sort strings using inappropriate strings sorter (for example, when the sorting method receives the nil pointer or instance, which does not compy the SCSorter protocol).
- When accessing the string with a non-existent index exception SCL-20072 is thrown. Exception instance property index contains the index that caused the error.
- If a class SCStrings instance method receives an incorrect indexes set, then error SCL-20074 is occurs. Exception instance property indexSet contains the detected incorrect index set.
- Exception SCL-20075 is thrown by methods, which receive as an arguments the indexes set and the list (or collection). You can determine the erroneous number of indexes and number of strings by using the exception instance properties indexesCount and stringsCount.
Unique strings list errors
Class SCUniqueStrings expands the parent class SCStrings by adding the following own exceptions:
- Exception SCL-20069 is throwing when the unique strings list detects the uniqueness violation and the property strongMode is set to value YES).
Text errors
Class SCText declares the following advanced exceptions:
- Exception SCL-20073 is throwing when the text detects the incorrect strings range, which is stored in the exception instance property range.
- Text blocks coping and moving methods may throw an exception SCL-20076 if they discover the ranges intersections. The ranges are intersect if they contain one or more common strings. Exception instance properties range and intersected contain the data about this ranges.
Text file errors
Like other children of the class SCStrings, the class SCTextFile adds its own exceptions related to various errors when performing reading and writing operations. Please note that in some cases (depending on the stream operating mode) instead of throwing the exception SCTextException possible to throw exceptions of the classes SCStreamException and SCSystemException.
- Exceptions SCL-20062 and SCL-20071 are thrown when the text file detects that the stream does not support the required operations, for example, when the writing stream is read only. Exception instance property stream contains the incorrect stream data.
- If the class SCTextFile instance receives the closed stream as an method argument, then the error SCL-20065 is occurs when the instance try read or write strings from this stream.
- If the text file detects the nil pointer instead the file path, then the exception SCL-20068 is throwing.
Delegation protocol SCTextDelegate
Delegation protocol SCTextDelegate declares methods, which can be devided into the following functional groups:
- strings processing method
- error handling method
- string adding event handlers
- string removing event handlers
- sorting event handlers
- string replacing event handlers
- string coping and moving event handlers
- reading and writing event handlers
For more details see the protocol SCTextDelegate description.
Text indexes
Text index is a class SCTextIndex instance, which contains information about position within the text, consisting of the string index and character index in the string. Class SCTextIndex is a support class for text unit and it does not used alone.
Class SCTextIndex declares the following properties and access methods:
@property (nonatomic, readwrite, assign)
SCIndex line;
@property (nonatomic, readwrite, assign)
SCIndex character;
- (void)setCharacter:(
SCULong)character;
For creating the class SCTextIndex instances you may use the following class methods and functions:
+ (instancetype)textIndexWithLine:(
SCULong)line character:(
SCULong)character;
+ (instancetype)textIndexWithTextIndex:(
SCTextIndex *)textIndex;
+ (instancetype)textIndex;
Interaction with Data Objects
Standard data classes (NSData and NSMutableData) provides storage the raw data bytes as a single object. Some standard classes have methods for creating instances using the data objects and methods for storing instances in the data objects. SCL adds the methods for interaction with data objects into the own classes and standard classes that have not these methods.
Because class NSData instances have methods for loading and storing data in files and with URL use, SCL also adds the methods for interaction with files and URLs.
This section describes these methods and contains examples on their use:
Methods for interaction with data objects
Protocol SCDating defines the following methods for interaction with data objects:
- (instancetype)initWithData:(NSData *)data;
- (instancetype)initWithDataWrapper:(
SCData *)data;
- (void)writeToData:(NSMutableData *)data;
- (NSData *)data;
- Method initWithData: initializes a class instance using the specified data object:
NSData *data = [NSData dataWithContentsOfFile:@"/tmp/source.txt"];
NSString *string = [[NSString alloc] initWithData:data];
NSLog( @"%@", string);
[string release];
2017-05-25 20:40:09.335302+0300 libtest[4387:232383] Sample String
If You create a class with own data, You must override this method or method initWithDataWrapper: which described below.
Also some classes declares the methods for creating class instances, for example, the category NSString(SCString) adds into the class NSString the following method: + (instancetype)stringWithData:(NSData *)data;
- Method initWithDataWrapper: initializes a class instance using the specified data object wrapper (class SCData instance). We recommend override this methods if You class has own data, because class NSData does not supports the data reading pointer instead a wrapper class SCData).
- Method writeToData: writes a class instance into the data object:
NSMutableData *data = [NSMutableData data];
NSLog( @"%@", data);
NSString *string = @"Sample String";
[string writeToData:data];
NSLog( @"%@", data);
2017-05-25 20:47:27.255961+0300 libtest[4478:236195] <>
2017-05-25 20:47:27.256118+0300 libtest[4478:236195] <53616d70 6c652053 7472696e 67>
You must override this method in your classes with own data.
- Method data returns a data object with the class instance:
NSString *string = @"Sample String";
NSLog( @"%@", [string data]);
2017-05-25 20:53:26.707208+0300 libtest[4536:238692] <53616d70 6c652053 7472696e 67>
Methods for interaction with files
For interaction with files protocol SCDating defines the following methods:
- (instancetype)initWithContentsOfURL:(NSURL *)url;
- (BOOL)writeToFile:(NSString *)path;
- Method initWithContentsOfFile: initializes a class instance using the data from the file with the specified path:
NSString *string = [[NSString alloc] initWithContentsOfFile:@"/tmp/source.txt"];
NSLog( @"%@", string);
[string release];
2017-05-25 21:18:17.885417+0300 libtest[4864:248948] Sample String
Some classes implements the methods for creating class instances: + (instancetype)stringWithContentsOfFile:(NSString *)path;
- Method writeToFile: saves the class instance into the file with the specified path. If the destination file is already exists, the existing contents of file will be deleted.
NSString *string = @"Sample String";
[string writeToFile:@"/tmp/output.txt"];
Methods for interaction with URLs
Objective-C declares the special class NSURL for working with URLs. However in some cases it is more convenient using the strings URLs instead instances of the class NSURL. Therefore protocol SCDating declares both types of methods - for using NSUSRL class instances and strings.
- (instancetype)initWithContentsOfURL:(NSURL *)url;
- (instancetype)initWithContentsOfURLString:(NSString *)urlString;
- (BOOL)writeToURL:(NSURL *)url;
- (BOOL)writeToURLString:(NSString *)urlString;
- Methods initWithContentsOfURL: and initWithContentsOfURLString: initializes class instance using the data from the specified URL (defines by NSURL class instance or string:
NSURL *url = [NSURL URLWithString:@"file:///tmp/source.txt"];
NSString *string = [[NSString alloc] initWithContentsOfURL:url];
NSLog( @"%@", string);
[string release];
2017-05-25 22:44:28.632374+0300 libtest[5199:283871] Sample String
These methods can be operating with any types of URLs.
Also some classes can define the methods for creating class instances: + (instancetype)stringWithContentsOfURL:(NSURL *)url;
+ (instancetype)stringWithContentsOfURLString:(NSString *)urlString;
- Methods writeToURL: and writeToURLString: saves the class instance into the specified URL (class NSURL instance or string):
NSURL *url = [NSURL URLWithString:@"file:///tmp/output.txt"];
NSString *string = @"Sample String";
[string writeToURL:url];
These methods can operating only with file URLs file://.
NSString extensions
Standard class NSString provides programmers a large range of features. Nevertheless, there are always those or other needs and suggestions that wants to supplement the basic functionality of the standard class.
With the power of language Objective-C it can be done without the need to create child classes that would require in the code to use instances of these subclasses. Due to categories, we can extend the functionality of an existing class, and cause the new features when using instances of the class itself, not its children.
This Programming Guide section describes the extensions provided by the category NSString(SCString), including adding support for standard features of our library (streams, data dictionaries, collections, and so on).
Consider by us added capabilities, we will in accordance with their categories the following groups:
Creating strings
Category NSString(SCString) implements the following methods for creating strings using the data from the serialized files, data dictionaries and streams:
+ (instancetype)stringWithCoder:(NSCoder *)coder;
+ (instancetype)stringWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)stringWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)stringWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)stringWithStream:(
SCStream *)stream;
+ (instancetype)stringWithFileStream:(NSString *)path;
Category implements the following methods for support data objects:
+ (instancetype)stringWithData:(NSData *)data;
+ (instancetype)stringWithContentsOfFile:(NSString *)path;
+ (instancetype)stringWithContentsOfURL:(NSURL *)url;
+ (instancetype)stringWithContentsOfURLString:(NSString *)urlString;
Category NSString(SCString) implements the following class methods for creating strings:
+ (instancetype)stringWithIndexSet:(NSIndexSet *)indexSet;
+ (instancetype)stringWithCharacter:(unichar)character;
+ (instancetype)stringWithCharacter:(unichar)character length:(
SCIndex)length;
+ (instancetype)stringWithLength:(
SCUInteger)length;
+ (instancetype)stringWithPointer:(void *)pointer;
+ (instancetype)stringWithID:(id)object;
- Class method stringWithIndexSet: returns a string created by using the character representation of the specified existing index set:
NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet];
[indexSet addIndex:2];
[indexSet addIndex:4];
[indexSet addIndex:8];
NSString *string = [NSString stringWithIndexSet:indexSet];
NSLog( @"%@", string);
2016-09-07 15:12:38.546 libtest[2562:194688] (2, 4, 8)
- Class method stringWithCharacter: returns a string created by using the specified character:
NSString *string = [NSString stringWithCharacter:'D'];
NSLog( @"%@", string);
2016-09-07 15:31:27.264 libtest[2633:207778] D
- Class method stringWithCharacter:length: returns a string created by using the specified number of a given character:
NSString *string = [NSString stringWithCharacter:'#' length:8];
NSLog( @"%@", string);
2016-09-07 15:35:48.226 libtest[2655:211738] ########
- Class method stringWithLength: returns a string created by using the specified number of spaces:
NSString *string = [NSString stringWithLength:12];
NSLog( @"#%@#", string);
2016-09-07 15:47:12.583 libtest[2680:217096] # #
- Class method stringWithPointer: returns a string created as text representation of the specified pointer:
size_t size = 64;
void *pointer = malloc(size);
NSString *string = [NSString stringWithPointer:pointer];
NSLog( @"%@", string);
free(pointer);
2016-09-07 15:52:36.835 libtest[2713:220992] 0x100703890
- Class method stringWithID: returns a string created by using class instance description:
NSString *string = [NSString stringWithID:object];
NSLog( @"%@", string);
2016-09-07 15:58:15.378 libtest[2747:224739] (23, 19)
Initializing strings
Category NSString(SCString) declares the following additional initializing methods:
- (instancetype)initWithIndexSet:(NSIndexSet *)indexSet;
- (instancetype)initWithCharacter:(unichar)character;
- (instancetype)initWithCharacter:(unichar)character length:(
SCIndex)length;
- (instancetype)initWithLength:(
SCUInteger)length;
- (instancetype)initWithPointer:(void *)pointer;
- (instancetype)initWithID:(id)object;
- Method initWithIndexSet: initializes the string using the character representation of the specified existing index set.
- Method initWithCharacter: initializes the string using the specified character.
- Method initWithCharacter:length: initializes the string using the specified number of a given character.
- Method initWithLength: initializes the string using the specified number of spaces.
- Method initWithPointer: initializes the string as a text representation of the specified pointer.
- Method initWithID: initializes the string using the specified class instance description.
Dividing strings and replacing substrings
Category NSString(SCString) extends the standard class NSString by implementing the large range of properties and methods for dividing strings and replacing substrings within strings. For convenience of description its this section is divided into several subsections according to the use of methods:
Strings part dropping
@property (nonatomic, readonly, assign) NSString *trimmedString;
- (NSString *)ltrim;
- (NSString *)rtrim;
- (NSString *)trim;
- (NSString *)stringWithLeftCharacters:(
SCIndex)characters;
- (NSString *)stringWithRightCharacters:(
SCIndex)characters;
- (NSString *)skipLeftPart:(
SCIndex)characters;
- (NSString *)skipRightPart:(
SCIndex)characters;
- Methods ltrim, rtrim and trim returns a string without a leading, trailing or leading and trailing spaces and tabs. A property trimmedString is a synonym of a method trim.
NSString *string = @" Test string ";
NSLog( @"#%@#", [string ltrim]);
NSLog( @"#%@#", [string rtrim]);
NSLog( @"#%@#", [string trim]);
2016-09-08 09:45:56.083 libtest[1063:17768] #Test string #
2016-09-08 09:45:56.083 libtest[1063:17768] # Test string#
2016-09-08 09:45:56.083 libtest[1063:17768] #Test string#
- Methods stringWithLeftCharacters: and stringWithRightCharacters: returns a string, which contains the specified number of receiving string leading or trailing characters. If the length of receiving string is less than number of charaters, then methods return the source string.
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithLeftCharacters:4]);
NSLog( @"%@", [string stringWithRightCharacters:4]);
2016-09-08 09:54:41.037 libtest[1099:19897] 0123
2016-09-08 09:54:41.038 libtest[1099:19897] 6789
- Methods skipLeftPart: and skipRightPart: returns a string without the specified number of receiving string leading or traling characters. If the receiving string length is less than number of characters, then method returns an empty string.
NSString *string = @"0123456789";
NSLog( @"%@", [string skipLeftPart:4]);
NSLog( @"%@", [string skipRightPart:4]);
2016-09-08 09:58:10.444 libtest[1123:21873] 456789
2016-09-08 09:58:10.445 libtest[1123:21873] 012345
Searching substrings
- (BOOL)isCorrectRange:(NSRange)range;
- (BOOL)existsSubstring:(NSString *)substring caseInsensitive:(BOOL)caseInsensitive;
- (BOOL)existsSubstring:(NSString *)substring;
- (
SCIndex)countOfSubstring:(NSString *)substring caseInsensitive:(BOOL)caseInsensitive;
- (
SCIndex)countOfSubstring:(NSString *)substring;
- (
SCIndex)indexOfSubstring:(NSString *)substring caseInsensitive:(BOOL)caseInsensitive;
- (
SCIndex)indexOfSubstring:(NSString *)substring;
- (NSArray *)indexesOfSubstring:(NSString *)substring caseInsensitive:(BOOL)caseInsensitive;
- (NSArray *)indexesOfSubstring:(NSString *)substring;
- Method isCorrectRange: checks a characters range within the receiving string. If the specified range is correct, the method retursn value YES, otherwise NO.
NSString *string = @"0123456789";
NSLog( @"%d", [string isCorrectRange:NSMakeRange(6, 2)]);
NSLog( @"%d", [string isCorrectRange:NSMakeRange(8, 4)]);
2016-09-08 10:27:12.437 libtest[1304:38314] 1
2016-09-08 10:27:12.438 libtest[1304:38314] 0
- Methods existsSubstring:caseInsensitive: and existsSubstring: check occurrence in the receiver's string the specified substring. If the required substring is found, methods return value YES, otherwise NO. If you are use the method existsSubstring:caseInsensitive:, you can manage the case sensitive. The method existsSubstring: always performs case sensitive search.
NSString *string = @"Sample string";
NSLog( @"%d", [string existsSubstring:@"sample"]);
NSLog( @"%d", [string existsSubstring:@"sample" caseInsensitive:YES]);
2016-09-08 10:30:33.017 libtest[1330:39892] 0
2016-09-08 10:30:33.017 libtest[1330:39892] 1
- Methods countOfSubstring:caseInsensitive: and countOfSubstring: return a number of the specified substring occurrences:
NSString *string = @"Sample string (from sample set)";
NSLog( @"%d", [string countOfSubstring:@"message"]);
NSLog( @"%d", [string countOfSubstring:@"sample"]);
NSLog( @"%d", [string countOfSubstring:@"sample" caseInsensitive:YES]);
2016-09-08 10:33:28.368 libtest[1362:41835] 0
2016-09-08 10:33:28.368 libtest[1362:41835] 1
2016-09-08 10:33:28.369 libtest[1362:41835] 2
- Methods indexOfSubstring:caseInsensitive: and indexOfSubstring: return the index of the first occurrence of the specified substring. If the required string does not exists, then methods returns value NSNotFound.
NSString *string = @"Sample string (from sample set)";
NSLog( @"%d", [string indexOfSubstring:@"message"]);
NSLog( @"%d", [string indexOfSubstring:@"sample"]);
NSLog( @"%d", [string indexOfSubstring:@"sample" caseInsensitive:YES]);
2016-09-08 10:41:41.499 libtest[1406:46169] -1
2016-09-08 10:41:41.499 libtest[1406:46169] 20
2016-09-08 10:41:41.499 libtest[1406:46169] 0
- Methods indexesOfSubstring:caseInsensitive: and indexesOfSubstring: return an array with the indexes of all occurrences of the specified substring:
NSString *string = @"Sample string (from sample set)";
NSLog( @"%@", [string indexesOfSubstring:@"message"]);
NSLog( @"%@", [string indexesOfSubstring:@"sample"]);
NSLog( @"%@", [string indexesOfSubstring:@"sample" caseInsensitive:YES]);
2016-09-08 10:45:02.004 libtest[1423:47803] (
)
2016-09-08 10:45:02.004 libtest[1423:47803] (
"20"
)
2016-09-08 10:45:02.004 libtest[1423:47803] (
"0",
"20"
)
Removing substrings
- (NSString *)stringWithDeletedSubstring:(NSString *)substring caseInsensitive:(BOOL)caseInsensitive;
- (NSString *)stringWithDeletedSubstring:(NSString *)substring;
- (NSString *)stringWithDeletedSubstringToIndex:(
SCIndex)index;
- (NSString *)stringWithDeletedSubstringToRange:(NSRange)range;
- (NSString *)stringWithDeletedSubstringFromIndex:(
SCIndex)index;
- (NSString *)stringWithDeletedSubstringWithRange:(NSRange)range;
- Methods stringWithDeletedSubstring:caseInsensitive: and stringWithDeletedSubstring: return a receiver's string without the specified substring. The first method allows you to control case insensitive mode, otherwise the second method always performs case sensitive search of the removed substring. If the specified substring does not exists in the string, then the methods return the source string without deleting.
NSString *string = @"Sample string (from sample set)";
NSLog( @"%@", [string stringWithDeletedSubstring:@"sample"]);
NSLog( @"%@", [string stringWithDeletedSubstring:@"sample" caseInsensitive:YES]);
2016-09-08 12:13:32.981 libtest[1757:91307] Sample string (from set)
2016-09-08 12:13:32.981 libtest[1757:91307] string (from set)
- Method stringWithDeletedSubstringToIndex: returns a receiver's string without characters before the specified index:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithDeletedSubstringToIndex:4]);
2016-09-08 12:16:04.777 libtest[1779:93021] 456789
- Метод stringWithDeletedSubstringToRange: возвращает строку без символов, входящих в указанный диапазон и без символов до указанного диапазона:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithDeletedSubstringToRange:NSMakeRange(4,2)]);
2016-09-08 12:18:34.292 libtest[1808:94967] 6789
- Method stringWithDeletedSubstringFromIndex: returns a receiver's string without characters after the specified index:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithDeletedSubstringFromIndex:4]);
2016-09-08 12:21:48.779 libtest[1833:97889] 0123
- Method stringWithDeletedSubstringWithRange: returns a receiver's string without characters in the specified range:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithDeletedSubstringWithRange:NSMakeRange(4,2)]);
2016-09-08 12:24:04.174 libtest[1852:99733] 01236789
Replacing substrings
- (NSString *)stringWithReplacedSubstringToIndex:(
SCUInteger)index withString:(NSString *)string;
- (NSString *)stringWithReplacedSubstringFromIndex:(
SCUInteger)index withString:(NSString *)string;
- (NSString *)stringWithReplacedSubstringWithRange:(NSRange)range withString:(NSString *)string;
- (NSString *)stringWithReplacedSubstring:(NSString *)substring
withString:(NSString *)string
caseInsensitive:(BOOL)caseInsensitive;
- (NSString *)stringWithReplacedSubstring:(NSString *)substring withString:(NSString *)string;
- Method stringWithReplacedSubstringToIndex:withString: returns a string with replaced characters before the specified index by the specified substring:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithReplacedSubstringToIndex:4 withString:@"ABCD_"]);
2016-09-08 12:57:19.581 libtest[2061:118066] ABCD_456789
- Method stringWithReplacedSubstringFromIndex:withString: returns a string with replaced characters after the specified index by the specified substring:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithReplacedSubstringFromIndex:6 withString:@"_SMND"]);
2016-09-08 12:59:44.898 libtest[2089:119513] 012345_SMND
- Method stringWithReplacedSubstringWithRange:withString: returns a string with replaced characters range by the specified substring:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithReplacedSubstringWithRange:NSMakeRange(4, 2) withString:@"_IETF_"]);
2016-09-08 13:07:10.944 libtest[2112:121668] 0123_IETF_6789
- Method stringWithReplacedSubstring:withString:caseInsensitive: and stringWithReplacedSubstring:withString: returns a string with replaced the specified substring by another substring. The first method allows you to set the case sensitive mode, otherwise the second method is always performs the case sensitive search.
NSString *string = @"Sample string (from sample set)";
NSLog( @"%@", [string stringWithReplacedSubstring:@"sample" withString:@"test"]);
NSLog( @"%@", [string stringWithReplacedSubstring:@"sample" withString:@"test" caseInsensitive:YES]);
2016-09-08 13:11:02.478 libtest[2137:123402] Sample string (from test set)
2016-09-08 13:11:02.478 libtest[2137:123402] test string (from test set)
Inserting substrings
- (NSString *)stringWithInsertedString:(NSString *)string;
- (NSString *)stringWithInsertedString:(NSString *)string index:(
SCUInteger)index;
- Method stringWithInsertedString: returns a string with added before the receiver's string the specified substring:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithInsertedString:@"SMND_"]);
2016-09-08 14:09:00.147 libtest[2338:151105] SMND_0123456789
- Method stringWithInsertedString:index: returns a string with inserted substring at the specified index:
NSString *string = @"0123456789";
NSLog( @"%@", [string stringWithInsertedString:@"_SMND_" index:5]);
2016-09-08 14:30:07.071 libtest[2432:161179] 01234_SMND_56789
String words
For operations with single words within strings the category NSString(SCString) implements the following properties and methods:
@property (nonatomic, readonly, assign) NSString *normalizedString;
@property (nonatomic, readonly, assign)
SCIndex wordsCount;
@property (nonatomic, readonly, assign) NSString *firstWord;
@property (nonatomic, readonly, assign) NSString *lastWord;
@property (nonatomic, readonly, assign) NSString *endOfString;
- Property normalizedString returns a normalized receiving string. Normal string is a string without leading and trailing spaces and tabs and every word of which is separated from the next by a single space.
NSString *string = @" This is a test message string ";
NSLog( @"%@", string.normalizedString);
2016-09-08 15:12:18.373 libtest[2577:181304] This is a test message string
- Property wordsCount returns a words count in the receiving string:
NSString *string = @"This is a test message string";
NSLog( @"%d", string.wordsCount);
2016-09-08 15:15:46.804 libtest[2612:183537] 6
- Property firstWord returns a first word of the receiving string. If the string does not contains any words, then property returns the empty string.
NSString *string = @"This is a test message string";
NSLog( @"%@", string.firstWord);
2016-09-08 15:23:22.066 libtest[2657:187834] This
- Property lastWord returns a last word of the receiving string. If the string does not contains any words, then property returns the empty string.
NSString *string = @"This is a test message string";
NSLog( @"%@", string.lastWord);
2016-09-08 15:25:34.884 libtest[2673:189714] string
- Property endOfString returns a receiving string without first word:
NSString *string = @"This is a test message string";
NSLog( @"%@", string.endOfString);
2016-09-08 15:28:01.610 libtest[2707:193924] is a test message string
- Method word: returns a word of the receiving string at the specified index. If the specified word index is incorrect, then method returns the empty string.
NSString *string = @"This is a test message string";
NSLog( @"%@", [string word:3]);
NSLog( @"%@", [string word:5]);
2016-09-08 15:20:54.105 libtest[2640:185875] test
2016-09-08 15:20:54.105 libtest[2640:185875] string
Comparing strings
Category NSString(SCString) implements the following additional comparing methods:
- (BOOL)isEqualToStrings:(NSString *)string, ...;
- Method isEqualToStrings: returns a boolean value that indicates whether the receiver is equal to any string from the specified nil terminated list:
NSString *string = @"Test string";
NSLog( @"%d", [string isEqualToStrings:@"Test message", @"Test letter", nil]);
NSLog( @"%d", [string isEqualToStrings:@"Test message", @"Test string", nil]);
2016-09-08 21:43:41.278 libtest[1584:133885] 0
2016-09-08 21:43:41.279 libtest[1584:133885] 1
Expanding strings
Category NSString(SCString) declares the following expanding methods:
- (NSString *)leftExpandedStringToLength:(
SCIndex)length character:(unichar)character;
- (NSString *)leftExpandedStringToLength:(
SCIndex)length;
- (NSString *)leftZeroExpandedStringToLength:(
SCIndex)length;
- (NSString *)rightExpandedStringToLength:(
SCIndex)length character:(unichar)character;
- (NSString *)rightExpandedStringToLength:(
SCIndex)length;
- Method leftExpandedStringToLength:character: returns a string padded on the left of the specified character to the specified length. If the receiving string length is greater than the specified length, then the method returns the source string.
NSString *string = @"Sample String";
NSLog( @"%@", [string leftExpandedStringToLength:15 character:'*']);
2016-09-08 22:46:02.279 libtest[1769:167644] **Sample String
- Method leftExpandedStringToLength: returns a string padded on the left of the spaced to the specified length:
NSString *string = @"Sample";
NSLog( @"#%@#", [string leftExpandedStringToLength:10]);
2016-09-08 22:48:06.698 libtest[1795:169511] # Sample#
- Method leftZeroExpandedStringToLength: returns a string padded on the left of the zero characters to the specified length:
NSString *string = @"2319";
NSLog( @"%@", [string leftZeroExpandedStringToLength:8]);
2016-09-08 22:50:38.417 libtest[1833:172009] 00002319
- Method rightExpandedStringToLength:character: returns a string padded on the right of the specified characters to the specified length:
NSString *string = @"Message_";
NSLog( @"%@", [string rightExpandedStringToLength:12 character:'*']);
2016-09-08 22:53:18.040 libtest[1862:174043] Message_****
- Method rightExpandedStringToLength: returns a string padded on the right of the spaced to the specified length:
NSString *string = @"Sample";
NSLog( @"#%@#", [string rightExpandedStringToLength:10]);
2016-09-08 22:54:37.596 libtest[1884:175283] #Sample #
Additionally, category NSString(SCString) implements the class methods for creating expanded strings:
+ (instancetype)stringWithLeftExpandedString:(NSString *)string length:(
SCIndex)length character:(unichar)character;
+ (instancetype)stringWithLeftExpandedString:(NSString *)string length:(
SCIndex)length;
+ (instancetype)stringWithLeftZeroExpandedString:(NSString *)string length:(
SCIndex)length;
+ (instancetype)stringWithRightExpandedString:(NSString *)string length:(
SCIndex)length character:(unichar)character;
+ (instancetype)stringWithRightExpandedString:(NSString *)string length:(
SCIndex)length;
Also category implements the following initialization methods:
- (instancetype)initWithLeftExpandedString:(NSString *)string length:(
SCIndex)length character:(unichar)character;
- (instancetype)initWithLeftExpandedString:(NSString *)string length:(
SCIndex)length;
- (instancetype)initWithLeftZeroExpandedString:(NSString *)string length:(
SCIndex)length;
- (instancetype)initWithRightExpandedString:(NSString *)string length:(
SCIndex)length character:(unichar)character;
- (instancetype)initWithRightExpandedString:(NSString *)string length:(
SCIndex)length;
Adding delimiters
Category NSString(SCString) implements the following methods for separation strings on the groups of characters:
- (NSString *)stringWithSeparator:(NSString *)separator left:(
SCIndex)left;
- (NSString *)stringWithSpacesLeft:(
SCIndex)left;
- (NSString *)stringWithSeparator:(NSString *)separator right:(
SCIndex)right;
- (NSString *)stringWithSpacesRight:(
SCIndex)right;
- Method stringWithSeparator:left: returns a string with the added separators after the specified number of characters from left to right:
NSString *string = @"123456789";
NSLog( @"%@", [string stringWithSeparator:@"-" left:4]);
2016-09-12 09:40:37.340 libtest[944:21744] 1234-5678-9
- Method stringWithSpacesLeft: returns a string with the added spaces as separator after the specified number of characters from left to right:
NSString *string = @"123456789";
NSLog( @"%@", [string stringWithSpacesLeft:2]);
2016-09-12 10:02:21.074 libtest[1010:33187] 12 34 56 78 9
- Method stringWithSeparator:right returns a string with the added separators after the specified number of characters from right to left:
NSString *string = @"123456789";
NSLog( @"%@", [string stringWithSeparator:@"-" right:5]);
2016-09-12 10:17:07.824 libtest[1059:41867] 1234-56789
- Method stringWithSpacesRight: returns a string with the added spaces as separators after the specified number of characters from right to left:
NSString *string = @"123456789";
NSLog( @"%@", [string stringWithSpacesRight:4]);
2016-09-12 10:25:54.572 libtest[1094:49088] 1 2345 6789
Also category declares the class methods and initializing methods for creating strings with the separators:
+ (instancetype)stringWithString:(NSString *)string separator:(NSString *)separator left:(
SCIndex)left;
+ (instancetype)stringWithString:(NSString *)string spacesLeft:(
SCIndex)left;
+ (instancetype)stringWithString:(NSString *)string separator:(NSString *)separator right:(
SCIndex)right;
+ (instancetype)stringWithString:(NSString *)string spacesRight:(
SCIndex)right;
- (instancetype)initWithString:(NSString *)string separator:(NSString *)separator left:(
SCIndex)left;
- (instancetype)initWithString:(NSString *)string spacesLeft:(
SCIndex)left;
- (instancetype)initWithString:(NSString *)string separator:(NSString *)separator right:(
SCIndex)right;
- (instancetype)initWithString:(NSString *)string spacesRight:(
SCIndex)right;
Data types representation
This sectiond describes the category NSString(SCString) properties and methods, which communicate between number objects and numbers text representation:
Detecting digits
Category NSString(SCString) declares the following methods to determine whether a string is a character representation of the number objects.
@property (nonatomic, readonly, assign) BOOL isBinaryString;
@property (nonatomic, readonly, assign) BOOL isOctalString;
@property (nonatomic, readonly, assign) BOOL isDecimalString;
@property (nonatomic, readonly, assign) BOOL isHexadecimalString;
@property (nonatomic, readonly, assign) BOOL isBooleanString;
@property (nonatomic, readonly, assign) BOOL isFloatString;
@property (nonatomic, readonly, assign) BOOL isDoubleString;
- Property isBinaryString checks whether the receiver's string is a binary text representation of integer value. The string is a binary string if which contains only characters "0" and "1" (also allow the spaces). If the receiving string contains any other characters, then property returns a value NO.
- Property isOctalString checks whether the receiver's string is a text representation of the octal integer value. The string is am octal string of which contains only characters from "0" to "7" and spaces as a digital character groups separators. If the receiving string contains any other characters, then the property returns the value NO.
- Property isDecimalString returns the value YES if the receving string contains only characters from "0" to "9", spaces and characters "+" and "-", otherwise property returns the value NO.
- Property isHexadecimalString checks whether the receiver's string is a text representation of hexadecimal integer value. If the string contains only characters from "0" to "9", from "a" to "f", from "A" to "F", spaces and special character "0x", then property returns the value YES, otherwise it returns the value NO.
- Property isBooleanString checks whether the receiving string is a text representation of boolean value.
- Properties isFloatString and isDoubleString return a boolean value which determines whether the receiving string is a text representation of the float or double value.
Converting strings to numbers
Category NSString(SCString) implements the following properties, which convert the various number representations into the integer or boolean values:
@property (nonatomic, readonly, assign)
SCULong binaryValue;
@property (nonatomic, readonly, assign)
SCULong octalValue;
@property (nonatomic, readonly, assign)
SCULong decimalValue;
@property (nonatomic, readonly, assign)
SCULong hexadecimalValue;
@property (nonatomic, readonly, assign) BOOL booleanValue;
- Property binaryValue converts the receiving string into the integer value as a binary text representation. If the source string does not contains the binary integer representation, then the property returns the value 0.
NSString *string = @"0100 1011";
NSLog( @"%d", string.binaryValue);
2016-09-12 12:49:09.030 libtest[1857:153790] 75
- Property octalValue returns integer value of the receiving octal text representation:
NSString *string = @"0640";
NSLog( @"%d", [string octalValue]);
2016-09-12 12:50:28.740 libtest[1888:155362] 416
- Property decimalValue returns an integer value of the receiving text representation of the decimal integer value:
NSString *string = @"318 423";
NSLog( @"%d", string.decimalValue);
2016-09-12 12:51:50.971 libtest[1930:157194] 318423
- Property hexadecimalValue returns an integer value of hexadecimal text representation of receiving value:
NSString *string = @"0x04AE78FB";
NSLog( @"%d", [string hexadecimalValue]);
2016-09-12 12:53:36.004 libtest[1951:158783] 78543099
- Property booleanValue returns boolean value of receiver's text representation of boolean value:
NSLog( @"%d", [@"Yes" booleanValue]);
NSLog( @"%d", @"True".booleanValue);
2016-09-12 12:56:53.526 libtest[2008:162575] 1
2016-09-12 12:56:53.526 libtest[2008:162575] 1
Converting numbers to strings
Category NSString(SCString) implements the following methods, which create the text representations of the various integer and boolean values:
+ (instancetype)stringWithBinaryInteger:(
SCULong)integer capacity:(
SCCapacity)capacity;
+ (instancetype)stringWithBinaryInteger:(
SCULong)integer;
+ (instancetype)stringWithOctalInteger:(
SCULong)integer;
+ (instancetype)stringWithDecimalInteger:(
SCLong)integer separators:(BOOL)separators;
+ (instancetype)stringWithDecimalInteger:(
SCLong)integer;
+ (instancetype)stringWithInteger:(
SCLong)integer;
+ (instancetype)stringWithHexadecimalInteger:(
SCULong)integer capacity:(
SCCapacity)capacity;
+ (instancetype)stringWithHexadecimalInteger:(
SCULong)integer;
+ (instancetype)stringWithBool:(BOOL)boolean;
+ (instancetype)stringWithFloat:(
SCFloat)value;
+ (instancetype)stringWithDouble:(
SCDouble)value;
- Class method stringWithBinaryInteger:capacity: returns a string created as a text representation of the binary integer value with the specified capacity:
NSString *string = [NSString stringWithBinaryInteger:1909 capacity:SCWordCapacity];
NSLog( @"%@", string);
2016-09-12 13:34:06.426 libtest[2271:191971] 00000111 01110101
- Class method stringWithBinaryInteger: is equals to the class method stringWithBinaryInteger:capacity:, but always using the 32-bit or 64-bit binary value representation (based on the source value capacity):
NSString *string = [NSString stringWithBinaryInteger:1909];
NSLog( @"%@", string);
2016-09-12 13:35:02.276 libtest[2289:193446] 00000000 00000000 00000111 01110101
- Class method stringWithOctalInteger: returns a string created as a text representation of the octal integer value:
NSString *string = [NSString stringWithOctalInteger:1909];
NSLog( @"%@", string);
2016-09-12 13:37:49.867 libtest[2317:196790] 3565
- Class method stringWithDecimalInteger:separators: returns a string created as the text representation of the decimal integer value with the flag of using the digits separators:
NSString *string = [NSString stringWithDecimalInteger:19091975 separators:YES];
NSLog( @"%@", string);
2016-09-12 13:38:33.963 libtest[2342:197280] 19 091 975
- Class method stringWithDecimalInteger: returns a string created as the text representation of the decimal integer value without using the digits separators:
NSString *string = [NSString stringWithDecimalInteger:19091975];
NSLog( @"%@", string);
2016-09-12 13:39:33.242 libtest[2361:198731] 19091975
- Class method stringWithInteger: is equals to the class method stringWithDecimalInteger:
NSString *string = [NSString stringWithInteger:1909];
NSLog( @"%@", string);
2016-09-12 13:40:31.283 libtest[2380:199859] 1909
- Class method stringWithHexadecimalInteger:capacity: returns a string created as a text representation of the hexadecimal integer value with the specified capacity:
NSString *string = [NSString stringWithHexadecimalInteger:19091975 capacity:SCIntCapacity];
NSLog( @"%@", string);
2016-09-12 13:43:03.999 libtest[2430:202816] 0123 5207
- Class method stringWithHexadecimalInteger: returs a string created as a text representation of the hexadecimal integer value with the 64-bit capacity:
NSString *string = [NSString stringWithHexadecimalInteger:19091975];
NSLog( @"%@", string);
2016-09-12 13:43:58.910 libtest[2447:203955] 0000 0000 0123 5207
- Class method stringWithBool: returns a string created as a text representation of the boolean value:
NSString *string = [NSString stringWithBool:YES];
NSLog( @"%@", string);
2016-09-12 13:45:09.607 libtest[2465:205489] YES
- Class method stringWithFloat: returns a string created as a text representation of the float value:
NSString *string = [NSString stringWithFloat:1909.1975];
NSLog( @"%@", string);
2016-09-12 13:47:10.766 libtest[2512:207546] 1909.197510
- Class method stringWithDouble: returns a string created as a text representation of the double value:
NSString *string = [NSString stringWithDouble:1909.1975];
NSLog( @"%@", string);
2016-09-12 13:48:23.241 libtest[2535:208992] 1909.197500
Initializing number strings
Categoty NSString(SCString) declares the following methods for initializing the class instances as an integer and boolean values representation:
- (instancetype)initWithBinaryInteger:(
SCULong)integer capacity:(
SCCapacity)capacity;
- (instancetype)initWithBinaryInteger:(
SCULong)integer;
- (instancetype)initWithOctalInteger:(
SCULong)integer;
- (instancetype)initWithDecimalInteger:(
SCLong)integer separators:(BOOL)separators;
- (instancetype)initWithDecimalInteger:(
SCLong)integer;
- (instancetype)initWithInteger:(
SCLong)integer;
- (instancetype)initWithHexadecimalInteger:(
SCULong)integer capacity:(
SCCapacity)capacity;
- (instancetype)initWithHexadecimalInteger:(
SCULong)integer;
- (instancetype)initWithBool:(BOOL)boolean;
- (instancetype)initWithFloat:(
SCFloat)value;
- (instancetype)initWithDouble:(
SCDouble)value;
- Method initWithBinaryInteger:capacity: initializes a string as a text representation of the binary integer value with the specified capacity.
- Method initWithBinaryInteger: initializes a string as a text representation of the binary integer value with the 32-bit capacity.
- Method initWithOctalInteger: initializes a string as a text representation of the octal integer value.
- Method initWithDecimalInteger:separators: initializes a string as the text representation of the decimal integer value with the flag of using the digits separators.
- Methods initWithDecimalInteger: and initWithInteger: initialize a string as the text representation of the decimal integer value without the digits separators.
- Method initWithHexadecimalInteger:capacity: returns a string created as a text representation of the hexadecimal integer value with the specified capacity.
- Method initWithHexadecimalInteger: returns a string created as a text representation of the hexadecimal integer value with the 64-bit capacity.
- Method initWithBool: initializes the string as a text representation of the boolean value.
- Methods initWithFloat: and initWithDouble: initializes a string as a text representation of the float or double value.
Reversing strings
Category NSString(SCString) implements the following reversing methods:
@property (nonatomic, readonly, assign) NSString *reversedString;
+ (instancetype)stringWithReversedString:(NSString *)string;
- (instancetype)initWithReversedString:(NSString *)string;
- Property reversedString returns a reversed string:
NSString *string = @"0123456789";
NSLog( @"%@", string.reversedString);
2016-09-12 21:57:17.443 libtest[1601:139563] 9876543210
- Class method stringWithReversedString: returns a string created by reversing the source string.
- Method initWithReversedString: initializes the string by reversing the specified source string.
Other methods
In addition to described properties and methods category NSString(SCString) declares the following properties that can not be assigned to any particular group:
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) NSString *stringWithUpperFirstLetter;
- Property empty check for the receiving string of at least one character other than space and tab:
NSString *string = @" ";
NSLog( @"%d", string.empty);
string = @"Sample String";
NSLog( @"%d", [string empty]);
2016-09-14 12:22:49.854 libtest[1963:133269] 1
2016-09-14 12:22:49.854 libtest[1963:133269] 0
- Properties stringWithUpperFirstLetter returns a receiving string with capital first character:
NSString *string = @"sample string";
NSLog( @"%@", [string stringWithUpperFirstLetter]);
2016-09-14 12:49:52.368 libtest[3440:148768] Sample string
Standard classes extentions
In the previous section has been described the category NSString(SCString), which extends the functionality of the standard class NSString. Additionally many standard classes also got advanced properties and methods. In this section, we describe this classes and their extensions. This section contains the description of the extentions for the following classes:
Class NSObject extentions
Class NSObject provides the standard features of all standard classes. That's why we created the category NSObject(SCObject), through which we add support for the mechanisms of our library to all classes at once, primarily support for SCCoding, SCDictionaring, SCStreaming, SCCollectioning and SCDating protocols.
We want to note that compliance with these protocols does not guarantee that an instance of any child class will support the corresponding mechanism, beacuse for full support it is necessary to implement it by overriding the corresponding methods through the creation a category or a child class.
Serialized files support
For supporting serialized files category implements the following methods from the protocol SCCoding:
- (instancetype)initWithCoder:(NSCoder *)coder;
- (instancetype)initWithContentsOfSerializedFile:(NSString *)path;
- (void)encodeWithCoder:(NSCoder *)coder;
- (BOOL)writeContentsToSerializedFile:(NSString *)path;
Data dictionaries support
Category NSObject(SCObject) supports data dictionaries by implementing the following methods of the protocol SCDictionaring:
- (instancetype)initWithDataDictionary:(NSDictionary *)dictionary;
- (instancetype)initWithDataDictionaryFromFile:(NSString *)path;
- (void)writeToDataDictionary:(NSMutableDictionary *)dictionary;
- (void)writeToDataDictionaryFile:(NSString *)path atomically:(BOOL)atomically;
- (void)writeToDataDictionaryFile:(NSString *)path;
- (NSDictionary *)dataDictionary;
Streams support
Category NSObject(SCObject) implements the streams support by declaring the following methods of the protocol SCStreaming:
- (instancetype)initWithStream:(
SCStream *)stream;
- (instancetype)initWithFileStream:(NSString *)path;
- (void)writeToStream:(
SCStream *)stream;
- (void)writeToFileStream:(NSString *)path;
- (void)appendToFileStream:(NSString *)path;
Collections support
For supporting the collections the category NSObject(SCObject) implements the following methods from the protocol SCCollectioning:
Interaction with data objects
Interaction with data objects, files and URLs обеспечивается provides with the following methods of the category NSObject(SCObject):
- (instancetype)initWithData:(NSData *)data;
- (instancetype)initWithContentsOfFile:(NSString *)path;
- (instancetype)initWithContentsOfURL:(NSURL *)url;
- (instancetype)initWithContentsOfURLString:(NSString *)urlString;
- (void)writeToData:(NSMutableData *)data;
- (BOOL)writeToFile:(NSString *)path;
- (BOOL)writeToURL:(NSURL *)url;
- (BOOL)writeToURLString:(NSString *)urlString;
- (NSData *)data;
Class NSNumber extensions
Class NSNumber provides the standard features for working with integers, logical values and float values. Of great importance of this class for all the Objective C has necessitated its extension both in support the SCL standard mechanisms and for entering the additional functionality.
Creating class instances
Category NSNumber(SCNumber) implements the following class methods for creating a numbers by using data from the serialized files, data dictionaries, streams and guideData:
+ (instancetype)numberWithCoder:(NSCoder *)coder;
+ (instancetype)numberWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)numberWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)numberWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)numberWithStream:(
SCStream *)stream;
+ (instancetype)numberWithFileStream:(NSString *)path;
+ (instancetype)numberWithData:(NSData *)data;
+ (instancetype)numberWithContentsOfFile:(NSString *)path;
+ (instancetype)numberWithContentsOfURL:(NSURL *)url;
+ (instancetype)numberWithContentsOfURLString:(NSString *)urlString;
Category NSNumber(SCNumber) declares the following class methods for creating the class instances by using the existing other types data:
+ (instancetype)numberWithNumber:(NSNumber *)number;
+ (instancetype)numberWithByte:(
SCByte)byte;
+ (instancetype)numberWithUnsignedByte:(
SCUByte)byte;
+ (instancetype)numberWithUnichar:(unichar)chr;
- Class method numberWithNumber: returns the number created by using the specified existing number:
NSNumber *source = @2319;
NSNumber *number = [NSNumber numberWithNumber:source];
NSLog( @"%@", number);
2016-09-14 13:48:55.679 libtest[3764:190588] 2319
- Class methods numberWithByte: and numberWithUnsignedByte: return the number created by using the specified signed or unsigned 8-bit integer:
NSLog( @"%@", [NSNumber numberWithByte:-66]);
NSLog( @"%@", [NSNumber numberWithUnsignedByte:115]);
2016-09-14 13:52:54.389 libtest[3811:194414] -66
2016-09-14 13:52:54.390 libtest[3811:194414] 115
- Class method numberWithUnichar: returns the number created by using the specified character:
NSNumber *number = [NSNumber numberWithUnichar:'Z'];
NSLog( @"%@", number);
2016-09-14 14:03:36.193 libtest[3850:198228] 90
Category NSNumber(SCNumber) implements the following class methods for creating the number by using the text representation of the source value:
+ (instancetype)numberWithBinaryString:(NSString *)string;
+ (instancetype)numberWithOctalString:(NSString *)string;
+ (instancetype)numberWithDecimalString:(NSString *)string;
+ (instancetype)numberWithHexadecimalString:(NSString *)string;
+ (instancetype)numberWithString:(NSString *)string;
+ (instancetype)numberWithBoolString:(NSString *)string;
+ (instancetype)numberWithFloatString:(NSString *)string;
+ (instancetype)numberWithDoubleString:(NSString *)string;
- Class method numberWithBinaryString: returns the number created by using the specified text representation of the binary integer value:
NSNumber *number = [NSNumber numberWithBinaryString:@"01100011"];
NSLog( @"%@", number);
2016-09-14 14:05:56.103 libtest[3874:200221] 99
- Class method numberWithOctalString: returns the number created by using the specified text representation of the octal integer value:
NSNumber *number = [NSNumber numberWithOctalString:@"0644"];
NSLog( @"%@", number);
2016-09-14 14:18:30.892 libtest[3921:208773] 420
- Class method numberWithDecimalString: returns the number created by using the specified text representation of the decimal integer value. Method is equals to the class method numberWithString:.
NSNumber *number = [NSNumber numberWithDecimalString:@"283 044"];
NSLog( @"%@", number);
2016-09-14 14:20:40.399 libtest[3936:210127] 283044
- Class method numberWithHexadecimalString: returns the number created by using the specified text representation of the hexadecimal integer value:
NSNumber *number = [NSNumber numberWithHexadecimalString:@"0x0DF4"];
NSLog( @"%@", number);
2016-09-14 14:23:47.962 libtest[3957:212381] 3572
- Class method numberWithString: is equals to the class method numberWithDecimalString: and returns the number created by using the specified text representation of the decimal integer value:
NSNumber *number = [NSNumber numberWithString:@"19091975"];
NSLog( @"%@", number);
2016-09-14 14:26:16.674 libtest[3976:214197] 19091975
- Class method numberWithBoolString: returns the number created by using the specified text representation of the boolean value:
NSNumber *number = [NSNumber numberWithBoolString:@"True"];
NSLog( @"%@", number);
2016-09-14 14:29:39.219 libtest[3996:216535] 1
- Class method numberWithFloatString: returns the number created by using the specified text representation of the float value:
NSNumber *number = [NSNumber numberWithFloatString:@"1909.1975"];
NSLog( @"%@", number);
2016-09-14 14:35:19.441 libtest[4020:221106] 1909.198
- Class method numberWithDoubleString: returns the number created by using the specified text representation of the double value:
NSNumber *number = [NSNumber numberWithDoubleString:@"1975.1909"];
NSLog( @"%@", number);
2016-09-14 14:37:51.538 libtest[4035:222530] 1975.1909
Initializing class instances
Category NSNumber(SCNumber) implements the following methods for initializing the class instances by using the existing other types data:
- (instancetype)initWithNumber:(NSNumber *)number;
- (instancetype)initWithByte:(
SCByte)byte;
- (instancetype)initWithUnsignedByte:(
SCUByte)byte;
- (instancetype)initWithUnichar:(unichar)chr;
- Method initWithNumber: initializes the number using the specified existing number.
- Methods initWithByte: and initWithUnsignedByte: initialize the number using the specified signed or unsigned 8-bit integer.
- Method initWithUnichar: initializes the number using the specified existing character.
Category NSNumber(SCNumber) declares the methods for initializing class instances using the text representation of the source data values:
- (instancetype)initWithBinaryString:(NSString *)string;
- (instancetype)initWithOctalString:(NSString *)string;
- (instancetype)initWithDecimalString:(NSString *)string;
- (instancetype)initWithHexadecimalString:(NSString *)string;
- (instancetype)initWithString:(NSString *)string;
- (instancetype)initWithBoolString:(NSString *)string;
- (instancetype)initWithFloatString:(NSString *)string;
- (instancetype)initWithDoubleString:(NSString *)string;
Class instance properties
Category NSNumber(SCNumber) declares the following properties:
@property (nonatomic, readonly, assign)
SCByte byteValue;
@property (nonatomic, readonly, assign)
SCUByte unsignedByteValue;
@property (nonatomic, readonly, assign) unichar unicharValue;
- Properties byteValue and unsignedByteValue returns the signed or unsigned 8-bit integer representation of the receiving number:
NSNumber *number = [NSNumber numberWithInteger:-74];
NSLog( @"Signed byte: %d", number.byteValue);
NSLog( @"Unsigned byte: %d", [number unsignedByteValue]);
2016-09-14 15:55:07.633 libtest[4421:269305] Signed byte: -74
2016-09-14 15:55:07.633 libtest[4421:269305] Unsigned byte: 182
- Property unicharValue returns the character representation of the receiving number:
NSNumber *number = [NSNumber numberWithInteger:68];
NSLog( @"Unichar: %c", number.unicharValue);
2016-09-14 15:57:51.406 libtest[4445:271133] Unichar: D
Also the category NSNumber(SCNumber) implements the properties for access to the text representations of the numbers:
@property (nonatomic, readonly, assign) NSString *binaryString;
@property (nonatomic, readonly, assign) NSString *octalString;
@property (nonatomic, readonly, assign) NSString *decimalString;
@property (nonatomic, readonly, assign) NSString *string;
@property (nonatomic, readonly, assign) NSString *hexadecimalString;
@property (nonatomic, readonly, assign) NSString *boolString;
@property (nonatomic, readonly, assign) NSString *floatString;
@property (nonatomic, readonly, assign) NSString *doubleString;
- Property binaryString returns the binary text representation of the receiving number:
NSNumber *number = @19091975;
NSLog( @"Binary: %@", number.binaryString);
2016-09-14 16:01:33.879 libtest[4472:273787] Binary: 00000001 00100011 01010010 00000111
- Property octalString returns the octal text representation of the receiving number:
NSNumber *number = @19091975;
NSLog( @"Octal: %@", number.octalString);
2016-09-14 16:02:17.224 libtest[4485:274810] Octal: 110651007
- Properties decimalString and string return the decimal text representation of the receiving object:
NSNumber *number = @19091975;
NSLog( @"Decimal: %@", [number decimalString]);
NSLog( @"Decimal: %@", number.string);
2016-09-14 16:09:20.171 libtest[4501:277438] Decimal: 19091975
2016-09-14 16:09:20.171 libtest[4501:277438] Decimal: 19091975
- Property hexadecimalString returns the hexadecimal text representation of the receiving object:
NSNumber *number = @19091975;
NSLog( @"Hex: %@", number.hexadecimalString);
2016-09-14 16:11:04.706 libtest[4516:278723] Hex: 0000 0000 0123 5207
- Property boolString returns the boolean text representation of the receiving object:
NSNumber *number = @1;
NSLog( @"Boolean: %@", number.boolString);
2016-09-14 16:13:11.751 libtest[4553:280427] Boolean: YES
- Property floatString returns the float text representation of the receiving object:
NSNumber *number = @1909.1975;
NSLog( @"Float: %@", number.floatString);
2016-09-14 16:15:19.865 libtest[4590:281896] Float: 1909.197510
- Property doubleString returns the double text representation of the receiving object:
NSNumber *number = @1909.1975;
NSLog( @"Double: %@", number.doubleString);
2016-09-14 16:17:24.308 libtest[4605:283251] Double: 1909.197500
Type detection
Class NSNumber instance can contain different types of data, which is determined during the instance creating. For information about the type of the number the category NSNumber(SCNumber) uses the property type:
@property (nonatomic, readonly, assign) SCStandardType type;
Property returns the data type ID. See details in the section Standard types.
NSNumber *number = [NSNumber numberWithShort:1909];
if ( number.type ==
SCTypeShort) NSLog(
@"number is signed short");
2016-09-14 17:33:22.302 libtest[5377:337635] number is signed short
Comparing class instances
For comparison the numbers with the other data type values category NSNumber(SCNumber) implements the following comparing methods:
- (BOOL)isEqualToByte:(
SCByte)value;
- (BOOL)isEqualToUnsignedByte:(
SCUByte)value;
- (BOOL)isEqualToShort:(
SCShort)value;
- (BOOL)isEqualToUnsignedShort:(
SCUShort)value;
- (BOOL)isEqualToUnsignedInteger:(
SCUInteger)value;
- (BOOL)isEqualToLongLong:(
SCLong)value;
- (BOOL)isEqualToUnsignedLongLong:(
SCULong)value;
- (BOOL)isEqualToChar:(char)value;
- (BOOL)isEqualToUnichar:(unichar)value;
- (BOOL)isEqualToBool:(BOOL)value;
- (BOOL)isEqualToFloat:(
SCFloat)value;
- (BOOL)isEqualToDouble:(
SCDouble)value;
For comparison the numbers with the its text representations (both as a strings and classic C strings) category NSNumber(SCNumber) declares the following methods:
- (BOOL)isEqualToBinaryString:(NSString *)string;
- (BOOL)isEqualToOctalString:(NSString *)string;
- (BOOL)isEqualToDecimalString:(NSString *)string;
- (BOOL)isEqualToHexadecimalString:(NSString *)string;
- (BOOL)isEqualToString:(NSString *)string;
- (BOOL)isEqualToBoolString:(NSString *)string;
- (BOOL)isEqualToFloatString:(NSString *)string;
- (BOOL)isEqualToDoubleString:(NSString *)string;
Error processing
When working with serialized files, data dictionaries, streams and collections we may encounter a situation where instead of a number object is detected an instance of another class. To indicate this situation we have the exception class SCNumberException, which provide the error SCL-20011.
Class NSNull extensions
CategoryNSNull(SCNull) does not add into the class NSNull no additional features, instead the class methods for creating class instances by using a serialized files, data dictionaries, streams and data objects:
+ (instancetype)nullWithCoder:(NSCoder *)coder;
+ (instancetype)nullWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)nullWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)nullWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)nullWithStream:(
SCStream *)stream;
+ (instancetype)nullWithFileStream:(NSString *)path;
+ (instancetype)nullWithData:(NSData *)data;
+ (instancetype)nullWithContentsOfFile:(NSString *)path;
+ (instancetype)nullWithContentsOfURL:(NSURL *)url;
+ (instancetype)nullWithContentsOfURLString:(NSString *)urlString;
Class NSDate extensions
Category NSDate(SCDate) implements into the class NSDate methods for creating dates by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)dateWithCoder:(NSCoder *)coder;
+ (instancetype)dateWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)dateWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)dateWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)dateWithStream:(
SCStream *)stream;
+ (instancetype)dateWithFileStream:(NSString *)path;
+ (instancetype)dateWithData:(NSData *)data;
+ (instancetype)dateWithContentsOfFile:(NSString *)path;
+ (instancetype)dateWithContentsOfURL:(NSURL *)url;
+ (instancetype)dateWithContentsOfURLString:(NSString *)urlString;
Class NSArray extensions
Categoy NSArray(SCArray) adds into the standard class NSArray features for support the protocols SCCollection and SCIndexedCollection:
Creating arrays
Category NSArray(SCArray) declares the following class methods for creating arrays with data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)arrayWithCoder:(NSCoder *)coder;
+ (instancetype)arrayWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)arrayWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)arrayWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)arrayWithStream:(
SCStream *)stream;
+ (instancetype)arrayWithFileStream:(NSString *)path;
+ (instancetype)arrayWithData:(NSData *)data;
+ (instancetype)arrayWithContentsOfURLString:(NSString *)urlString;
Category NSArray(SCArray) implements the following additional methods for creating arrays:
+ (instancetype)arrayWithCollection:(
id<
SCCollection>)collection;
- Class method arrayWithCollection: returns an array created by using the specified existing collection of any supported type:
NSArray *array = [NSArray arrayWithCollection:source];
NSLog( @"%@", array);
2016-09-15 09:50:39.632 libtest[863:19072] (
00,
10,
20
)
Initializing arrays
Category NSArray(SCArray) declares the following additional initializing methods:
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- Method initWithCollection: initializes an array using the specified existing collection of any supported type.
Protocol SCCollection implementation
The most popular properties of protocol SCCollection in the class NSArray are the following properties implemented in the category NSArray(SCArray):
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL readOnly;
@property (nonatomic, readonly, retain) id<SCCollectionDelegate> delegate;
- Property name declared for compatibility reasons and always returns a nil value.
- Property empty returns the value YES if the receiving array is empty (does not contains any object), otherwise returns value NO:
NSArray *array = [NSArray arrayWithObjects:@"00", @"01", @"02", nil];
if ( !array.empty) NSLog( @"Array contents objects");
2016-09-15 12:56:20.747 libtest[1697:126956] Array contents objects
- Property readOnly returns the value YES if the receiving array does not allows the content changing. Please note that this property of class NSArray always returns the value YES, otherwise the property of the class NSMutableArray instances always returns the value NO, because the class NSArray never allows any changes, otherwise the class NSMutableArray permits changes of its own objects. Also please note, that you cannot change the value of this property of the classes NSArray and NSMutableArray instances.
- Property delegate alwys returns the value nil, because the property is declared in the category only for compatibility purposes.
Also category NSArray(SCArray) implements the following methods for collection type detection from the protocol SCCollection:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
Property collectionType of objects of classes NSArray and NSMutableArray always returns the value SCCollectionFoundationArray.
For the classes NSArray and NSMutableArray instances the value YES return the following collection type detection properties:
- isCollection
- isFoundationCollection
- isArray
- isFoundationArray
- isSortable
Other type detection properties always return the value NO.
Searching array objects
Category NSArray(SCArray) implements the following protocol SCCollection properties and methods for objects searching:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastObject;
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
Converting arrays
Category NSArray(SCArray) implements the following converting properties of the protocol SCCollection:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, assign) NSArray *foundationArray;
@property (nonatomic, readonly, assign) NSSet *foundationSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, assign) NSDictionary *foundationDictionary;
@property (nonatomic, readonly, assign) NSArray *reversedArray;
Sorting arrays
Category NSArray(SCArray) implements the following sorting properties and methods of the protocol SCCollection:
@property (nonatomic, readonly, assign) NSArray *ascendingSortedArray;
@property (nonatomic, readonly, assign) NSArray *descendingSortedArray;
@property (nonatomic, readonly, assign) NSArray *sortedArray;
- (NSArray *)ascendingSortedArrayWithSorter:(
id<
SCSorter>)sorter;
- (NSArray *)descendingSortedArrayWithSorter:(
id<
SCSorter>)sorter;
- (NSArray *)sortedArrayWithSorter:(
id<
SCSorter>)sorter;
Also category implements the methods for creating and initializing the sorted arrays using existing collections of any supported type:
+ (instancetype)arrayWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)arrayWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)arrayWithAscendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)arrayWithDescendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)arrayWithSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithSortedCollection:(
id<
SCCollection>)collection;
Comparing arrays
Additionally to the standard comparing methods the category NSArray(SCArray) implements the following new methods:
- Method isEqualToCollection: compares the array to the specified collection of any supported type.
Deriving new arrays
Category NSArray(SCArray) declares the following methods for deriving new arrays that contains objects from the receiving arrays:
- (NSArray *)arrayByAddingObjects:(id)object, ... NS_REQUIRES_NIL_TERMINATION;
- (NSArray *)arrayByAddingArray:(NSArray *)array;
- (NSArray *)arrayByAddingCollection:(
id<
SCCollection>)collection;
- Method arrayByAddingObjects: creates and returns an array that contains objects from receiving array and objects from the specified list:
NSArray *array = @[ @200, @600, @800, @400];
NSLog( @"%@", [array arrayByAddingObjects:@300, @500, nil]);
2017-06-06 17:15:58.848438+0300 libtest[81129:4801463] (
200,
600,
800,
400,
300,
500
)
- Method arrayByAddingArray: returns a new array with objects from the receiving array and objects from the specified array (combining arrays). This method is an analog of the method arrayByAddingObjectsFromArray:.
NSArray *array = @[ @200, @600, @800, @400];
NSLog( @"%@", [array arrayByAddingArray:@[ @100, @700]]);
2017-06-06 17:15:58.848680+0300 libtest[81129:4801463] (
200,
600,
800,
400,
100,
700
)
- Method arrayByAddingCollection: returns an array that combines objects from the receiving array and objects from the specified collection of any supported type:
NSArray *array = @[ @200, @600, @800, @400];
NSSet *set = [NSSet setWithObjects:@"One", @"Two", nil];
NSLog( @"%@", [array arrayByAddingCollection:set]);
2017-06-06 17:15:58.849211+0300 libtest[81129:4801463] (
200,
600,
800,
400,
One,
Two
)
Class NSMutableArray extensions
Category NSMutableArray(SCMutableArray) extends the class NSMutableArray by implementing the methods of the protocols SCMutableCollection and SCMutableIndexedCollection. Also the class NSMutableArray inherits all extensions from the category NSArray(SCArray).
Copying arrays
Category NSMutableArray(SCMutableArray) implements the following copying methods of the protocol SCMutableCollection:
Additionally, category NSMutableArray(SCMutableArray) implements the methods for copying into the array the sorted content of the existing collections of any supported type:
- (void)setAscendingSortedCollection:(
id<
SCCollection>)collection;
- (void)setDescendingSortedCollection:(
id<
SCCollection>)collection;
Adding objects to array
Category NSMutableArray(SCMutableArray) implements the following adding methods:
Also the category NSMutableArray(SCMutableArray) declares the method addArray: that adds into the receiving array objects from the specified array:
- (void)addArray:(NSArray *)array;
NSMutableArray *array = [NSMutableArray arrayWithArray:@[ @200, @600, @800, @400]];
[array addArray:@[ @100, @500]];
NSLog( @"%@", array);
2017-06-08 09:59:42.981230+0300 libtest[84484:5850646] (
200,
600,
800,
400,
100,
500
)
Removing objects from array
Category NSMutableArray(SCMutableArray) implements the following removing methods of the protocol SCMutableCollection:
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
Replacing objects
Category NSMutableArray(SCMutableArray) implements the following objects replacing methods of the protocol SCMutableCollection:
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withCollection:(
id<
SCCollection>)collection;
- (void)replaceObjectsInRange:(NSRange)range withObjects:(
id<
SCCollectioning>)object, ...;
- (void)replaceObjectsInRange:(NSRange)range withCollection:(
id<
SCCollection>)collection;
Sorting arrays
Category NSMutableArray(SCMutableArray) declares the following sorting methods:
- (void)sortAscendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortDescendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortWithSorter:(
id<
SCSorter>)sorter;
- (void)sortAscending;
- (void)sortDescending;
- (void)sort;
Advanced methods
Also category NSMutableArray(SCMutableArray) implements the following additional methods:
- (void)copyObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)moveObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- (void)reverse;
- Method copyObjectAtIndex:toIndex: copies the object at the specified index to a given destination index.
- Method moveObjectAtIndex:toIndex: moves the object at the specified index to a given destination index.
- Method reverse returns the array with the all objects from the receiving array in reverse order.
Class NSSet extensions
Category NSSet(SCSet) appends into the standard class NSSet support of the serialized files, data dictionaries and streams. Also the category implements the methods for compatibility with the collections and primarily with the class SCSet:
Creating sets
Category NSSet(SCSet) declares the following methods for creating sets with data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)setWithCoder:(NSCoder *)coder;
+ (instancetype)setWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)setWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)setWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)setWithStream:(
SCStream *)stream;
+ (instancetype)setWithFileStream:(NSString *)path;
+ (instancetype)setWithData:(NSData *)data;
+ (instancetype)setWithContentsOfFile:(NSString *)path;
+ (instancetype)setWithContentsOfURL:(NSURL *)url;
+ (instancetype)setWithContentsOfURLString:(NSString *)urlString;
Category implements the following class methods for creating class instances:
+ (instancetype)setWithCollection:(
id<
SCCollection>)collection;
Initializing sets
Category declares the following additional initializing methods:
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
Protocol SCCollection implementation
To comply with the SCCollection protocol the category NSSet(SCSet) implements the following properties:
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL readOnly;
@property (nonatomic, readonly, retain) id<SCCollectionDelegate> delegate;
- Property name is declared for compatibility purposes and always returns a value nil.
- Property empty returns the value NO if the set contains at least one object and returns the value NO if the set does not contains objects.
- Property readOnly determines the possibility of changes. For the class NSSet instances property always returns the value YES. Property of the class NSMutableSet instance always returns the value NO.
- Property delegate always returns a nil value and declared for compatibility with the library collections.
Also category implements the collection type detection properties from the protocol SCCollection:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
Property collectionType of objects of classes SCSet and NSMutableSet always returns the value SCCollectionFoundationSet.
For the classes NSSet and NSMutableSet the value YES returns methods isCollection, isFoundationCollection, isSet and isFoundationSet. Other collection type detection methods return the value NO.
Searching set objects
Category NSSet(SCSet) implements the following searching methods from the protocol SCCollection:
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
Converting sets
Category declares the following converting properties:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, assign) NSArray *foundationArray;
@property (nonatomic, readonly, assign) NSSet *foundationSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, assign) NSDictionary *foundationDictionary;
Comparing sets
Additionally to the standard comparing methods the category NSSet(SCSet) implements the following new methods:
- Method isEqualToCollection: compares the set to the specified collection of any supported type.
Deriving new sets
Category NSSet(SCSet) implements the following methods for deriving new sets by using objects from existing sets:
- (NSSet *)setByAddingObjects:(id)object, ...;
- (NSSet *)setByAddingArray:(NSArray *)array;
- (NSSet *)setByAddingSet:(NSSet *)set;
- (NSSet *)setByAddingCollection:(
id<
SCCollection>)collection;
- Method setByAddingObjects: returns a new set that contains objects from the receiving set and objects from a given list:
NSSet *set = [NSSet setWithObjects:@200, @400, @800, nil];
NSLog( @"%@", [set setByAddingObjects:@100, @500, nil]);
2017-06-08 12:30:41.749466+0300 libtest[87520:5957625] {(
500,
800,
100,
400,
200
)}
- Method setByAddingArray: creates a new set that contains objects from the receiving set and a given array:
NSSet *set = [NSSet setWithObjects:@200, @400, @800, nil];
NSLog( @"%@", [set setByAddingArray:@[ @"One", @"Two"]]);
2017-06-08 13:00:41.647159+0300 libtest[87981:5976878] {(
Two,
800,
One,
400,
200
)}
- Method setByAddingSet: creates a new set that contains objects from the receiving set and a given set:
NSSet *set = [NSSet setWithObjects:@200, @400, @800, nil];
NSLog( @"%@", [set setByAddingArray:@[ @"One", @"Two"]]);
2017-06-08 13:00:41.647159+0300 libtest[87981:5976878] {(
Two,
800,
One,
400,
200
)}
- Method setByAddingCollection: returns a new set that contains objects from the receiving set and a given collection of any supported type:
NSSet *set = [NSSet setWithObjects:@200, @400, @800, nil];
NSLog( @"%@", [set setByAddingCollection:source]);
2017-06-08 13:13:18.770057+0300 libtest[88634:5987272] {(
800,
MacOS,
400,
200,
Windows
)}
Class NSMutableSet extensions
Category NSMutableSet(SCMutableSet) extends the class NSMutableSet functions by implements the methods of the protocol SCMutableCollection:
Copying sets
Category implements the following copying methods from the protocol SCMutableCollection:
Adding objects to set
Category NSMutableSet(SCMutableSet) implements the following methods of the procotol SCMutableCollection for adding objects into the sets:
Also the category declares the following methods for adding objects:
- (void)addArray:(NSArray *)array;
- (void)addObjectsFromSet:(NSSet *)set;
- (void)addSet:(NSSet *)set;
- Method addArray: adds into the receiving set the objects from a given array:
NSMutableSet *set = [NSMutableSet setWithObjects:@200, @400, @800, nil];
[set addArray:@[ @100, @500]];
NSLog( @"%@", set);
2017-06-08 13:32:32.062581+0300 libtest[89249:6001158] {(
500,
800,
100,
400,
200
)}
- Methods addObjectsFromSet: and addSet: add into the receiving set the objects from a given set:
NSSet *source = [NSSet setWithObjects:@"One", @"Two", nil];
NSMutableSet *set = [NSMutableSet setWithObjects:@200, @400, @800, nil];
[set addObjectsFromSet:source];
NSLog( @"%@", set);
2017-06-08 13:43:53.246534+0300 libtest[89585:6010909] {(
Two,
800,
One,
400,
200
)}
Removing objects from set
Category implements the following methods for removing objects from set:
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
Class NSOrderedSet extensions
Category NSOrderedSet(SCOrderedSet) implements in the ordered sets the methods and properties from the protocols SCCollection and SCIndexedCollection:
Creating ordered sets
Category declares the following methods for creating an ordered sets with data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)orderedSetWithCoder:(NSCoder *)coder;
+ (instancetype)orderedSetWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)orderedSetWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)orderedSetWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)orderedSetWithStream:(
SCStream *)stream;
+ (instancetype)orderedSetWithFileStream:(NSString *)path;
+ (instancetype)orderedSetWithData:(NSData *)data;
+ (instancetype)orderedSetWithContentsOfFile:(NSString *)path;
+ (instancetype)orderedSetWithContentsOfURL:(NSURL *)url;
+ (instancetype)orderedSetWithContentsOfURLString:(NSString *)urlString;
Also the caregory implements the following methods for creating a class instances:
+ (instancetype)orderedSetWithCollection:(
id<
SCCollection>)collection;
- Class method orderedSetWithCollection: returns an ordered set created by using the specified existing collection of any supported type.
Initializing ordered sets
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- Method initWithCollection: initializes an ordered set using the specified existing collection of any supported type.
Protocol SCCollection implementation
Category NSOrderedSet(SCOrderedSet) implements the following properties of the SCCollection protocol:
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL readOnly;
@property (nonatomic, readonly, retain) id<SCCollectionDelegate> delegate;
- Property name declared for compatibility reasons and always returns a nil value.
- Property empty returns the value YES if the receiving ordered set does not contains any objects, otherwise returns the value NO.
- Property readOnly returns a boolean value, which is determine the read only mode of the receiving ordered set. Property of the class NSOrderedSet always returns the value YES, instead the instances of the class NSMutableOrderedSet, which property always returns the value NO. You cannot change the value of this property.
- Property delegate alwys returns the value nil, because the property is declared in the category only for compatibility purposes.
The following properties of the protocol SCCollection and category NSOrderedSet(SCOrderedSet) determines the receiving collection type:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
Property collectionType of objects of classes SCOrderedSet and NSMutableOrderedSet always returns the value SCCollectionFoundationOrderedSet.
The methods isCollection, isFoundationCollection, isOrderedSet and isFoundationOrderedSet for class NSOrderedSet instances always return the value YES.
Searching ordered set objects
Category NSOrderedSet(SCOrderedSet) implements the following searching properties of the protocol SCCollection:
@property (nonatomic, readonly, assign)
SCIndex indexOfLastObject;
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
Converting ordered sets
Category NSOrderedSet(SCOrderedSet) supports operations of converting the ordered sets into the collections of any supported type:
@property (nonatomic, readonly, assign)
SCArray *libraryArray;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, assign) NSArray *foundationArray;
@property (nonatomic, readonly, assign) NSSet *foundationSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, assign) NSDictionary *foundationDictionary;
Sorting ordered sets
Category NSOrderedSet(SCOrderedSet) implements properties and methods thatreturn the sorted ordered sets:
@property (nonatomic, readonly, assign) NSOrderedSet *ascendingSortedOrderedSet;
@property (nonatomic, readonly, assign) NSOrderedSet *descendingSortedOrderedSet;
@property (nonatomic, readonly, assign) NSOrderedSet *sortedOrderedSet;
- (NSOrderedSet *)ascendingSortedOrderedSetWithSorter:(
id<
SCSorter>)sorter;
- (NSOrderedSet *)descendingSortedOrderedSetWithSorter:(
id<
SCSorter>)sorter;
- (NSOrderedSet *)sortedOrderedSetWithSorter:(
id<
SCSorter>)sorter;
Also category declares the methods for creating and initializing sorted ordered sets by using the existing collections of any supported type:
+ (instancetype)orderedSetWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
+ (instancetype)orderedSetWithAscendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)orderedSetWithDescendingSortedCollection:(
id<
SCCollection>)collection;
+ (instancetype)orderedSetWithSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection sorter:(
id<
SCSorter>)sorter;
- (instancetype)initWithAscendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithDescendingSortedCollection:(
id<
SCCollection>)collection;
- (instancetype)initWithSortedCollection:(
id<
SCCollection>)collection;
Comparing ordered sets
Additionally to the standard comparing methods the category NSOrderedSet(SCOrderedSet) implements the following new methods:
- Method isEqualToCollection: compares the ordered set to the specified collection of any supported type.
Deriving new ordered sets
Category NSOrderedSet(SCOrderedSet) declares the following methods for deriving new ordered sets:
- (NSOrderedSet *)orderedSetByAddingObject:(id)object;
- (NSOrderedSet *)orderedSetByAddingObjects:(id)object, ... NS_REQUIRES_NIL_TERMINATION;
- (NSOrderedSet *)orderedSetByAddingCollection:(
id<
SCCollection>)collection;
- (NSOrderedSet *)orderedSetByAddingArray:(NSArray *)array;
- (NSOrderedSet *)orderedSetByAddingSet:(NSSet *)set;
- (NSOrderedSet *)orderedSetByAddingOrderedSet:(NSOrderedSet *)orderedSet;
- Method orderedSetByAddingObject: returns a new ordered set with objects from the receiving ordered set and with a given object:
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingObject:@600]);
2017-06-13 09:54:45.904177+0300 libtest[96827:6953327] {(
200,
800,
400,
600
)}
- Method orderedSetByAddingObjects: creates a new ordered set that contains objects from the receiving ordered set and objects from a given list:
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingObjects:@100, @500, nil]);
2017-06-13 10:31:05.062206+0300 libtest[97289:6977535] {(
200,
800,
400,
100,
500
)}
- Method orderedSetByAddingCollection: returns an ordered set that contains objects from the receiving ordered set and objects from a given collection of any supported type:
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingCollection:array]);
2017-06-13 10:52:36.237174+0300 libtest[97634:6991939] {(
200,
800,
400,
One,
Two
)}
- Method orderedSetByAddingArray: creates and returns a new ordered set with objects from the receiving ordered set and objects from a given array:
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingArray:@[ @"MacOS", @"FreeBSD"]]);
2017-06-13 11:21:04.015942+0300 libtest[97996:7014741] {(
200,
800,
400,
MacOS,
FreeBSD
)}
- Method orderedSetByAddingSet: creates a new ordered set with objects from the receiving ordered set and objects from a given set:
NSSet *source = [NSSet setWithObjects:@"Solaris", @"SunOS", nil];
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingSet:source]);
2017-06-13 11:32:15.082294+0300 libtest[98380:7025724] {(
200,
800,
400,
Solaris,
SunOS
)}
- Method orderedSetByAddingOrderedSet: returns a new ordered set that contains objects from the receiving ordered set and objects from a given ordered set:
NSOrderedSet *source = [NSOrderedSet orderedSetWithObjects:@"Windows", @"Linux", nil];
NSOrderedSet *set = [NSOrderedSet orderedSetWithObjects:@200, @800, @400, nil];
NSLog( @"%@", [set orderedSetByAddingOrderedSet:source]);
2017-06-13 11:47:40.266219+0300 libtest[98717:7035664] {(
200,
800,
400,
Windows,
Linux
)}
Advanced methods
Additionally, the category NSOrderedSet(SCOrderedSet) implements the properties not related to any functional group:
@property (nonatomic, readonly, assign) NSArray* allObjects;
- Property allObjects returns the array, which contains the all objects from the receiving ordered set. This method is equals to the property foundationArray.
Class NSMutableOrderedSet extensions
Category NSMutableOrderedSet(SCMutableOrderedSet) implements into the mutable ordered sets the protocols SCMutableCollection and SCMutableIndexedCollection functionality:
Copying ordered sets
To support the copying methods of the protocol SCMutableCollection category NSMutableOrderedSet(SCMutableOrderedSet) implements these methods in the class NSMutableOrderedSet:
- (void)setSet:(NSSet *)set;
- (void)setOrderedSet:(NSOrderedSet *)orderedSet;
- Method setSet: replaces the contents of the receiving ordered set of contents from the specified set.
- Method setOrderedSet: replaces the contents of the receiving ordered set with objects from the specified ordered set.
- Method setCollection: replaces the content of the receiving ordered set of content from the specified existing collection of any supported type.
- Method setObject: replaces the content of the receiving ordered set of the specified existing object.
- Method setObjects: replace the content of the receiving ordered set of the existing objects from the specified nil terminated list.
Adding objects to ordered set
To comply with the protocol SCMutableCollection category NSMutableOrderedSet(SCMutableOrderedSet) implements the following methods for adding objects into the ordered set:
- (void)addArray:(NSArray *)array;
- (void)addObjectsFromSet:(NSSet *)set;
- (void)addSet:(NSSet *)set;
- (void)addObjectsFromOrderedSet:(NSOrderedSet *)orderedSet;
- (void)addOrderedSet:(NSOrderedSet *)orderedSet;
- Method addObjects: adds into the receiving ordered set the objects from the specified nil terminated list.
- By using the method addCollection: you can add into the receiving ordered set the objects from the specified existing collection of any supported type.
- Method addArray: adds the objects from a given array into the receiving ordered set.
- Methods addObjectsFromSet: and addSet: allows adding objects from the specified set into the receving ordered set.
- Methods addObjectsFromOrderedSet: and addOrderedSet: adds the objects from a given ordered set into the receiving ordered set.
Removing objects from ordered set
Category implements the following removing methods of the protocol SCMutableCollection:
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
- Method removeObjectsWithClass: removes from the receiving ordered set all objects of the specified class.
- Method removeObjectsWithClassName: removes from the receiving ordered set all objects of the specified class name.
- Method removeCollection: removes from the receiving ordered set the objects in the specified collection of any supported type.
- Method removeObjects: removes from the receiving ordered set the objects from the specified nil terminated list.
Replacing objects
Category NSMutableOrderedSet(SCMutableOrderedSet) implements the following methods for replacing objects within the ordered set:
- (void)replaceObjectsAtIndexes:(NSIndexSet *)indexes withCollection:(
id<
SCCollection>)collection;
- Method replaceObjectsAtIndexes:withCollection: replaces the objects in the receiving ordered set at the specified locations with the objects from a given collection of any supported type.
Sorting ordered sets
Sort of ordered set objects is performed by the following methods of the category:
- (void)sortAscendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortDescendingWithSorter:(
id<
SCSorter>)sorter;
- (void)sortWithSorter:(
id<
SCSorter>)sorter;
- (void)sortAscending;
- (void)sortDescending;
- (void)sort;
Additionally, the category implements the methods for replacing the receiving ordered set content of the sorted content of the specified existing collections of any supported type:
- (void)setAscendingSortedCollection:(
id<
SCCollection>)collection;
- (void)setDescendingSortedCollection:(
id<
SCCollection>)collection;
Advanced methods
Category NSMutableOrderedSet(SCMutableOrderedSet) implements the following advanced methods:
- (void)moveObjectAtIndex:(
SCIndex)index toIndex:(
SCIndex)destination;
- Method moveObjectAtIndex:toIndex: moves the object at the specified index to a given destination index.
Class NSDictionary extensions
Category NSDictionary(SCDictionary) extends the standard class NSDictionary by adding the support of the protocol SCCollection. These extensions not only added the new functionality but also provide class compatibility with the SCL:
Creating dictionaries
Category implements the following methods for creating a dictionaries with data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)dictionaryWithCoder:(NSCoder *)coder;
+ (instancetype)dictionaryWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)dictionaryWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)dictionaryWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)dictionaryWithStream:(
SCStream *)stream;
+ (instancetype)dictionaryWithFileStream:(NSString *)path;
+ (instancetype)dictionaryWithData:(NSData *)data;
+ (instancetype)dictionaryWithContentsOfURLString:(NSString *)urlString;
Category declares the following methods for creating dictionaries:
+ (instancetype)dictionaryWithCollection:(
id<
SCCollection>)collection;
- Class method dictionaryWithCollection: returns a dictionary created by using the specified existing collection of any supported type. If the source collection does not dictionary (library or foundation) then the keys for added objects generate automatically.
NSDictionary *dictionary = [NSDictionary dictionaryWithCollection:source];
NSLog( @"%@", dictionary);
2016-09-19 16:33:51.614 libtest[1167:87256] {
"Key 0" = 000;
"Key 1" = 100;
"Key 2" = 200;
}
Initializing dictionaries
Category NSDictionary(SCDictionary) declares the following initialization methods:
- (instancetype)initWithCollection:(
id<
SCCollection>)collection;
- Method initWithCollection: initializes a dictionary using the specified existing collection of any supported type.
Protocol SCCollection implementation
Category implements the following properties of the SCCollection protocol:
@property (nonatomic, readonly, retain) NSString *name;
@property (nonatomic, readonly, assign) BOOL empty;
@property (nonatomic, readonly, assign) BOOL readOnly;
@property (nonatomic, readonly, retain) id<SCCollectionDelegate> delegate;
- Property name declared for compatibility reasons and always returns a nil value.
- Property empty returns value NO if the receiving dictionary contains at least one object, otherwise returns the YES value.
- Property readOnly determines, can you change the contents of the receiving dictionary. Please note, that the NSDictionary class instances is always read only, otherwise the instances of the class NSMutableDictionary is always read and write.
- Property delegate alwys returns the value nil, because the property is declared in the category only for compatibility purposes.
Also category implements the collection type detection properties:
@property (nonatomic, readonly, assign) BOOL isCollection;
@property (nonatomic, readonly, assign) BOOL isLibraryCollection;
@property (nonatomic, readonly, assign) BOOL isFoundationCollection;
@property (nonatomic, readonly, assign) BOOL isArray;
@property (nonatomic, readonly, assign) BOOL isLibraryArray;
@property (nonatomic, readonly, assign) BOOL isFoundationArray;
@property (nonatomic, readonly, assign) BOOL isSet;
@property (nonatomic, readonly, assign) BOOL isLibrarySet;
@property (nonatomic, readonly, assign) BOOL isFoundationSet;
@property (nonatomic, readonly, assign) BOOL isOrderedSet;
@property (nonatomic, readonly, assign) BOOL isLibraryOrderedSet;
@property (nonatomic, readonly, assign) BOOL isFoundationOrderedSet;
@property (nonatomic, readonly, assign) BOOL isDictionary;
@property (nonatomic, readonly, assign) BOOL isLibraryDictionary;
@property (nonatomic, readonly, assign) BOOL isFoundationDictionary;
@property (nonatomic, readonly, assign) BOOL isStack;
@property (nonatomic, readonly, assign) BOOL isQueue;
@property (nonatomic, readonly, assign) BOOL isList;
@property (nonatomic, readonly, assign) BOOL isSortable;
Property collectionType of objects of classes NSDictionary and NSMutableDictionary always returns the value SCCollectionFoundationDictionary.
For the instances of the classes NSDictionary and NSMutableDictionary return the YES value the methods isCollection, isFoundationCollection, isDictionary and isFoundationDictionary. Other methods return the NO value.
Searching dictionary objects and keys
Category declares the following object search methods of the protocol <SCCollection>:
- (BOOL)containsAnyObjectFromCollection:(
id<
SCCollection>)collection;
- Method containsObject: returns a Boolean value that indicates whether a equovalent of the given object is present in the receiving dictionary.
- Method containsObjects: returns a Boolean value that indicates whether the receiving dictionary contains the all objects from the specified nil terminated list.
- Method containsCollection: returns a Boolean value that indicates whether the receiving dictionary contains the all objects from the specified collection of any supported type.
- Method containsAnyObject: returns a Boolean value that indicates whether the receiving dictionary contains at least one object from the specified nil terminated list.
- Method containsAnyObjectFromCollection: returns a Boolean value that indicates whether the receiving dictionary contains at least one object from the specified collection of any supported type.
Also the category NSDictionary(SCDictionary) implements the following methods for finding keys:
- (BOOL)containsKey:(id)key;
- (BOOL)containsKeys:(id)key, ... NS_REQUIRES_NIL_TERMINATION;
- (BOOL)containsKeysFromCollection:(
id<
SCCollection>)collection;
- (BOOL)containsAnyKey:(id)key, ... NS_REQUIRES_NIL_TERMINATION;
- (BOOL)containsAnyKeyFromCollection:(
id<
SCCollection>)collection;
- Method containsKey: returns a Boolean value that indicates whether the object for a given key is present in the receiving dictionary.
- Method containsKeys: returns a Boolean value that indicates whether the receiving dictionary contains objects for all keys from the specified list.
- Method containsKeysFromCollection: returns a Boolean value that indicates whether the receiving dictionary contains objects for all keys from a given collection of any supported type.
- Method containsAnyKey: returns a Boolean value that indicates whether the receiving dictionary contsinas objects for at least one key from the specified list.
- Method containsAnyKeyFromCollection: returns a Boolean value that indicates whether the receiving dictionary contains object for at least one key from a given collection of any supported type.
Accessing Keys and Values
Method getObjectForKey: creates and returns an object for a given key that stores in a data dictionaries format, that saves the type of a key and object.
Converting dictionaries
Category implements the following converting properties:
@property (nonatomic, readonly, assign)
SCArray *array;
@property (nonatomic, readonly, assign)
SCSet *set;
@property (nonatomic, readonly, assign)
SCOrderedSet *orderedSet;
@property (nonatomic, readonly, assign)
SCDictionary *dictionary;
@property (nonatomic, readonly, assign)
SCStack *stack;
@property (nonatomic, readonly, assign)
SCQueue *queue;
@property (nonatomic, readonly, assign) NSArray *foundationArray;
@property (nonatomic, readonly, assign) NSSet *foundationSet;
@property (nonatomic, readonly, assign) NSOrderedSet *foundationOrderedSet;
@property (nonatomic, readonly, assign) NSDictionary *foundationDictionary;
Comparing dictionaries
Additionally to the standard comparing methods the category NSDictionary(SCDictionary) implements the following new methods:
- Method isEqualToCollection: compares the dictionary to the specified collection of any supported type.
Deriving new dictionaries
Category NSDictionary(SCDictionary) implements the following methods for deriving new dictionaries by using existing dictionaries:
- (NSDictionary *)dictionaryByAddingObject:(id)object forKey:(id)key;
- (NSDictionary *)dictionaryByAddingObject:(id)object;
- (NSDictionary *)dictionaryByAddingObjects:(NSArray *)objects forKeys:(NSArray *)keys;
- (NSDictionary *)dictionaryByAddingObjects:(id)object, ...;
- (NSDictionary *)dictionaryByAddingObjectsAndKeys:(id)object, ...;
- (NSDictionary *)dictionaryByAddingCollection:(
id<
SCCollection>)collection;
- (NSDictionary *)dictionaryByAddingObjectsFromArray:(NSArray *)array;
- (NSDictionary *)dictionaryByAddingArray:(NSArray *)array;
- (NSDictionary *)dictionaryByAddingEntriesFromDictionary:(NSDictionary *)dictionary;
- (NSDictionary *)dictionaryByAddingDictionary:(NSDictionary *)dictionary;
- Method dictionaryByAddingObject:forKey: returns a new dictionary that contains entries from the receiving dictionary and a new entry with a given object and key:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingObject:@"samond" forKey:@"Login"]);
2017-06-13 16:16:51.760288+0300 libtest[6204:7223688] {
Version = 10.12.5;
System = MacOS;
Login = samond
}
- Method dictionaryByAddingObject: creates a new dictionary by using entries from the receiving dictionary and a new entry with the specified object and automatic generated key:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingObject:@"Steve Samond"]);
2017-06-13 16:30:36.323358+0300 libtest[6632:7235273] {
Version = 10.12.5;
System = MacOS;
"Key 2" = "Steve Samond"
}
- Method dictionaryByAddingObjects:forKeys: returns a dictionary with entries from the receiving dictionary and new entries created by using objects and keys from a given collections:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingObjects:@[ @"root", @"System Administrator"]
forKeys:@[ @"Login", @"Description"]]);
2017-06-13 16:45:53.918349+0300 libtest[7032:7245740] {
Version = 10.12.5;
Description = "System Administrator";
Login = root;
System = MacOS
}
- Method dictionaryByAddingObjects: creates a dictionary that contains entries from the receiving dictionary and entries constructed by using objects from a given list with automatic generated keys:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingObjects:@"root", @"daemon", nil]);
2017-06-13 17:11:45.588804+0300 libtest[7379:7260638] {
"Key 2" = root;
Version = 10.12.5;
System = MacOS;
"Key 3" = daemon
}
- Method dictionaryByAddingObjectsAndKeys: returns a new dictionary that contains entries from the receiving dictionary and new entries constructed by using objects and keys from a given list:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingObjectsAndKeys:@"root", @"Login", nil]);
2017-06-13 17:22:12.677010+0300 libtest[7715:7268599] {
Version = 10.12.5;
System = MacOS;
Login = root
}
- Method dictionaryByAddingCollection: creates a new dictionary with entries from the receiving dictionary and entries from a given collection of any supported type:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingCollection:@{ @"Login":@"root", @"Status":@"Active"}]);
2017-06-13 17:37:02.700361+0300 libtest[8049:7278868] {
Version = 10.12.5;
Login = root;
Status = Active;
System = MacOS
}
- Methods dictionaryByAddingObjectsFromArray: and dictionaryByAddingArray: return a dictionary that contains entries from the receiving dictionary and entries constructed by using objects from array and automatic generated keys:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingArray:@[ @"root", @"news"]]);
2017-06-13 17:45:55.676151+0300 libtest[8379:7285531] {
"Key 2" = root;
Version = 10.12.5;
System = MacOS;
"Key 3" = news
}
- Methods dictionaryByAddingEntriesFromDictionary: and dictionaryByAddingDictionary: creates a dictionary with entries from the receiving dictionary and entries from a given another dictionary:
NSDictionary *dictionary = @{ @"System":@"MacOS", @"Version":@"10.12.5"};
NSLog( @"%@", [dictionary dictionaryByAddingDictionary:@{ @"Login":@"root", @"Level":@0}]);
2017-06-13 17:56:59.819060+0300 libtest[8775:7294359] {
Version = 10.12.5;
Login = root;
System = MacOS;
Level = 0
}
Class NSMutableDictionary extensions
Category NSMutableDictionary(SCMutableDictionary) extends the class NSMutableDictionary by adding the functionality of the protocol SCMutableCollection:
Copying dictionaries
Category implements the following protocol SCMutableCollection methods:
- Method setCollection: replaces the content of the receiving dictionary by content from the specified existing collection of any supported type.
- Method setObject: replaces the content of the receiving dictionary by the specified existing object.
- Method setObjects: replaces the receiving dictionary content by the objects from the specified nil terminated list.
Adding objects to dictionary
Category implements the following adding methods of the SCMutableCollection protocol. These methods generate keys for added objects automatically, except some situations of the method addCollection:.
- (void)addObjectsFromArray:(NSArray *)array;
- (void)addArray:(NSArray *)array;
- (void)addDictionary:(NSDictionary *)dictionary;
- (void)addObjectsAndKeys:(id)object, ...;
- Method addObject: adds into the receiving dictionary the specified existing object.
- Method addObjects: adds into the receiving dictionary the existing objects from the specified nil terminated list.
- Method addCollection: adds into the receiving dictionary the objects from the specified collection of any supported type. If the collection does not a dictionary, then the method generates the keys for added objects automatically.
- Methods addObjectsFromArray: and addArray add into the receiving dictionary objects from the specified array. Keys for these objects are automatically generated.
- Method addDictionary: adds into the receiving dictionary the entries from a given another dictionary.
- Method addObjects:forKeys: adds into the receiving dictionary the entries constructed by using the contents of a given array of objects and array of keys.
- Method addObjectsAndKeys: adds to the receiving dictionary the entries constructed from the specified set of objects and keys.
- Method addObject:forKey: adds into the receiving dictionary the specified object with a given key by using a data dictionaries format for storing a key and object types.
Removing objects from dictionary
For removing objects from the dictionaries category NSMutableDictionary(SCMutableDictionary) implements the following methods of the protocol SCMutableCollection:
- (void)removeObjectsWithClass:(Class)oclass;
- (void)removeObjectsWithClassName:(NSString *)name;
Class NSData extensions
Category NSData(SCData) implements into the class NSData methods for creating a data objects by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)dataWithCoder:(NSCoder *)coder;
+ (instancetype)dataWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)dataWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)dataWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)dataWithStream:(
SCStream *)stream;
+ (instancetype)dataWithFileStream:(NSString *)path;
+ (instancetype)dataWithContentsOfURLString:(NSString *)urlString;
Class NSIndexSet extentions
Category NSIndexSet(SCIndexSet) implements in the class NSIndexSet methods for creating an index sets by using the data from the serialized files, data dictionaries, streams and data objects:
+ (instancetype)indexSetWithCoder:(NSCoder *)coder;
+ (instancetype)indexSetWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)indexSetWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)indexSetWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)indexSetWithStream:(
SCStream *)stream;
+ (instancetype)indexSetWithFileStream:(NSString *)path;
+ (instancetype)indexSetWithData:(NSData *)data;
+ (instancetype)indexSetWithContentsOfFile:(NSString *)path;
+ (instancetype)indexSetWithContentsOfURL:(NSURL *)url;
+ (instancetype)indexSetWithContentsOfURLString:(NSString *)urlString;
Also category declares the following methods for creating index sets:
+ (instancetype)indexSetWithIndexSet:(NSIndexSet *)indexSet;
- Method indexSetWithIndexSet: creates and returns a copy of an existing index set.
Classes and categories for macOS
- Warning
- Classes and categories described in this section are supported only in the operation system macOS and a limited support with the GNUstep.
Section desctibes the following components:
Category NSButton(SCButton)
Category NSButton(SCButton) extends the standard class NSButton by declaring the following property:
@property (nonatomic, readwrite, assign) BOOL boolState;
This property allows to set the state of the interface button by using the boolean value:
- if you set the property to boolean value YES, then the button state is set to the status NSOnState
- if you assign the value NO to the property, then the state of the button is set to the status NSOffState
Category NSAlert(SCAlert)
The standard class NSAlert implements the interface for using the alerts with the various messages and buttons for the request the user response. The next image contains the sample of the alert, which is required the user response before the deleting action:
Although its capabilities, class NSAlert to operate it requires a large number of parameters, which makes this class is not the most comfortable to use. To solve this issue, we developed our extentions as a category NSAlert(SCAlert). Thid section details considering our additions to the class:
Alert styles
Opeationg system macOS defines the following alert styles:
NSAlertStyleCritical - critical alert with the error message
NSAlertStyleWarning - alert with the warning message
NSAlertStyleInformational - alert with the informational text
Creating and initializing alerts
Category NSAlert(SCAlert) declares the following method for creating a generic alert:
+ (instancetype)alertWithStyle:(NSAlertStyle)style
message:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
A method returns the pointer to the alert with the specified style, message text, informative text and a comma-separated list of the button titles, ending with nil pointer. For creating the sample alert from the previous section You can use the following code:
NSAlert *alert = [NSAlert criticalAlertWithMessage:@"Confirm the deleting of the selected user:"
text:@"John Smith"
buttons:@"Yes", @"No", @"Help", nil];
[alert runModal];
Also the category NSAlert(SCAlert) declares the following methods for creating an alerts:
+ (instancetype)criticalAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (instancetype)criticalAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (instancetype)criticalAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (instancetype)warningAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (instancetype)warningAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (instancetype)warningAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (instancetype)alertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (instancetype)alertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (instancetype)alertWithMessage:(NSString *)message text:(NSString *)text;
- Method criticalAlertWithMessage:text:buttons: returns a critical alert created by using the specified message text, informative text and a comma-separated list of the button titles, ending with nil poiter.
- Method criticalAlertWithMessage:text:button: creates and returns a new critical alert with the specified message text, informative text and a title of the single button.
- Method criticalAlertWithMessage:text: returns a new critical alert created by using a given message text, informative text and a default closing button (button with a title "OK").
- Method warningAlertWithMessage:text:buttons: creates and return a warning alert with a given message text, informative text and a comma-separated list of the button titles, ending with nil pointer.
- Method warningAlertWithMessage:text:button: returns a warning alert created by using the specified message text, informative text and a title of the single button.
- Method warningAlertWithMessage:text: returns a new warning alert created by using a given message text, informative text and a default closing button (button with a title "OK").
- Method alertWithMessage:text:buttons: returns an information alert created by using the specified message text, informative text and a comma-separated list of the button titles, ending with nil pointer.
- Method alertWithMessage:text:button: creates and returns a new information alert with the specified message text, informative text and a single button title.
- Method alertWithMessage:text: returns a new information alert created by using a given message text, informative text and a default closing button (button with a title "OK").
Also the category NSAlert(SCAlert) implements the following initialization methods:
- (instancetype)initWithStyle:(NSAlertStyle)style
message:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
- (instancetype)initCriticalAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
- (instancetype)initCriticalAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
- (instancetype)initCriticalAlertWithMessage:(NSString *)message text:(NSString *)text;
- (instancetype)initWarningAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
- (instancetype)initWarningAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
- (instancetype)initWarningAlertWithMessage:(NSString *)message text:(NSString *)text;
- (instancetype)initWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
- (instancetype)initWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
- (instancetype)initWithMessage:(NSString *)message text:(NSString *)text;
Running alerts
A created alerts can be show on the screen by using the method NSAlert::runModal, but the category NSAlert(SCAlert) declares the methods that perform the following actions:
- create the alert using the specified settings
- show the created alert
- return the code of the button pressed by the user
These methods are declares in the category NSAlert(SCAlert) as follows:
+ (NSInteger)runAlertWithStyle:(NSAlertStyle)style
message:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (NSInteger)runCriticalAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (NSInteger)runCriticalAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (NSInteger)runCriticalAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (NSInteger)runWarningAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (NSInteger)runWarningAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (NSInteger)runWarningAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (NSInteger)runAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (NSInteger)runAlertWithMessage:(NSString *)message text:(NSString *)text button:(NSString *)button;
+ (NSInteger)runAlertWithMessage:(NSString *)message text:(NSString *)text;
Details of the codes returned by these methods see in the section Alert buttons of the Programming Guide.
Request confirmation
In the previous section we looked at methods that show the alerts on the screen. In most cases, alerts is used for the doing one of the following:
- informing users about the occurrence of the various events
- enabling users to select the further behaviour of the application
Previously examined methods can be used to solve both of these tasks. However in the second case often all we are waiting for the user to select one of two options - to do or not to do a certain action, for example, delete or do not delete some entry in the database.
For in these simple cases, do not add to the application checks the user selected the button code we created in the category NSAlert(SCAlert) series of confirmation request methods, most important of which is the method:
+ (BOOL)confirmAlertWithStyle:(NSAlertStyle)style
message:(NSString *)message
text:(NSString *)text
confirm:(NSInteger)confirm
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
This method creates and displays the alert with the specified style, message text, informative text and a list of the button titles. Once the user clicks one of the buttons, the method compares the code of the button with the code, which is specified by the parameter confirm. If the codes match, the method returns the value of YES, otherwise it returns a value NO.
Also the vategory NSAlert(SCAlert) declares the following additional methods for running the confirmation requests:
+ (BOOL)confirmCriticalAlertWithMessage:(NSString *)message
text:(NSString *)text
confirm:(NSInteger)confirm
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (BOOL)confirmCriticalAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (BOOL)confirmWarningAlertWithMessage:(NSString *)message
text:(NSString *)text
confirm:(NSInteger)confirm
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (BOOL)confirmWarningAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (BOOL)confirmAlertWithMessage:(NSString *)message
text:(NSString *)text
confirm:(NSInteger)confirm
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
+ (BOOL)confirmAlertWithMessage:(NSString *)message
text:(NSString *)text
buttons:(NSString *)button, ... NS_REQUIRES_NIL_TERMINATION;
Please note that if the method does not have an option confirm, this means that the first added button is used as a confirm button. Learn more about working with the buttons and their codes can be found in the next section.
Additionally a category NSAlert(SCAlert) implements the simple confirmation request methods:
+ (BOOL)confirmYesNoAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (BOOL)confirmNoYesAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (BOOL)confirmOKCancelAlertWithMessage:(NSString *)message text:(NSString *)text;
+ (BOOL)confirmCancelOKAlertWithMessage:(NSString *)message text:(NSString *)text;
- Method confirmYesNoAlertWithMessage:text: shows the alert with a given message text, informative text and a buttons "Yes" and "No". Method returns the value YES if a user presses the button "Yes". In this case the button "Yes" is a default button and a user can select it by pressing the key "Enter".
- Method confirmNoYesAlertWithMessage:text: behaves similarly to the previous method, however, the default button is a "No" button.
- Methods confirmOKCancelAlertWithMessage:text: and confirmCancelOKAlertWithMessage:text: use the buttons "OK" and "Cancel" instead the buttons "Yes" and "No".
Alert buttons
Class NSAlert declares the method addButtonWithTitle: which adds into the existing alert the new button to the left of the previously added. This algorithm is also using by the methods from the category NSAlert(SCAlert) - if You use the method which allows defining a several buttons, than the method displays the first button on a right of an alert, the next button is placed to the left of the previous button and so on.
Method NSAlert::runModal returns the code of the user pressed button, which is defines by using the next formula: 1000 + id, where the argument id defines the order number of the button from right to left. For the rightmost button id is set to 0. Thus, the rightmost button returns the code 1000, the next button returns the code 1001 and so on.
Apple defines for the class NSAlert the following predefined constants of the buttons return codes:
NSAlertFirstButtonReturn = 1000
NSAlertSecondButtonReturn = 1001
NSAlertThirdButtonReturn = 1002
However, you can use your own constants for the first three buttons, as well as for all the others, you will be added to your alert if necessary.
Exceptions
Samond Classes Library uses the exception classes hierarchy (with parent class SCException) for the efficient handling of possible errors. This Programming Guide section describes in detail how on common points of all exception classes, and about the features of certain library errors.
The library declares the following types of exceptions:
Exception classes hierarchy
Category NSException(SCException)
Category NSException(SCException) adds into the class SCException the support of serialized files, data dictionaries, streams, data objects and collections:
+ (instancetype)exceptionWithCoder:(NSCoder *)coder;
+ (instancetype)exceptionWithContentsOfSerializedFile:(NSString *)path;
+ (instancetype)exceptionWithDataDictionary:(NSDictionary *)dictionary;
+ (instancetype)exceptionWithDataDictionaryFromFile:(NSString *)path;
+ (instancetype)exceptionWithStream:(
SCStream *)stream;
+ (instancetype)exceptionWithFileStream:(NSString *)path;
+ (instancetype)exceptionWithData:(NSData *)data;
+ (instancetype)exceptionWithContentsOfFile:(NSString *)path;
+ (instancetype)exceptionWithContentsOfURL:(NSURL *)url;
+ (instancetype)exceptionWithContentsOfURLString:(NSString *)urlString;
Class SCException
Class SCException is a parent class of all other library exception classes. It not only defines a class hierarchy, it also defines for other classes some concepts and tools such as error codes and error identifiers:
Error codes and IDs
Each library error has its own code and ID.
Error code is a negative number starting from the value -20000 and below. This choice is related to the error codes that are allocated for the ORACLE database user errors. In fact the system itself is the formation of codes and identifiers of error is taken by us from ORACLE.
For getting the error code you can use the property code of the class SCException instance:
@property (nonatomic, readonly, assign)
SCInteger code;
@try {
NSLog( @"%@", array);
}
NSLog( @"%@", [error description]);
NSLog( @"========================================================================");
NSLog(
@"Error code: %d", error.
code);
NSLog( @"========================================================================");
}
2016-09-21 13:11:00.173 libtest[3362:472990] SCL-20041: Source collection is nil
2016-09-21 13:11:00.174 libtest[3362:472990] ========================================================================
2016-09-21 13:11:00.174 libtest[3362:472990] Error code: -20041
2016-09-21 13:11:00.174 libtest[3362:472990] ========================================================================
Error ID is a string, which normally contains three characters and text representation of the error code. For the library errors we use the symbols SCL. For getting the error ID you can use property eid of the class SCException instance:
@property (nonatomic, readonly, retain) NSString *eid;
@try {
[array addObject:nil];
NSLog( @"%@", array);
}
NSLog( @"%@", [error description]);
NSLog( @"========================================================================");
NSLog(
@"Error ID: %@", error.
eid);
NSLog( @"========================================================================");
}
2016-09-21 14:04:41.375 libtest[3803:499118] SCL-20044: Array - empty item adding attemption
2016-09-21 14:04:41.375 libtest[3803:499118] ========================================================================
2016-09-21 14:04:41.375 libtest[3803:499118] Error ID: SCL-20044
2016-09-21 14:04:41.375 libtest[3803:499118] ========================================================================
Initializing exceptions
Class SCException declares the following methods for exceptions initializing:
- (instancetype)initWithName:(NSString *)name reason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
- Method initWithName:reason:code:eid: is a designed initializer for the class SCException. It allows to initializing the exception using the specified error name, error description, error code and error ID. We recommend using this method for you own errors initialization if you does not need to create own child exception class.
@try {
reason:@"Unspecified error"
code:-30000
eid:@"SCL-3000"] autorelease];
@throw exception;
}
NSLog( @"%@", [error description]);
NSLog( @"========================================================================");
NSLog(
@"Error Code: %d", error.
code);
NSLog(
@"Error ID: %@", error.
eid);
NSLog( @"========================================================================");
}
2016-09-21 15:26:21.203 libtest[3982:536145] Unspecified error
2016-09-21 15:26:21.203 libtest[3982:536145] ========================================================================
2016-09-21 15:26:21.203 libtest[3982:536145] Error Code: -30000
2016-09-21 15:26:21.203 libtest[3982:536145] Error ID: SCL-3000
2016-09-21 15:26:21.203 libtest[3982:536145] ========================================================================
Class SCAbstractMethodException
Class SCAbstractMethodException created specifically for situations where there is an attempt to call an abstract method. Since the Objective C does not implement the concept of an abstract method, it is necessary to create the implementation of this method to call the exception SCL-20001.
Class declares the following properties for accessing to the error data:
@property (nonatomic, readonly, retain) NSString *methodName;
- Property methodName returns the called abstract method name.
Class method returns a class instance created by using the specified abstract method name:
+ (instancetype)exceptionWithMethod:(NSString *)method;
Class SCSystemException
Exception class SCSystemException designed to handle errors that occur when using the system calls directly or through the thrid-party libraries. All system error are identified by the error ID SCL-20002.
Class declares the following properties and methods for accessing to the processed error data:
@property (nonatomic, assign, readonly, getter=error)
SCSystemError error;
@property (nonatomic, retain, readonly, getter=objectName) NSString *objectName;
- Property error returns the system code of the detected error.
- Properties objectName returns the name of object, which has caused a system error. Depending on the type of error, it may be a file name or any other information.
Class declares the following methods for creating a class instances:
+ (instancetype)exceptionWithError:(
SCSystemError)error object:(NSString *)object;
- Class method exceptionWithError:object: returns an exception by using the specified system error ID and name of the erroneous object.
- Class method exceptionWithError: returns an exception created by using the specified system error ID and empty erroneous object (for situations in which the detected error does not associate with any object).
Class SCNumberException
Class SCNumberException handle the number object errors, which can be occur when you use the methods from the class NSNumber expanding category NSNumber(SCNumber). Class defines the following error identifiers:
- SCL-20010 - unspecified NSNumber error (does not use in the library code)
- SCL-20011 - unspecified number object type
The following class method returns a number exception created by using the specified description, code and ID:
- (instancetype)initWithReason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
Unspecified NSNumber error
Error SCL-20010 did not used by the library, but it can be used in those cases when it is necessary to identify a numeric error object, but does not enter a new error identifier.
The following methods can be used for creating and initializing the number exception:
+ (instancetype)exception;
- Class method exception returns a number exception created by using the default error description.
Unsupported number object type
Error SCL-20011 is generated upon detection of an unsupported number object. Thus during the error processing can use the following properties:
@property (nonatomic, readonly, retain) NSString *unsupportedType;
For creating the unsupported number object type exception you can use the following methods:
+ (instancetype)exceptionWithUnsupportedType:(NSString *)type;
Class SCStreamException
Exception class SCStreamException provides stream error handling:
Exception properties
Class SCStreamException declares the following properties and access methods:
@property (nonatomic, readonly, retain) NSString *streamName;
@property (nonatomic, readonly, retain) NSString *unknown;
@property (nonatomic, readonly, retain) NSString *unexpected;
@property (nonatomic, readonly, retain) NSString *expected;
@property (nonatomic, readonly, retain) NSString *unsupported;
@property (nonatomic, readonly, assign)
SCSize readedBytes;
@property (nonatomic, readonly, assign)
SCSize writedBytes;
@property (nonatomic, readonly, assign)
SCSize waitedBytes;
@property (nonatomic, readonly, assign)
SCInteger openError;
@property (nonatomic, readonly, assign)
SCInteger readError;
@property (nonatomic, readonly, assign)
SCInteger writeError;
@property (nonatomic, readonly, assign) NSString *numberType;
@property (nonatomic, readonly, assign) NSInteger offset;
- Property streamName stores the erroneous stream name. This property can contains the nil value if the erroneous stream is unnamed.
- Property unknown returns the class name detected when reading data from the stream, which is unknown to the system. The value in this property be written when an error SCL-20024 processing.
- Property unexpected contains name of the unexpected class, which is detected instead the expected class, the name of which is contains in the property expected. These properties are used for error SCL-20025 processing.
- Property openError contain the code of the error, which is detected during the stream opening. The value of this property is set during the error SCL-20029 processing.
- Property readError stores the code of the error, which is detected during the stream reading operation. This property is formed during the error SCL-20030 processing.
- Property writeError contains the code of stream writing error, which is formed during the error SCL-20031 processing.
- Property numberType determines the unknown object number type detected during the stream operations. The value of this property is set during the error SCL-20032 processing.
- Property openMode returns the file stream incorrect opening mode. This property is used for error SCL-20033 processing.
- Property seekError contains information about the system error detected when trying to position in the stream. This property is used for processing the errors SCL-20036 and SCL-20037.
- Property offset stores incorrect offset, which detected during the positioning operation. These data are used for error SCL-20036 processing.
- Property whence returns the erroneous whence, which was detected during stream positioning operation. This property is used for errors SCL-20036 and SCL-20037 processing.
SCL-20020: unspecified stream error
This error can be used in cases where the handled situation not appropriate for the existing stream error codes, but the new error ID creating is inappropriate.
The exception class SCStreamException allows you to create an exception to the possibility of set the custom error codes and identifiers:
+ (instancetype)exceptionWithStream:(NSString *)stream
reason:(NSString *)reason
eid:(NSString *)eid;
+ (instancetype)exceptionWithReason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
- Class method exceptionWithStream:reason:code:eid: returns an exception created by using the specified stream name, error description, error code and error ID.
- Class method exceptionWithReason:code:eid: is equals to the previously described method, but does not allows set the erroneous stream name. This method uses for creating exception for the unnamed stream.
SCL-20021: stream not open
This error occurs when attempting to make a read or write operation with unopened stream.
The following class methods create this exception:
+ (instancetype)exceptionWithNotOpenStream:(NSString *)stream;
+ (instancetype)exceptionWithNotOpen;
SCL-20022: read only stream
The exception occurs when you try to write data to the stream, which is open for read-only.
The following class methods create this exception:
+ (instancetype)exceptionWithReadOnlyStream:(NSString *)stream;
+ (instancetype)exceptionWithReadOnly;
SCL-20023: write only stream
The exception occurs when you try to read data from the stream, which is open for write-only.
The following class methods create this exception:
+ (instancetype)exceptionWithReadOnlyStream:(NSString *)stream;
+ (instancetype)exceptionWithReadOnly;
SCL-20024: unknown class
The error occurs when readed from the stream class instance is refers to an unknown class in the system. This usually happens when you try to read the stream of the older version of software than the version of the software by means of which have been writed this stream.
Obtain the name of an unknown class is possible through the property unknown:
@property (nonatomic, readonly, retain) NSString *unknown;
To create this exception instances are designed th following class methods:
+ (instancetype)exceptionWithUnknown:(NSString *)name stream:(NSString *)stream;
+ (instancetype)exceptionWithUnknown:(NSString *)name;
SCL-20025: unexpected class
If the stream instead of an instance of one class detects instance of the another class, then the generate this exception.
The name of the detected and the expected classes are determined by the following properties of the class:
@property (nonatomic, readonly, retain) NSString *unexpected;
@property (nonatomic, readonly, retain) NSString *expected;
To create this exception are designed the following class methods:
+ (instancetype)exceptionWithUnexpected:(NSString *)unexpected expected:(NSString *)expected stream:(NSString *)stream;
+ (instancetype)exceptionWithUnexpected:(NSString *)unexpected expected:(NSString *)expected;
SCL-20026: unsupported class
When you load an data of the class instance you may find that this class does not comply the SCStreaming protocol.
The name of the class can be found out by property of the SCStreamException class instance:
@property (nonatomic, readonly, retain) NSString *unsupported;
The following class methods can be used to create an exception:
+ (instancetype)exceptionWithUnsupported:(NSString *)name stream:(NSString *)stream;
+ (instancetype)exceptionWithUnsupported:(NSString *)name;
SCL-20027: incomplete read operation
An error occurs if less characters were retrieved from the stream than was requested.
Data that how many characters have been read, and as requested, can be obtained by the following properties:
@property (nonatomic, readonly, assign)
SCSize readedBytes;
@property (nonatomic, readonly, assign)
SCSize waitedBytes;
The following methods create the exception:
+ (instancetype)exceptionWithReaded:(
SCSize)readed waited:(
SCSize)waited stream:(NSString *)stream;
+ (instancetype)exceptionWithReaded:(
SCSize)readed waited:(
SCSize)waited;
SCL-20028: incomplete write operation
This error is usually generated by a stream unit in cases where has been fixed the fact that the stream was write less characters than required. This can occur when you try to write to a file on the file system, which is out of space or when writing in which closed due to a network failure stream.
Data actually written and to be written symbols can be read through the properties of the class:
@property (nonatomic, readonly, assign)
SCSize writedBytes;
@property (nonatomic, readonly, assign)
SCSize waitedBytes;
To create an instance of the exception class are designed the following methods:
+ (instancetype)exceptionWithWrited:(
SCUInteger)writed waited:(
SCUInteger)waited stream:(NSString *)stream;
SCL-20029: stream opening error
This error occurs during the stream open operation. The main error parameter is the error code, which returns after the unsuccessful execution the system call or third-party function:
@property (nonatomic, readonly, assign)
SCInteger openError;
You can create this exception by using the following methods:
+ (instancetype)exceptionWithOpenError:(
SCInteger)error stream:(NSString *)stream;
+ (instancetype)exceptionWithOpenError:(
SCInteger)error;
SCL-20030: data read error
The error occurs if during the read operation system or library call returns the data read error (for example, when trying to read a file from a damaged media or in the event of network failures). When an error occurs the detected error code written in the property readError:
@property (nonatomic, readonly, assign)
SCInteger readError;
For creating this exception, are responsible the followin class methods:
+ (instancetype)exceptionWithReadError:(
SCInteger)error stream:(NSString *)stream;
+ (instancetype)exceptionWithReadError:(
SCInteger)error;
SCL-20031: data write error
This exception is designed to handle errors during data writing into the stream. Information, which are obtained from the system of librray call, is stored in the property writeError:
@property (nonatomic, readonly, assign)
SCInteger writeError;
Exception class SCStreamException declares the following methods for creating class instances:
+ (instancetype)exceptionWithWriteError:(
SCInteger)error stream:(NSString *)stream;
+ (instancetype)exceptionWithWriteError:(
SCInteger)error;
SCL-20032: NSNumber error
The error occurs when the stream unit detects the unknown number object type. Information about detected NSNumber type stores in the property numberType:
@property (nonatomic, readonly, assign) NSString *numberType;
Creating this exception provided by the following class methods:
+ (instancetype)exceptionWithUnsupportedNumberType:(NSString *)type stream:(NSString *)stream;
+ (instancetype)exceptionWithUnsupportedNumberType:(NSString *)type;
SCL-20033: incorrect stream mode
Class SCFileStream supports a specified set of file stream open modes. When you try to open a stream with a different mode this exception is generated. Property openMode allows obtained the detected incorrect opening mode:
For creating this exception you can use the following class methods:
SCL-20034: empty file stream path
This error is occurs when you try to open a file by using the nil path. Typically, this situation occurs when the software transmits without verification the path, that received from the user. Also this error can be occur as a result of the errors in the software, which uses the streams.
Create this exception is possible by using the following class methods:
+ (instancetype)exceptionWithEmptyPath;
SCL-20035: end of stream
The error is generated when trying to read data from the stream after its end has been reached, that is, read all the available data in the stream. For creating this exception class SCStreamException declares the following class methods:
+ (instancetype)exceptionWithEndOfFile:(NSString *)file;
+ (instancetype)exceptionWithEndOfFile;
SCL-20036: incorrect offset
The error occurs when trying to position the pointer over the stream boundaries.
For accessing the error data class SCStreamException declares the following properties:
@property (nonatomic, readonly, assign) NSInteger offset;
Class SCStreamException implements the following methods for creating the exceptions:
offset:(NSInteger)offset
path:(NSString *)path;
offset:(NSInteger)offset;
+ (instancetype)exceptionWithSeekError:(
SCSystemError)error path:(NSString *)path;
SCL-20037: incorrect offset whence
This error is occurs when the stream detects the incorrect whence of the offset operation. Error data can be obtained from the following properties of the class SCStreamException:
Class SCStreamException implements the following class methods for creating this exception:
Class SCCollectionException
Exception class SCCollectionException supports handling of errors, which can occur during the operations with collections:
Exception properties
For access to the information about collection errors the class SCCollectionException declares the following read only properties:
@property (nonatomic, readonly, retain) NSString *collectionName;
@property (nonatomic, readonly, retain) NSString *typeName;
@property (nonatomic, readonly, retain) NSString *unsupported;
@property (nonatomic, readonly, retain) NSString *unknown;
@property (nonatomic, readonly, assign)
SCIndex index;
@property (nonatomic, readonly, assign) NSRange range;
@property (nonatomic, readonly, retain) NSIndexSet *indexSet;
@property (nonatomic, readonly, assign)
SCULong indexesCount;
@property (nonatomic, readonly, assign)
SCULong objectsCount;
@property (nonatomic, readonly, retain) NSString *key;
@property (nonatomic, readonly, assign)
SCULong keysCount;
- Property collectionName stores the erroneous collection name. The value of this property performed at any collection error. If the erroneous collection is unnamed, then this property returns the nil pointer.
- Property typeName returns the name of the class, which was referred to as a pointer to a collection. Value of this property is used by the error SCL-20042 processing.
- To determine the name of a class not conforming to the SCCollectioning protocol, but found among the objects in the collection, the handler of the error SCL-20046 generates the value of the property unsupported.
- Property unknown stores the name of class, which is unknown to the system, and which was met at the collection objects processing. Error information is performed during the error SCL-20047 processing.
- Property index contains the incorrect object index, which be detected during the error SCL-20052 processing.
- Property range can determines the incorrect range, which became the cause of the error SCL-20053.
- Property indexSet provides access to the incorrect index set, which be detected during the error SCL-20054 processing.
- Property indexesCount contains incorrect number of indexes, which be detected during the error SCL-20055 processing.
- Property objectsCount provides access to the incorrect number of objects, which be detected during the processing of the errors SCL-20055 and SCL-20057.
- Incorrect object key, which detected during the errors SCL-20056 and SCL-20058 processing, can be obtained by using the property key.
- Detected during error SCL-20057 processing can be obtaind by using the property keysCount.
SCL-20040 - unspecified collection error
Error SCL-20040 is designed to indicate the collection errors, that are not related to those already defined for specific exceptions. This ID is created for cases where there is no need to create the individual error ID.
The following class SCCollectionException methods can be used for creating the exceptions by using the specified error codes and identifiers:
+ (instancetype)exceptionWithName:(NSString *)name reason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
+ (instancetype)exceptionWithReason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
SCL-20041 - source collection does not exist
Exception SCL-20041 is generated if the collection detects what the specified source collection does not exists - collection method receives the nil pointer instead the pointer to the collection.
Class SCCollectionException declares the following methods for creating this exception:
+ (instancetype)exceptionWithSource;
SCL-20042 - unsupported collection type
Exception SCL-20042 is generated if the collection instead the pointer to the collection receivies the pointer to instance of any other class, for example, class receives the string instead the pointer to the array.
Name of the unsupported collection type stores in the property typeName:
@property (nonatomic, readonly, retain) NSString *typeName;
Class SCCollectionException implements the following creating methods:
+ (instancetype)exceptionWithUnsupportedType:(NSString *)type;
SCL-20043 - collection is read-only
If you attemt changing the content of read only collection, then the error SCL-20043 is occurs.
Class SCCollectionException declares the following class methods for creating this exception:
+ (instancetype)exceptionWithReadOnlyType:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithReadOnlyType:(NSString *)type;
Please note, that the parameter type of these methods (and some other) passes the type name of collection that caused the exception to the correct error message generation.
SCL-20044 - adding a null pointer
Error SCL-20044 is occurs when the collection detects the attempt to adding the nil pointer. For creating this exception instances you can use the follow class SCCollectionException methods:
+ (instancetype)exceptionWithItemType:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithItemType:(NSString *)type;
SCL-20045 - source object does not exist
Exception SCL-20045 is generated when the collection receives the nil pointer instead the source object.
Class SCCollectionException implements the following methods for creating this exception instance:
+ (instancetype)exceptionWithObject;
SCL-20046 - unsupported class
If the collection detects the instance of the class, which does not comply to the protocol SCCollectioning, then the exception SCL-20046 is generated. The name of this class can be obtained from the property unsupported:
@property (nonatomic, readonly, retain) NSString *unsupported;
Class SCCollectionException declares the following methods for creating this exception:
+ (instancetype)exceptionWithUnsupported:(NSString *)cname type:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithUnsupported:(NSString *)cname type:(NSString *)type;
SCL-20047 - unknown class
If the collection detects the class, which does not known by the system, the exception SCL-20047 is generated. Name of the unknown class can be obtained from the property unknown.
@property (nonatomic, readonly, retain) NSString *unknown;
For creating this exception instance class SCCollectionException declares the following methods:
+ (instancetype)exceptionWithUnknown:(NSString *)cname type:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithUnknown:(NSString *)cname type:(NSString *)type;
SCL-20048 - incomparable collection object
Exception SCL-20048 is generated when the collection during the sorting process detects the objects, that cannot be compared. For creating this exception instance class SCCollectionException implements the following methods:
+ (instancetype)exceptionWithNotComparableType:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithNotComparableType:(NSString *)type;
SCL-20049 - collection does not support sorting
Error SCL-20049 occurs if you attempt sorting collection, which does not support the sorting opeations. Class SCCollectionException implements the following methods for creating this exception instance:
+ (instancetype)exceptionWithNotSortableType:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithNotSortableType:(NSString *)type;
SCL-20050 - incorrect data sorter
Error SCL-20050 is occurs when the collection receives the pointer to the incorrect data sorter. Class SCCollectionException implements the following methods for creating this exception instance:
+ (instancetype)exceptionWithSorterType:(NSString *)type name:(NSString *)name;
+ (instancetype)exceptionWithSorterType:(NSString *)type;
SCL-20052 - incorrect index
If the indexed collection detects the incorrect index, then the exception SCL-20052 is generated. This exception stores the detected incorrect index in the property index:
@property (nonatomic, readonly, assign)
SCIndex index;
You can create the exception instance by using the specified class methods:
+ (instancetype)exceptionWithIndex:(
SCIndex)index name:(NSString *)name;
+ (instancetype)exceptionWithIndex:(
SCIndex)index;
SCL-20053 - incorrect objects range
If the collection detects the incorrect objects range, then the exception SCL-20053 is generated. The incorrect range can be obtained from the property range:
@property (nonatomic, readonly, assign) NSRange range;
Exception instance can be created by using the specified class SCCollectionException methods:
+ (instancetype)exceptionWithRange:(NSRange)range name:(NSString *)name;
+ (instancetype)exceptionWithRange:(NSRange)range;
SCL-20054 - incorrect index set
If the indexed collection detects the incorrect index set (nil pointer to index set or incorrect index within the set), then the error SCL-20054 is occurs and exception is generated. The property indexSet return the detected incorrect index set.
@property (nonatomic, readonly, retain) NSIndexSet *indexSet;
Class SCCollectionException declares the following methods for creating this exception:
+ (instancetype)exceptionWithIndexSet:(NSIndexSet *)indexSet name:(NSString *)name;
+ (instancetype)exceptionWithIndexSet:(NSIndexSet *)indexSet;
SCL-20055 - number of indexes does not match number of objects
Some methods of indexed collections operate with index sets and object lists. The number of indexes in the set must match the number of objects. If the collection detects a mismatch between them, the exception SCL-20055 is thrown. Error information is stored in the following properties:
@property (nonatomic, readonly, assign)
SCULong indexesCount;
@property (nonatomic, readonly, assign)
SCULong objectsCount;
- Property indexesCount contains the number of indexes in the index set.
- Property objectsCount stores the number of objects in the list.
Class SCCollectionException implements the following methods for creating this exception instance:
+ (instancetype)exceptionWithIndexesCount:(
SCULong)indexes objectsCount:(
SCULong)objects;
SCL-20056 - incorrect object key
If the collection detects the incorrect object key, then the error SCL-20056 is occurs. Detected incorrect key can be obtained from the property key:
@property (nonatomic, readonly, retain) NSString *key;
Class SCCollectionException declares the following methods for creating this exception instance:
+ (instancetype)exceptionWithKey:(NSString *)key name:(NSString *)name;
+ (instancetype)exceptionWithKey:(NSString *)key;
SCL-20057 - number of keys does not match number of objects
Error SCL-20057 is equals to the error SCL-20055, but instead the number of indexes use the number of keys. Error information can be obtained by using the following properties:
@property (nonatomic, readonly, assign)
SCULong keysCount;
@property (nonatomic, readonly, assign)
SCULong objectsCount;
Class SCCollectionException implements the following methods for creating this exception instance:
+ (instancetype)exceptionWithKeysCount:(
SCULong)keys objectsCount:(
SCULong)objects;
SCL-20058 - empty value
Error SCL-20058 can be occured if you attempt add into the collection the nil pointer instead the value. Key of the erroneous value can be obtained from the property key:
@property (nonatomic, readonly, retain) NSString *key;
For creating this exception instance you can use the following methods of the class SCCollectionException:
+ (instancetype)exceptionValueForKey:(NSString *)key name:(NSString *)name;
+ (instancetype)exceptionValueForKey:(NSString *)key;
Class SCTextException
Exception class SCTextException handle the errors, which can be occur during using the text classes:
Exception properties
Class SCTextException declares the following read only properties:
@property (nonatomic, readonly, retain) NSString *textName;
@property (nonatomic, readonly, retain) NSString *string;
@property (nonatomic, readonly, assign)
SCIndex index;
@property (nonatomic, readonly, retain) NSIndexSet *indexSet;
@property (nonatomic, readonly, retain) NSString *unsupported;
@property (nonatomic, readonly, assign)
SCULong indexesCount;
@property (nonatomic, readonly, assign)
SCULong stringsCount;
@property (nonatomic, readonly, assign) NSRange range;
@property (nonatomic, readonly, assign) NSRange intersected;
@property (nonatomic, readonly, retain)
SCStream *stream;
- Property textName returns the erroneous text object name. If the error is occurs in the unnamed text object, then the property textName returns the nil pointer. This property is formed during processing of any error.
- Property string returns the string, which is a reason of the error SCL-20069, which occurs than the unique strings list detects the unique violation.
- Property index stores the information about the index, which is used during the processing of errors SCL-20072, and SCL-20069.
- Detected by the error SCL-20074 handler incorrect index set can be obtained by using the property indexSet.
- Property unsupported stores the unsupported class name, which is detected by the error SCL-20066 handler.
- Property indexesCount contains the number of indexes, which did not match the number of strings. Value of this property is performed during the error SCL-20075 processing. The number of strings can be obtained by using the property stringsCount.
- Property range returns the incorrect range, which is detected during the error SCL-20073 processing or one of the intersected ranges, which is detected during processing the error SCL-20076.
- Property intersected stores the second of the intersected ranges, which is detected during the error SCL-20076 processing.
SCL-20060 - unspecified text error
In addition to certain exceptions class SCTextException class allows you to create exception to the additional error identifiers and unspecified text error SCL-20060:
+ (instancetype)exceptionWithName:(NSString *)name reason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
+ (instancetype)exceptionWithReason:(NSString *)reason code:(
SCInteger)code eid:(NSString *)eid;
+ (instancetype)exceptionWithName:(NSString *)name;
+ (instancetype)exception;
- Class method exceptionWithName:reason:code:eid: returns an exception created by using the specified text name, error description, error code and error ID.
- Class method exceptionWithReason:code:eid: returns an exception created by using the specified error description, error code and error ID.
- Class method exceptionWithName: returns an unspecified text exception created by using the specified text name.
- Class method exception returns an unspecified text exception created for the unnamed erroneous text object.
SCL-20061 - source object does not exist
Error SCL-20061 is occurs when the text object receives the nil pointer instead the pointer to the source object. For creating this exception instance class SCTextException implements the following class methods:
+ (instancetype)sourceExceptionWithName:(NSString *)name;
+ (instancetype)sourceException;
SCL-20062 - incorrect input stream
If the problem with the input stream (nil pointer to the stream, specified stream does not support read operations) is detected during the read text from the stream, then the text object throws an exception SCL-20062. The pointer to the incorrect input stream can be ontained by using the property stream:
@property (nonatomic, readonly, retain)
SCStream *stream;
Class SCTextException declares the following methods for creating this exception instance:
+ (instancetype)exceptionWithInputStream:(
SCStream *)stream name:(NSString *)name;
+ (instancetype)exceptionWithInputStream:(
SCStream *)stream;
SCL-20063 - text is read only
Error SCL-20063 is occurs when you attempt changing the content of the read only text object. For creating this exception instances class SCTextException implements the following methods:
+ (instancetype)readOnlyExceptionWithName:(NSString *)name;
+ (instancetype)readOnlyException;
SCL-20064 - null string adding
Error SCL-20064 occurs during the attemt to add the nil string into the text object. Class SCTextException declares the following methods for creating this exception instances:
+ (instancetype)emptyStringExceptionWithName:(NSString *)name;
+ (instancetype)emptyStringException;
SCL-20065 - closed stream
Exception SCL-20065 is thrown then the text object detects the attemption to read from or write to the closed stream. Pointer to the closed stream can be obtained from the property stream:
@property (nonatomic, readonly, retain)
SCStream *stream;
Class SCTextException declares the following methods for creating this exception instances:
+ (instancetype)exceptionWithClosedStream:(
SCStream *)stream name:(NSString *)name;
+ (instancetype)exceptionWithClosedStream:(
SCStream *)stream;
SCL-20066 - not string instance
If the text object detects the unsupported class, then the exception SCL-20066 is thrown. Name of unsupported class can be obtained from the property unsupported:
@property (nonatomic, readonly, retain) NSString *unsupported;
For creating this exception instance class SCTextException declares the following class methods:
+ (instancetype)exceptionWithUnsupported:(NSString *)unsupported name:(NSString *)name;
+ (instancetype)exceptionWithUnsupported:(NSString *)unsupported;
SCL-20067 - reading error
If the reading error detects during the reading strings from the stream, then the text object generates the exception SCL-20067. Erroneous stream can be obtained from the property SCTextException.stream "stream":
@property (nonatomic, readonly, retain)
SCStream *stream;
Class SCTextException implements the following class methods for creating this exception instance:
+ (instancetype)readErrorExceptionWithStream:(
SCStream *)stream name:(NSString *)name;
+ (instancetype)readErrorExceptionWithStream:(
SCStream *)stream;
SCL-20068 - empty text file path
Error SCL-20068 is occurs then the text file receives the empty path to the disk file (nil pointer or empty string). For creating this exception instance class SCTextException implements the following class methods:
+ (instancetype)emptyPathExceptionWithName:(NSString *)name;
+ (instancetype)emptyPathException;
SCL-20069 - string unique violation
Exception SCL-20069 generates by the class SCUniqueStrings if the unique strings list detects the unique violation. For processing this exception class SCTextException uses the following properties and methods:
@property (nonatomic, readonly, retain) NSString *string;
@property (nonatomic, readonly, assign)
SCIndex index;
- Property string contains violation string.
- Property index contains the index, which indicates the already exist string.
For creating this exception instance class SCTextException uses the following class methods:
+ (instancetype)duplicateExceptionWithName:(NSString *)name string:(NSString *)string index:(
SCIndex)index;
+ (instancetype)duplicateExceptionWithString:(NSString *)string index:(
SCIndex)index;
SCL-20070 - incorrect strings sorter
If the text object detects the incorrect strings sorter, then the exception SCL-20070 is thrown. For creating this exception instance class SCTextException implements the following methods:
+ (instancetype)sorterExceptionWithName:(NSString *)name;
+ (instancetype)sorterException;
SCL-20071 - incorrect output stream
Error SCL-20071 is occurs if the text object detects the nil pointer to the output stream or detects the output stream, which does not support write operations. Erroneous stream can be obtained from the property stream:
@property (nonatomic, readonly, retain)
SCStream *stream;
Class SCTextException declares the following class methods for creating this exception instances:
+ (instancetype)exceptionWithOutputStream:(
SCStream *)stream name:(NSString *)name;
+ (instancetype)exceptionWithOutputStream:(
SCStream *)stream;
SCL-20072 - incorrect string index
Error SCL-20072 is occurs when the text object detects the incorrect index. Detected index can be obtained from the property index:
@property (nonatomic, readonly, assign)
SCIndex index;
Class SCTextException implements the following class methods for creating this exception instance:
+ (instancetype)exceptionWithIndex:(
SCIndex)index name:(NSString *)name;
+ (instancetype)exceptionWithIndex:(
SCIndex)index;
SCL-20073 - incorrect string range
If the text object detects the incorrect strings range, then the exception SCL-20073 is thrown. Detected incorrect range can be obtained from the property range:
@property (nonatomic, readonly, assign) NSRange range;
Class SCTextException declares the following class methods for creating this exception instances:
+ (instancetype)exceptionWithRange:(NSRange)range name:(NSString *)name;
+ (instancetype)exceptionWithRange:(NSRange)range;
SCL-20074 - incorrect index set
Incorrect index set generates the exception SCL-20074. Detected index set can be obtained from the property indexSet:
@property (nonatomic, readonly, retain) NSIndexSet *indexSet;
Class SCTextException declares the following class methods for creating this exception instances:
+ (instancetype)exceptionWithIndexSet:(NSIndexSet *)indexSet name:(NSString *)name;
+ (instancetype)exceptionWithIndexSet:(NSIndexSet *)indexSet;
SCL-20075 - number of indexes does not match number of strings
Some text objects methods accept as an argument the index sets and object lists. If the number of indexes does not match the number of objects, then the error SCL-20075 is occurs. Class SCTextException declares the following properties and methods for accessing the error information:
@property (nonatomic, readonly, assign)
SCULong indexesCount;
@property (nonatomic, readonly, assign)
SCULong stringsCount;
- Property indexesCount stores the detected incorrect number of indexes.
- Property stringsCount contains the detected incorrect number of strings.
Class SCTextException implements the following class methods for creating this exception instance:
+ (instancetype)exceptionWithIndexesCount:(
SCULong)icount stringsCount:(
SCULong)scount name:(NSString *)name;
+ (instancetype)exceptionWithIndexesCount:(
SCULong)icount stringsCount:(
SCULong)scount;
SCL-20076 - intersected string ranges
If the text object detects the intersected ranges of strings, then the exception SCL-20076 is thrown. Information about intersected ranges can be obtained from the following properties and methods of the class SCTextException:
@property (nonatomic, readonly, assign) NSRange range;
@property (nonatomic, readonly, assign) NSRange intersected;
Class SCTextException implements the following class methods for creating this exception instances:
+ (instancetype)exceptionWithRange:(NSRange)range intersected:(NSRange)intersected name:(NSString *)name;
+ (instancetype)exceptionWithRange:(NSRange)range intersected:(NSRange)intersected;
SCL-20077 - writing error
If the text object detects the error during the read strings from the stream, then the error SCL-20077 is occurs. The erroneous stream can be obtained from the property stream:
@property (nonatomic, readonly, retain)
SCStream *stream;
Class SCTextException declares the following methods for creating this exception instance:
+ (instancetype)writeErrorExceptionWithStream:(
SCStream *)stream name:(NSString *)name;
+ (instancetype)writeErrorExceptionWithStream:(
SCStream *)stream;
Grouping classes
In this Programming Guide section we describe the grouping classes that provide the creation of an hierarchy of classes related to each other only logically. Create instances of these classes makes no sense:
Class SCDelegate
Class SCDelegate is a common ancestor of the delegation classes (event handling classes). Currently the delegate classes Класс SCDelegate объединяет в общую иерархию все классы-обработчики событий (классы делегирования):
Class SCService
Class SCService creates the hierarchy of the auxiliary classes, which very rarely used outside of library units:
Library information
Information relating directly to the library, available through class properties declared in a special class SCCommon. To call these methods, there is no need to create instances of this class.
@property (class, readonly, copy) NSString *version;
@property (class, readonly, copy) NSString *fullVersion;
@property (
class, readonly, assign)
SCUInteger sclBuild;
@property (class, readonly, copy) NSString *libraryInformation;
@property (class, readonly, copy) NSString *compilationDate;
@property (class, readonly, copy) NSString *compilationDateTime;
@property (class, readonly, copy) NSString *compilationString;
@property (class, readonly, copy) NSString *copyright;
- Class property version returns the library version number:
2017-04-14 11:07:58.886283+0300 libtest[90123:8395285] 1.2.2-CURRENT
- Class property fullVersion returns a string with the full version of the library:
2017-04-14 11:20:43.323232+0300 libtest[90512:8404986] Samond Classes Library 1.2.2-CURRENT
- By using the class property sclBuild you can obtain the library build number:
2017-04-14 11:37:07.273212+0300 libtest[90930:8417146] 184
- Class property libraryInformation returns a string with the full information about the library:
2017-04-14 11:46:36.491225+0300 libtest[91314:8426113] Samond Classes Library 1.2.2-CURRENT (Build 184)
- Class properties compilationDate, compilationDateTime and compilationString return information about the library compilation date and time:
2017-04-14 11:57:42.201618+0300 libtest[91637:8434662] Apr 14 2017
2017-04-14 11:57:42.201640+0300 libtest[91637:8434662] Apr 14 2017 11:57:01
2017-04-14 11:57:42.201662+0300 libtest[91637:8434662] Compiled at Apr 14 2017 11:57:01
- Class property copyright return a copyright information for library source code:
2017-09-08 16:24:19.859516+0300 libtest[6306:381369] Copyright (c) 2007 - 2017 by Samond Development Corporation. All rights reserved.
Types and constants
This Programming Guide section describes data types, constants and macroses, which are used by many components of the library:
Standard types
For ease of programming and maintenance of software portability between different systems, the library introduces its standard data types that are defined in the file SCTypes.h:
Special types
Library in the file SCTypes.h declares the following special data type:
Data type | Description | Size | Comments |
SCSize | Unsigned size data type | 4 or 8 bytes | |
- Type SCSize uses for data sizing specification, for sample the number of writed to stream characters.
Other data types
File SCTypes.h declares the following advanced data types:
Data type | Description |
SCCapacity | Declares a set of constants that indicate a capacity of integer values (8, 16, 32 and 64 bits) |
SCIntegerBase | Declares a set of contants that indicate a base of an integer values |
- Type SCCapacity defines the integer capacity constants:
- Type SCIntegerBase declares a set of constants that indicates the integer base:
Macroses
File SCConstants.h declares the following macroses:
#define SCLS( string) NSLocalizedString( string, nil)
#define __abstract__( name) { @throw [SCAbstractMethodException exceptionWithMethod:name]; }
- Macros SCLS is replaced by the call of the standard function NSLocalizedString:
NSLog(
@"%@",
SCLS(
@"Message"));
2016-09-29 23:33:03.977 libtest[10630:2349707] Message
- Macros abstract calls the abstract method using exception SCL-20001:
2016-09-29 23:34:23.971 libtest[10643:2350275] SCL-20001: Abstract method call detected ([
SCStream writeBytes:fromBuffer:])
Data Types Definition System
Data Types Definition System is developed for the purpose of support of different data storage and transport systems (such as a database systems) with their different data types. By the analysis of the majority of DBMS all diversity of their types was reduced to a limited set which is declared in library by means of the SCDataType type (since version 1.2.5).
Type SCDataType defines the following constants and data types:
At present not all DTDS types have implementation in Objective C or our library - gradually we will add new data types from listed above. Also so,me types from the standard do not support such mechanisms of our library, as a serialized files and streams. This support will be added also in a futured versions of our library.
Let's in addition mark that for today we did not start development of components which will use SDTS in the operation, however we enter DTDS into version 1.2.5 that in upcoming versions to start development of mechanisms of library using these system.
DTDS also contains a SCArgumentType type that defines kinds of agruments by operation with different modules (for example stored procedures of databases). Type defines the following constants and argument kinds:
Functions
This documentation section describes various functions which does not belong to any classes of library. For convenience of study of functions are grouped in the functionality:
Logging functions
Logging functions provide the formatted output of various information and are analogs standard functions NSLog and NSLogv. Functions were developed with two purposes:
- support of a raw output without additional information output by standard functions
- possibility of an output as in a standard output stream stdout, and in a standard errors stream stderr
A Samond Classes Library declares the following logging functions:
void SCLog( NSString *format, ...);
void SCLogv( NSString *format, va_list arguments);
void SCError( NSString *format, ...);
void SCErrorv( NSString *format, va_list arguments);
void SCPrint( NSString *format, ...);
void SCPrintv( NSString *format, va_list arguments);
- Function SCLog output into the standard output stream stdout a formatted string that creates by using the specified format string and a comma separated list of arguments to substitute into the format string:
Samond Classes Library 1.2.4-CURRENT (Build 196)
Compiled at Jul 24 2017 20:20:28
- A function SCLogv works similar to the SCLog function, however accepts agruments in the form of the list va_list instead of in the form of the comma separated list.
- A function SCLogl writes an empty line into the standard output stream stdout:
SCLog(
@"First message");
SCLog(
@"Second message");
First message
Second message
- The functions SCError, SCErrorv and SCErrorl work similar to the functionsSCLog, SCLogv and SCLogl, only the output of the formatted information is carried out in a standard error stream stderr:
SCError(
@"Error %d in the unit %@ detected", 68,
@"LOADER");
SCError(
@"System error detected");
Error 68 in the unit LOADER detected
System error detected
- The functions SCPrint and SCPrintv differ from the functions SCLog and SCLogv by that in case of an output does not add the new line character:
SCPrint(
@"Run a system test... ");
- The functions SCPrintError and SCPrintErrorv write formatted information into a standard error stream stderr without adding a new line character:
Run a system test... FAILED