Cocoa API解説(macOS/iOS)

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。

目次

enumerateSubstringsInRange:options:usingBlock:

INDEX>Foundation>NSString>

指定した範囲で文字列とマッチする行があるかを調べます。
-(void)enumerateSubstringsInRange:(NSRange)range
          options:(NSStringEnumerationOptions)opts
          usingBlock:(void (^)(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop))block

解説

返り値

( void )

なし

引数

( NSRange )range
( NSStringEnumerationOptions )opts
( void (^)(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) )block

クラス

NSString

Instance Methods

使用可能

10.6

参照

例文

#pragma mark enumerateSubstringsInRange:options:usingBlock:
- (void)displayText063:(NSString *)text {
	
    NSLog(@"text 063 %@",text);
}
-(void)method063
{
    __block BOOL found = NO;
	
	//find word
	NSString *multiLine = [NSString stringWithString:@"apple\nbanana\norange\n" ];
	NSString *string = [NSString stringWithString:@"apple" ];
    NSRange aRange = NSMakeRange(0,9);
	[multiLine enumerateSubstringsInRange:aRange
                                  options:NSStringEnumerationByLines
                               usingBlock:^(NSString *line, 
                                            NSRange substringRange, 
                                            NSRange enclosingRange, 
                                            BOOL *stop) {
		
		if ([line localizedCaseInsensitiveCompare:string] == NSOrderedSame) {
			*stop = YES;
			found = YES;
			NSLog(@"myBlock class= %@",[line className]);
            
            [self performSelectorOnMainThread:@selector(displayText063:) withObject:string waitUntilDone:NO];
            
		}else{
            *stop = YES;
			found = NO;
            [self performSelectorOnMainThread:@selector(displayText063:) withObject:@"NO!" waitUntilDone:NO];
            
        }
        NSLog(@"substringRange = (%lu,%lu)",substringRange.location,substringRange.length);
        NSLog(@"enclosingRange = (%lu,%lu)",enclosingRange.location,enclosingRange.length);
		
	}];
	
}