Tôi đang làm việc thông qua các hướng dẫn ở đây (học Swift) cho ứng dụng đầu tiên của tôi: http://www.appcoda.com/search-bar-tutorial-ios7/Sử dụng Predicate trong Swift
tôi bị mắc kẹt trên một phần này (Objective-C code):
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"name contains[c] %@", searchText];
searchResults = [recipes filteredArrayUsingPredicate:resultPredicate];
}
Bất cứ ai có thể tư vấn cách tạo tương đương cho NSPredicate trong Swift?
Cảm ơn. Bạn tiết kiệm cho tôi một ngày! – dusty
Để giải quyết dòng thứ hai của phương thức của bạn, bạn có thể sử dụng biến vị ngữ là: 'searchResults = recipes.filter {resultPredicate.evaluateWithObject ($ 0)}' –