Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isDataAvailableForKey should be public to easier to check data available #1595

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Parse/Parse/Internal/Object/PFObjectPrivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,6 @@
- (void)setHasBeenFetched:(BOOL)fetched;
- (void)_setDeleted:(BOOL)deleted;

- (BOOL)isDataAvailableForKey:(NSString *)key;

- (BOOL)_hasChanges;
- (BOOL)_hasOutstandingOperations;
- (PFOperationSet *)unsavedChanges;
Expand Down
7 changes: 7 additions & 0 deletions Parse/Parse/PFObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ NS_REQUIRES_PROPERTY_DEFINITIONS
*/
@property (nonatomic, assign, readonly, getter=isDataAvailable) BOOL dataAvailable;

/**
Gets whether the `PFObject` has data for given key

@return `YES` if data is available for given key
*/
- (BOOL)isDataAvailableForKey:(NSString *)key;

#if TARGET_OS_IOS

/**
Expand Down
33 changes: 17 additions & 16 deletions Parse/Parse/PFObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -743,19 +743,6 @@ - (void)_setDeleted:(BOOL)deleted {
}
}

- (BOOL)isDataAvailableForKey:(NSString *)key {
if (!key) {
return NO;
}

@synchronized (lock) {
if (self.dataAvailable) {
return YES;
}
return [_availableKeys containsObject:key];
}
}

///--------------------------------------
#pragma mark - Validations
///--------------------------------------
Expand Down Expand Up @@ -2030,6 +2017,19 @@ - (BOOL)isDataAvailable {
return self._state.complete;
}

- (BOOL)isDataAvailableForKey:(NSString *)key {
if (!key) {
return NO;
}

@synchronized (lock) {
if (self.dataAvailable) {
return YES;
}
return [_availableKeys containsObject:key];
}
}

- (instancetype)refresh {
return [self fetch];
}
Expand Down Expand Up @@ -2142,9 +2142,10 @@ - (void)setObject:(id)object forKeyedSubscript:(NSString *)key {

- (id)objectForKey:(NSString *)key {
@synchronized (lock) {
PFConsistencyAssert([self isDataAvailableForKey:key],
@"Key \"%@\" has no data. Call fetchIfNeeded before getting its value.", key);

if (![self isDataAvailableForKey:key]) {
return nil;
}

id result = _estimatedData[key];
if ([key isEqualToString:PFObjectACLRESTKey] && [result isKindOfClass:[PFACL class]]) {
PFACL *acl = result;
Expand Down
2 changes: 1 addition & 1 deletion Parse/Tests/Unit/ObjectUnitTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)testObjectForKey {

- (void)testObjectForUnavailableKey {
PFObject *object = [PFObject objectWithoutDataWithClassName:@"Yarr" objectId:nil];
PFAssertThrowsInconsistencyException(object[@"yarr"]);
XCTAssertNil(object[@"yarr"]);
}

- (void)testSettersWithNilArguments {
Expand Down
2 changes: 1 addition & 1 deletion ParseUI/Classes/SignUpViewController/PFSignUpView.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ - (void)layoutSubviews {
frame.origin.y = currentY + loginButtonTopInset;
_signUpButton.frame = frame;

currentY = CGRectGetMaxY(frame);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this being kept commented though?

// currentY = CGRectGetMaxY(frame);
}
}

Expand Down