小编use*_*967的帖子

使用Objective C从CSV文件创建数组

我是新编码所以请原谅我,如果这看起来像一个简单的问题.

我正在尝试在地图上绘制坐标.

我想读取CSV文件并将信息传递给两个单独的数组.

第一个数组将是NSArray*towerInfo(包含纬度,经度和塔标题)

第二个,NSArray*区域(包含塔标题和区域)与第一个数组具有相同的计数索引.

基本上,我相信我需要;

1)将文件读取为字符串.....

2)将字符串分成每个/ n/r分隔的临时数组......

3)循环访问临时数组并在每次将此信息附加到两个主存储阵列之前创建塔和区域对象.

这是正确的过程,如果有的话,那里有人可以发布一些示例代码,因为我真的很难做到这一点.

感谢所有提前.

克里斯.

我编辑了这个以显示我的代码示例.我遇到的问题是我收到警告说

1)"'dataStr'的本地声明隐藏了实例变量.2)"'array'的本地声明隐藏了实例变量.

我想我明白这些意思,但我不知道怎么解决它.程序编译并运行但日志告诉我"数组为空".

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

@synthesize dataStr;
@synthesize array;

-(IBAction)convert {
//calls the following program when the onscreen 'convert' button is pressed.

    NSString *dataStr = [NSString stringWithContentsOfFile:@"Towers.csv" encoding:NSUTF8StringEncoding error:nil];
    //specifies the csv file to read - stored in project root directory - and encodes specifies that the format of the file is NSUTF8. Choses not to return an error message if …
Run Code Online (Sandbox Code Playgroud)

xcode objective-c

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

objective-c ×1

xcode ×1