Во-первых, ваш объект, вот как вы это настраиваете, пример:
Книга.ч
#import <Foundation/Foundation.h>
@interface Book : NSObject
@property (strong, nonatomic)NSString *bookID;
@property (strong, nonatomic)NSString *publishingYear;
@property (strong, nonatomic)NSString *author;
@property (strong, nonatomic)NSString *printHouse;
@property (strong, nonatomic)NSString *title;
@property (strong, nonatomic)NSString *ISBN;
-(id)initWithBookObjectId:(NSString *)bookID
publishingYear:(NSString *)publishingYear
author:(NSString *)author
printHouse:(NSString *)printHouse
title:(NSString *)title
ISBN:(NSString *)ISBN;
- (id)initWithDictionary:(PFObject *)dic;
@end
Книга.м
#import "Book.h"
#define NSHNullCheck(object) ([object isKindOfClass:[NSNull class]] ? nil : object)
@implementation Book
{
NSDictionary * descriptionDict;
}
-(id)initWithBookObjectId:(NSString *)bookID
publishingYear:(NSString *)publishingYear
author:(NSString *)author
printHouse:(NSString *)printHouse
title:(NSString *)title
ISBN:(NSString *)ISBN;
{
self = [super init];
if (self) {
_bookID = bookID;
_publishingYear = publishingYear;
_author = author;
_printHouse = printHouse;
_title = title;
_ISBN = ISBN;}
return self;
}
- (id)initWithDictionary:(PFObject *)dic
{
self = [self initWithBookObjectId:dic.objectId
publishingYear:NSHNullCheck([dic valueForKey:@"publishingYear"])
author:NSHNullCheck([dic valueForKey:@"author"])
printHouse:NSHNullCheck([dic valueForKey:@"printHouse"])
title:NSHNullCheck([dic valueForKey:@"title"])
ISBN:NSHNullCheck([dic valueForKey:@"ISBN"])];
descriptionDict = @{ @"sessionObjectId":_bookID,
@"teacherAge":_publishingYear,
@"teacherEmail":_author,
@"teacherFacebookuniquekey":_printHouse,
@"teacherFirstname":_title,
@"teacherGender":_ISBN};
return self;
}
- (id)init
{
self = [self initWithBookObjectId:nil
publishingYear:nil
author:nil
printHouse:nil
title:nil
ISBN:nil];
return self;
}
- (NSString *)description
{
return descriptionDict.description;
}
@end
Хранение данных в объектной модели: books — это массив, содержащий ваши «книжные объекты». Следующий фрагмент кода используется везде, где вы извлекаете данные из сети с помощью запроса от Parse.
for (PFObject *object in objects) { //"objects" here is the NSArrray returned from the parse query!
Book *book = [[Book alloc] initWithBookObjectId:object.objectId];
book.publishingYear = object[@"publishingYear"];
book.author = object[@"author"];
book.printHouse = object[@"printHouse"];
book.title = object[@"title"];
book.ISBN = object[@"isbn"];
[self.books addObject:book];
}
if ([self.searchTerm isEqualToString:@""]) {
self.filteredBooksArray = self.books;
} else {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.title contains[c] %@",self.searchTerm];
self.filteredBooksArray = [NSMutableArray arrayWithArray:[self.books filteredArrayUsingPredicate:predicate]];
}
[self.booksTable reloadData];
Итак, вот как вы выполняете поиск с помощью PFObjects: сначала вам нужно извлечь данные, сохранить эти данные внутри подкласса NSObject (объектная модель данных), а затем использовать предикаты регулярных выражений, как в любой объектной модели с функцией поиска в IOS. .
Есть такой метод:
PFQuery *query = [PFQuery queryWithClassName:@"Post"]
[query whereKey:@"hashtags" containsAllObjectsInArray:@[@"#parse", @"#ftw"]];
NSArray *parseFTWPosts = [query findObjects];
а затем этот метод:
/ Using PFQuery
[query whereKey:@"playerName" notEqualTo:@"Michael Yabuti"];
[query whereKey:@"playerAge" greaterThan:@18];
// Using NSPredicate
NSPredicate *predicate = [NSPredicate predicateWithFormat: @"playerName != 'Michael Yabuti' AND playerAge > 18"];
PFQuery *query = [PFQuery queryWithClassName:@"GameScore" predicate:predicate];
а затем этот фрагмент:
Specifying Constraints with NSPredicate
To get the most out of PFQuery we recommend using its methods listed below to add constraints. However, if you prefer using NSPredicate, a subset of the constraints can be specified by providing an NSPredicate when creating your PFQuery.
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"playerName = 'Dan Stemkosk'"];
PFQuery *query = [PFQuery queryWithClassName:@"GameScore" predicate:predicate];
let predicate = NSPredicate(format: "playerName = 'Dan Stemkosk'")
var query = PFQuery(className: "GameScore", predicate: predicate)
These features are supported:
Simple comparisons such as =, !=, <, >, <=, >=, and BETWEEN with a key and a constant.
Containment predicates, such as x IN {1, 2, 3}.
Key-existence predicates, such as x IN SELF.
BEGINSWITH expressions.
Compound predicates with AND, OR, and NOT.
Sub-queries with "key IN %@", subquery.
The following types of predicates are not supported:
Aggregate operations, such as ANY, SOME, ALL, or NONE.
Regular expressions, such as LIKE, MATCHES, CONTAINS, or ENDSWITH.
Predicates comparing one key to another.
Complex predicates with many ORed clauses.
и еще здесь:
https://github.com/ParsePlatform/Docs/blob/master/en/ios/queries.mdown
person
Larry Pickles
schedule
29.08.2015