GSLCSVSerialization is an Objective-C CSV parser for iOS, macOS, watchOS and tvOS.
- Xcode 12.0 or later
- Base SDK: iOS 14.0 / macOS 10.15 / watchOS 7.0 / tvOS 14.0 or later
- Deployment Target: iOS 6.0 / OS X 10.6 / watchOS 2.0 / tvOS 9.0 or later
Add the pod to your Podfile
:
# ...
pod 'GSLCSVSerialization'
Install the pod:
$ pod install
Check out the source:
$ git clone https://github.com/GyazSquare/GSLCSVSerialization.git
GSLCSVSerialization can create a CSV object from a RFC 4180-compliant CSV data by using the following methods:
+ (nullable __kindof NSArray<__kindof NSArray<__kindof NSString *> *> *)CSVRecordsWithData:(NSData *)data encoding:(NSStringEncoding)encoding options:(GSLCSVReadingOptions)opt error:(NSError **)error;
+ (nullable __kindof NSArray<__kindof NSArray<__kindof NSString *> *> *)CSVRecordsWithStream:(NSInputStream *)stream encoding:(NSStringEncoding)encoding options:(GSLCSVReadingOptions)opt error:(NSError **)error;
For example, if you parse CSV data below,
aaa,bbb,ccc
zzz,yyy,xxx
you can get a CSV object like this:
@[
@[@"aaa",@"bbb",@"ccc"],
@[@"zzz",@"yyy",@"xxx"]
]
GSLCSVSerialization can create CSV data from a CSV object by using the following methods:
+ (nullable NSData *)dataWithCSVRecords:(NSArray<NSArray<NSString *> *> *)records encoding:(NSStringEncoding)encoding options:(GSLCSVWritingOptions)opt error:(NSError **)error;
+ (NSInteger)writeCSVRecords:(NSArray<NSArray<NSString *> *> *)records toStream:(NSOutputStream *)stream encoding:(NSStringEncoding)encoding options:(GSLCSVWritingOptions)opt error:(NSError **)error;
A records
object is a two-dimensional array containing field
strings. You should check whether the input will produce valid CSV data before calling these methods by using isValidCSVRecords:
.
This software is licensed under the MIT License.
See the LICENSE file for details.