아래와 같이 BOOL을 반환하는 새로운 메서드를 만들었습니다.BOOL 메서드가 블록 내부에서 YES를 반환하지 않습니다.
+(BOOL)checkIfGameAlreadyExistsAgainst:(PFUser *)opponentUser {
// Find all the games where the current user is user1 and the opponentUser is user2
PFQuery *currentUserIsUser1 = [PFQuery queryWithClassName:@"Game"];
[currentUserIsUser1 whereKey:kMESGameUser1 equalTo:[PFUser currentUser]];
[currentUserIsUser1 whereKey:kMESGameUser2 equalTo:opponentUser];
[currentUserIsUser1 whereKey:kMESGameIsActive equalTo:[NSNumber numberWithBool:YES]];
[currentUserIsUser1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (objects) {
// We have games where the current user is user1
// NEED TO RETURN NO TO THIS METHOD AND NOT RUN FURTHER IN METHOD...
NSLog(@"Results returned for existing game where current user is User1. Results: %@",objects);
} else {
// If there are no objects from first query and no error we run the second query
if (!error) {
// Find all the games where the current user is user2 and the opponentUser is user1
PFQuery *currentUserIsUser2 = [PFQuery queryWithClassName:@"Game"];
[currentUserIsUser2 whereKey:kMESGameUser1 equalTo:opponentUser];
[currentUserIsUser2 whereKey:kMESGameUser2 equalTo:[PFUser currentUser]];
[currentUserIsUser2 whereKey:kMESGameIsActive equalTo:[NSNumber numberWithBool:YES]];
[currentUserIsUser2 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (objects) {
// We have games where the current user is user2
// NEED TO RETURN NO TO THIS METHOD AND NOT RUN FURTHER IN METHOD...
NSLog(@"Results returned for existing game where current user is User2. Results: %@",objects);
}
}];
}
}
}];
return NO;
}
I 가지는 문제가있어서 내의 블록 내의 값 YES를 리턴하는 방법이다. 메소드의 섹션을 참조하십시오. // 메소드에 반환 할 필요가없고 메소드에서 더 이상 실행하지 않습니다. 여기서 어떻게 YES를 리턴 할 수 있습니까? 내가 YES를 반환하면 호환되지 않는 포인터 유형 오류가 발생합니다.
이 메서드는 YES를 반환하면이 메서드를 호출하고 결과에 따라 무언가를 수행 할 수 있습니다. 예를 들어,이 메서드를 호출해야하며 true이면 아무 것도 수행하지 않으면 다른 작업을 수행해야합니다.
나는 방법은 당신이 당신의 방법 안에 그 코드는 비동기 실행됩니다 생각 특히, 대신 BOOL 값을 반환하는 PARAMS 당신이 "성공/실패"블록을 사용하는 것이 좋습니다. – danypata