Sunday, May 12, 2013

NSString completePathIntoString example ios


completePathIntoString: caseSensitive: matchesIntoArray: filterTypes:

Interprets the receiver as a path in the file system and attempts to perform filename completion, returning a numeric value that indicates whether a match was possible, and by reference the longest path that matches the receiver.
- (NSUInteger)completePathIntoString:(NSString **)outputName caseSensitive:(BOOL)flagmatchesIntoArray:(NSArray **)outputArray filterTypes:(NSArray *)filterTypes
Parameters
outputName
Upon return, contains the longest path that matches the receiver.
flag
If YES, the methods considers case for possible completions.
outputArray
Upon return, contains all matching filenames.
filterTypes
An array of NSString objects specifying path extensions to consider for completion. only paths whose extensions (not including the extension separator) match one of those strings.
Return Value of [NSString completePathIntoString]
0 if no matches are found and 1 if exactly one match is found. In the case of multiple matches, returns the actual number of matching paths if outputArray is provided, or simply a positive value if outputArray is NULL.
Discussion of [NSString completePathIntoString]
You can check for the existence of matches without retrieving by passing NULL as outputArray.
Note that this method only works with file paths (not, for example, string representations of URLs).
Example of [NSString completePathIntoString]
{
CGDirectDisplayID displeys[2];
CGGetActiveDisplayList( (int)[[NSScreen screens] count], displeys, nil );

NSMutableArray* arrayProf=[[NSMutableArray alloc] init];

for (int q=0;q<[[NSScreen screens] count];q++){

uint32_t vendor = CGDisplayVendorNumber(displeys[q]);
uint32_t model = CGDisplayModelNumber (displeys[q]);


NSString *str=[[NSString alloc] initWithFormat:@"%0x",vendor];
NSString *str2=[[NSString alloc] initWithFormat:@"%0x",model];


NSArray *array;
NSArray *arrayT=[[NSArray alloc] initWithObjects:@"icc",nil];

[@"/Library/ColorSync/Profiles/Displays" completePathIntoString: nil
caseSensitive:NO
matchesIntoArray:&array
filterTypes:arrayT];

[arrayT release];

for(int i=0;i<array.count;i++){
[arrayProf addObject:[[[array objectAtIndex:i] componentsSeparatedByString:@"/"] objectAtIndex:5] ];
}


for (int i=0;i<[arrayProf count];i++){
NSString *strModel=[[NSString alloc]initWithFormat:@"%@%@",
[[[arrayProf objectAtIndex:i] componentsSeparatedByString:@"-"] objectAtIndex:2],
[[[arrayProf objectAtIndex:i] componentsSeparatedByString:@"-"] objectAtIndex:3]];


if (([[arrayProf objectAtIndex:i] rangeOfString:[str uppercaseString]].location!=NSNotFound)&&
([strModel rangeOfString:[str2 uppercaseString] ].location!=NSNotFound))
{
if (q==0){
displayFirstName = [[NSString alloc] initWithFormat:@"%@",
[[[arrayProf objectAtIndex:i] componentsSeparatedByString:@"-"] objectAtIndex:0]] ;
}
else
{
displaySecondName = [[NSString alloc] initWithFormat:@"%@",
[[[arrayProf objectAtIndex:i] componentsSeparatedByString:@"-"] objectAtIndex:0]] ;
}
}
[strModel release];
}

[str release];
[str2 release];
[arrayProf removeAllObjects];
}

[arrayProf release];
}