구문 분석 할 파일이 쉼표로 구분되어 있습니다. 그것은 다음과 같습니다텍스트 파일 구문 분석하기
... "John", "Smith", "New York", "10038" ...
내가 약 1000 파일 당이 기록을 처리하고 있습니다. 내 계획은 그들을 dictionary
으로 파싱하는 것입니다.
내가 지금까지 찾은 것부터 NSInputStream
을 사용해야합니다. 나의 현재 코드는 다음과 같습니다
firstViewController.m
...
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
GruParser *stream = [[GruParser alloc] init];
[stream parse:[[NSBundle mainBundle] pathForResource:@"sample" ofType:@"gru"]];
}
...
에게 GruParser.m을
#import "GruParser.h"
@implementation GruParser
-(id)init {
if(self = [super init]) {
dict = [NSMutableDictionary alloc];
}
return self;
}
-(void)parse:(NSString *)path {
NSInputStream *stream = [NSInputStream inputStreamWithFileAtPath:path];
//NSInputStream *stream = [NSInputStream inputStreamWithURL:[NSURL URLWithString:@"http://www.w3schools.com/xml/note.xml"]];
[stream setDelegate:self];
[stream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[stream open];
NSLog(@"%@", @"parse");
}
-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode {
NSLog(@"%@", @"stream event");
}
@end
main.m
충돌 라인 16 (BAD_ACCESS)에서 그리고 이후 내가 '4.2 디버깅 멍청한 놈이야 내가 뭘 잘못하고 있는지 모르겠다. 그러나 로그에는 "스트림"이 표시됩니다. 나는 꽤 내가 [stream open]
에 충돌하고 있다고 확신한다. 다음 단계에 대한 조언이 있으십니까?
(내 코드와 편집본에) 덧붙여서, 같은 콘솔과 같은 크래시를 얻고 있습니다. – Jacksonkr
콘솔에서 정확한 출력을 붙여 넣을 수 있습니까? – jrtc27
'dict = [[NSMutableDictionary alloc] init]'도 호출해야합니다. –