0

I have an array within objects like below;

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

TableStructure *structure = [[TableStructure alloc] init];
                    structure.TableName =@"Client";
                    structure.Type =@"U";
                    structure.ColumnName =@"Id";
                    structure.DataType =@"int";
                    structure.Length = 2;

TableStructure *structure2 = [[TableStructure alloc] init];
                    structure2.TableName =@"Client";
                    structure2.Type =@"U";
                    structure2.ColumnName =@"Name";
                    structure2.DataType =@"text";
                    structure2.Length = 20;

[tableStructure addObject:structure];
[tableStructure addObject:structure2];


 NSString *typeFilter = @"U";
 NSString *nameFilter = @"sysname";
 NSString *tableNameFilter = @"Sync";

 NSPredicate *pred = [NSPredicate predicateWithFormat:@"Type == %@ and DataType != %@ and TableName != %@)", typeFilter, nameFilter, tableNameFilter];

 NSArray *filteredArray = [tableStructure filteredArrayUsingPredicate:pred];

When the debugger came to NSPredicete *pred... line, it gives 'Unable to parse the format string "Type == %@ and DataType != %@ and TableName != %@)"' error.

How can I solve this?

4

3 回答 3

1

You have an unbalanced closing parenthesis in the predicate string:

@"Type == %@ and DataType != %@ and TableName != %@)"
                                           HERE ---^

If you remove that it should work.

于 2013-07-05T07:38:06.103 回答
1

You simply have an orphaned ")", try this: [NSPredicate predicateWithFormat:@"Type == %@ and DataType != %@ and TableName != %@", typeFilter, nameFilter, tableNameFilter]; `

于 2013-07-05T07:38:08.120 回答
1

Try this,No need of )

 NSPredicate *pred = [NSPredicate predicateWithFormat:@"Type == %@ and DataType != %@ and TableName != %@", typeFilter, nameFilter, tableNameFilter];
于 2013-07-05T07:40:17.650 回答