Skip to content

rename firebase database classes to use objc prefix convention #184

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

Merged
merged 2 commits into from
Nov 3, 2016
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@import FirebaseDatabase;

#import "FirebaseArrayDelegate.h"
#import "FUIArrayDelegate.h"

NS_ASSUME_NONNULL_BEGIN

Expand All @@ -41,50 +41,52 @@ NS_ASSUME_NONNULL_BEGIN
@end

/**
* FirebaseArray provides an array structure that is synchronized with a Firebase reference or
* FUIArray provides an array structure that is synchronized with a Firebase reference or
* query. It is useful for building custom data structures or sources, and provides the base for
* FirebaseDataSource.
*/
@interface FirebaseArray : NSObject
@interface FUIArray : NSObject

/**
* The delegate object that array changes are surfaced to, which conforms to the
* @c FirebaseArrayDelegate protocol.
* @c FUIArrayDelegate protocol.
*/
@property(weak, nonatomic, nullable) id<FirebaseArrayDelegate> delegate;
@property(weak, nonatomic, nullable) id<FUIArrayDelegate> delegate;

/**
* The query on a Firebase reference that provides data to populate the instance of FirebaseArray.
* The query on a Firebase reference that provides data to populate the array.
*/
@property(strong, nonatomic) id<FIRDataObservable> query;

/**
* The number of objects in the FirebaseArray.
* The number of objects in the array.
*/
@property(nonatomic, readonly) NSUInteger count;

/**
* The items currently in the FirebaseArray.
* The items currently in the array.
*/
@property(nonatomic, readonly, copy) NSArray *items;

#pragma mark - Initializer methods

/**
* Initalizes FirebaseArray with a Firebase query (FIRDatabaseQuery) or database reference
* Initalizes an FUIArray with a Firebase query (FIRDatabaseQuery) or database reference
* (FIRDatabaseReference).
* @param query A query or Firebase database reference
* @param delegate An object conforming to FirebaseArrayDelegate that should receive delegate messages.
* @return A FirebaseArray instance
*/
- (instancetype)initWithQuery:(id<FIRDataObservable>)query
delegate:(nullable id<FirebaseArrayDelegate>)delegate NS_DESIGNATED_INITIALIZER;
delegate:(nullable id<FUIArrayDelegate>)delegate NS_DESIGNATED_INITIALIZER;

/**
* Initalizes FirebaseArray with a Firebase query (FIRDatabaseQuery) or database reference
* (FIRDatabaseReference).
* @param query A query or Firebase database reference
* @param query A query or Firebase database reference
* @return A FirebaseArray instance
* @param query A query or Firebase database reference
* @return An FUIArray instance
*/
- (instancetype)initWithQuery:(id<FIRDataObservable>)query;

Expand All @@ -98,14 +100,14 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Public API methods

/**
* Returns an object at a specific index in the FirebaseArray.
* Returns an object at a specific index in the array.
* @param index The index of the item to retrieve
* @return The object at the given index
*/
- (id)objectAtIndex:(NSUInteger)index;

/**
* Returns a Firebase reference for an object at a specific index in the FirebaseArray.
* Returns a Firebase reference for an object at a specific index in the array.
* @param index The index of the item to retrieve a reference for
* @return A Firebase reference for the object at the given index
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

// clang-format on

#import "FirebaseArray.h"
#import "FUIArray.h"

@interface FirebaseArray ()
@interface FUIArray ()

/**
* The backing collection that holds all of the FirebaseArray's data.
* The backing collection that holds all of the array's data.
*/
@property(strong, nonatomic) NSMutableArray<FIRDataSnapshot *> *snapshots;

Expand All @@ -35,11 +35,11 @@ @interface FirebaseArray ()

@end

@implementation FirebaseArray
@implementation FUIArray

#pragma mark - Initializer methods

- (instancetype)initWithQuery:(FIRDatabaseQuery *)query delegate:(id<FirebaseArrayDelegate>)delegate {
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query delegate:(id<FUIArrayDelegate>)delegate {
NSParameterAssert(query != nil);
self = [super init];
if (self) {
Expand Down Expand Up @@ -187,8 +187,8 @@ - (id)objectAtIndexedSubscript:(NSUInteger)index {
}

- (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)index{
@throw [NSException exceptionWithName:@"FirebaseArraySetIndexWithSubscript"
reason:@"Setting an object as FirebaseArray[i] is not supported."
@throw [NSException exceptionWithName:@"FUIArraySetIndexWithSubscript"
reason:@"Setting an object as FUIArray[i] is not supported."
userInfo:nil];
}

Expand Down
74 changes: 74 additions & 0 deletions FirebaseDatabaseUI/FUIArrayDelegate.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// clang-format off

//
// Copyright (c) 2016 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

// clang-format on

@class FUIArray;

/**
* A protocol to allow instances of FUIArray to raise events through a
* delegate. Raises all Firebase events except FIRDataEventTypeValue.
*/
@protocol FUIArrayDelegate<NSObject>

@optional

/**
* Delegate method which is called whenever an object is added to an FUIArray.
* On a FUIArray synchronized to a Firebase reference, this corresponds to a
* @c FIRDataEventTypeChildAdded event being raised.
* @param object The object added to the FUIArray
* @param index The index the child was added at
*/
- (void)array:(FUIArray *)array didAddObject:(id)object atIndex:(NSUInteger)index;

/**
* Delegate method which is called whenever an object is changed in an
* FUIArray. On a FUIArray synchronized to a Firebase reference, this
* corresponds to a @c FIRDataEventTypeChildChanged event being raised.
* @param object The object that changed in the FUIArray
* @param index The index the child was changed at
*/
- (void)array:(FUIArray *)array didChangeObject:(id)object atIndex:(NSUInteger)index;

/**
* Delegate method which is called whenever an object is removed from an
* FUIArray. On a FUIArray synchronized to a Firebase reference, this
* corresponds to a @c FIRDataEventTypeChildRemoved event being raised.
* @param object The object removed from the FUIArray
* @param index The index the child was removed at
*/
- (void)array:(FUIArray *)array didRemoveObject:(id)object atIndex:(NSUInteger)index;

/**
* Delegate method which is called whenever an object is moved within a
* FUIArray. On a FUIArray synchronized to a Firebase reference, this
* corresponds to a @c FIRDataEventTypeChildMoved event being raised.
* @param object The object that has moved locations in the FUIArray
* @param fromIndex The index the child is being moved from
* @param toIndex The index the child is being moved to
*/
- (void)array:(FUIArray *)array didMoveObject:(id)object fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex;

/**
* Delegate method which is called whenever the backing query is canceled.
* @param error the error that was raised
*/
- (void)array:(FUIArray *)array queryCancelledWithError:(NSError *)error;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,19 @@

@import UIKit;

#import "FirebaseDataSource.h"
#import "FUIDataSource.h"

NS_ASSUME_NONNULL_BEGIN

@class FIRDatabaseReference;

/**
* FirebaseCollectionViewDataSource provides an class that conforms to the
* UICollcetionViewDataSource protocol which allows UICollectionViews to
* implement
* FirebaseCollectionViewDataSource in order to provide a UICollectionView
* synchronized to a
* Firebase reference or query. In addition to handling all Firebase child
* events (added, changed,
* removed, moved), FirebaseCollectionViewDataSource handles UITableViewCell
* creation, either with
* the default UICollectionViewCell, prototype cells, custom
* UICollectionViewCell subclasses, or
* custom XIBs, and provides a simple [FirebaseCollectionViewDataSource
* populateCellWithBlock:]
* method which allows developers to populate the cells created for them with
* desired data from
* Firebase.
* FUICollectionViewDataSource provides a class that conforms to the
* UICollectionViewDataSource protocol which allows UICollectionViews to
* adopt FUICollectionViewDataSource in order to provide a UICollectionView
* synchronized to a Firebase reference or query.
*/
@interface FirebaseCollectionViewDataSource : FirebaseDataSource<UICollectionViewDataSource>
@interface FUICollectionViewDataSource : FUIDataSource<UICollectionViewDataSource>

/**
* The UICollectionView instance that operations (inserts, removals, moves,
Expand All @@ -61,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN
(UICollectionView *collectionView, NSIndexPath *indexPath, FIRDataSnapshot *object);

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates
* Initialize an instance of FUICollectionViewDataSource that populates
* UICollectionViewCells with FIRDataSnapshots.
* @param query A Firebase query to bind the data source to.
* @param collectionView An instance of a UICollectionView to bind to. This view
Expand All @@ -70,7 +58,7 @@ NS_ASSUME_NONNULL_BEGIN
* are displayed in the collection view. This closure is retained by the data
* source, so if you capture self in the closure and also claim ownership of the
* data source, be sure to avoid retain cycles by capturing a weak reference to self.
* @return An instance of FirebaseCollectionViewDataSource that populates
* @return An instance of FUICollectionViewDataSource that populates
* UICollectionViewCells with FIRDataSnapshots.
*/
- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
Expand All @@ -79,11 +67,11 @@ NS_ASSUME_NONNULL_BEGIN
NSIndexPath *indexPath,
FIRDataSnapshot *object))populateCell NS_DESIGNATED_INITIALIZER;

- (instancetype)initWithArray:(FirebaseArray *)array NS_UNAVAILABLE;
- (instancetype)initWithArray:(FUIArray *)array NS_UNAVAILABLE;

@end

@interface UICollectionView (FirebaseCollectionViewDataSource)
@interface UICollectionView (FUICollectionViewDataSource)

/**
* Creates a data source, attaches it to the collection view, and returns it.
Expand All @@ -96,10 +84,10 @@ NS_ASSUME_NONNULL_BEGIN
* @return The created data source. This value must be retained while the collection
* view is in use.
*/
- (FirebaseCollectionViewDataSource *)bindToQuery:(FIRDatabaseQuery *)query
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *object))populateCell __attribute__((warn_unused_result));
- (FUICollectionViewDataSource *)bindToQuery:(FIRDatabaseQuery *)query
populateCell:(UICollectionViewCell *(^)(UICollectionView *collectionView,
NSIndexPath *indexPath,
FIRDataSnapshot *object))populateCell __attribute__((warn_unused_result));

@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@

// clang-format on

#import "FirebaseCollectionViewDataSource.h"
#import "FUICollectionViewDataSource.h"

@import FirebaseDatabase;

@implementation FirebaseCollectionViewDataSource
@implementation FUICollectionViewDataSource

#pragma mark - FirebaseDataSource initializer methods
#pragma mark - FUIDataSource initializer methods

- (instancetype)initWithQuery:(FIRDatabaseQuery *)query
view:(UICollectionView *)collectionView
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
NSIndexPath *,
FIRDataSnapshot *))populateCell {
FirebaseArray *array = [[FirebaseArray alloc] initWithQuery:query];
FUIArray *array = [[FUIArray alloc] initWithQuery:query];
self = [super initWithArray:array];
if (self) {
_collectionView = collectionView;
Expand All @@ -40,24 +40,24 @@ - (instancetype)initWithQuery:(FIRDatabaseQuery *)query
return self;
}

#pragma mark - FirebaseArrayDelegate methods
#pragma mark - FUIArrayDelegate methods

- (void)array:(FirebaseArray *)array didAddObject:(id)object atIndex:(NSUInteger)index {
- (void)array:(FUIArray *)array didAddObject:(id)object atIndex:(NSUInteger)index {
[self.collectionView
insertItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index inSection:0] ]];
}

- (void)array:(FirebaseArray *)array didChangeObject:(id)object atIndex:(NSUInteger)index {
- (void)array:(FUIArray *)array didChangeObject:(id)object atIndex:(NSUInteger)index {
[self.collectionView
reloadItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index inSection:0] ]];
}

- (void)array:(FirebaseArray *)array didRemoveObject:(id)object atIndex:(NSUInteger)index {
- (void)array:(FUIArray *)array didRemoveObject:(id)object atIndex:(NSUInteger)index {
[self.collectionView
deleteItemsAtIndexPaths:@[ [NSIndexPath indexPathForItem:index inSection:0] ]];
}

- (void)array:(FirebaseArray *)array didMoveObject:(id)object
- (void)array:(FUIArray *)array didMoveObject:(id)object
fromIndex:(NSUInteger)fromIndex toIndex:(NSUInteger)toIndex {
[self.collectionView moveItemAtIndexPath:[NSIndexPath indexPathForItem:fromIndex inSection:0]
toIndexPath:[NSIndexPath indexPathForItem:toIndex inSection:0]];
Expand Down Expand Up @@ -85,14 +85,14 @@ - (NSInteger)collectionView:(nonnull UICollectionView *)collectionView

@end

@implementation UICollectionView (FirebaseCollectionViewDataSource)
@implementation UICollectionView (FUICollectionViewDataSource)

- (FirebaseCollectionViewDataSource *)bindToQuery:(FIRDatabaseQuery *)query
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
NSIndexPath *,
FIRDataSnapshot *))populateCell {
FirebaseCollectionViewDataSource *dataSource =
[[FirebaseCollectionViewDataSource alloc] initWithQuery:query view:self populateCell:populateCell];
- (FUICollectionViewDataSource *)bindToQuery:(FIRDatabaseQuery *)query
populateCell:(UICollectionViewCell *(^)(UICollectionView *,
NSIndexPath *,
FIRDataSnapshot *))populateCell {
FUICollectionViewDataSource *dataSource =
[[FUICollectionViewDataSource alloc] initWithQuery:query view:self populateCell:populateCell];
self.dataSource = dataSource;
return dataSource;
}
Expand Down
Loading