gpt4 book ai didi

ios - 使用 .csv 文件创建对象 Objective-C

转载 作者:行者123 更新时间:2023-11-29 02:53:21 25 4
gpt4 key购买 nike

我正在绘制我的大学 map ,他们提供了一个 .csv 文件,其中包含校园内所有建筑物的列表。其中包括建筑物编号、名称、代码、街道地址、街道坐标等信息。

我想从这个文件中读取值来创建 Building 对象的 NSArray。这就是文件的格式,我该怎么做?

enter image description here

最佳答案

将 csv 加载到 NSString 中。

NSString *path = [[NSBundle mainBundle] pathForResource:@"filename"
ofType:@"csv"];

NSStringEncoding encoding = 0;
NSError *error = nil;
NSString *csvString = [NSString stringWithContentsOfFile:path
usedEncoding:&encoding
error:&error];

用你喜欢的方法解析它,我使用一个开源库,CHCSVParser https://github.com/davedelong/CHCSVParser

NSArray *fields = [csvString CSVComponents]; // you need to import "CHCSVParser.h"

关于ios - 使用 .csv 文件创建对象 Objective-C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24221697/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com