我正在尋找循環訪問我的NSArray *網址 - 對每個對象進行一些字符串調整。循環瀏覽URL的NSArray - 崩潰 - iOS
但是,一旦它進入For循環並嘗試調整NSString *的東西 - 這會引發異常。
任何想法爲什麼我難倒?
- (void)GetData
{
NSFileManager *fm = [NSFileManager defaultManager];
NSString *directory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
directory = [NSString stringWithFormat:@"%@/%@/%@/%@", directory, self.researcherID, self.participantID, testTypeString];
directory = [directory stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSError *error;
NSURL *url = [NSURL URLWithString:directory];
NSArray *urls = [fm contentsOfDirectoryAtURL:url includingPropertiesForKeys:nil options:0 error:&error];
for (int x = 0; x < urls.count; x++) {
NSString *urlIndex = urls[x];
NSString *thing = [urlIndex stringByReplacingOccurrencesOfString:@"%20" withString:@" "];
thing = [thing stringByReplacingOccurrencesOfString:@"file://" withString:@""];
// add thing to new array but crashes before i can
}
}
編輯: 拋出異常
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSURL stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x14ebf1a0'
aaaaand ....有什麼例外? –
@MichaelDautermann - 哎呀 - 忘了提,我現在編輯了我的帖子。 – Ryan
@Ben也可以使用快速枚舉,爲您提供更好的性能,即爲(NSURL * url in url){// code here} –