Skip to content

Commit

Permalink
Removed __kindof, since support in Cocoapods doesn't seem to work pro…
Browse files Browse the repository at this point in the history
…perly. Also added proper macros for nullability and generics to guard against older versions.
  • Loading branch information
asciimike committed Aug 15, 2015
1 parent 97b6b1a commit 33bd35d
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 29 deletions.
4 changes: 4 additions & 0 deletions FirebaseUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
D8B6ACF91B583D3E005CDDB2 /* FirebaseDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B6ACED1B583C33005CDDB2 /* FirebaseDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8B6ACFB1B583D48005CDDB2 /* FirebaseArray.h in Headers */ = {isa = PBXBuildFile; fileRef = D8B6ACEC1B583C33005CDDB2 /* FirebaseArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8DA10F11B7AC50400D00954 /* FirebaseCollectionViewDataSource.h in Headers */ = {isa = PBXBuildFile; fileRef = D8DA10F01B7AC50400D00954 /* FirebaseCollectionViewDataSource.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8DB81A81B7EA357001429C6 /* XCodeMacros.h in Headers */ = {isa = PBXBuildFile; fileRef = D8DB81A71B7EA357001429C6 /* XCodeMacros.h */; settings = {ATTRIBUTES = (Public, ); }; };
D8DF55621B742DB40030E996 /* FirebaseCollectionViewDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = D8DF55611B742DB40030E996 /* FirebaseCollectionViewDataSource.m */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -73,6 +74,7 @@
D8C579A61B57349000899F86 /* libFirebaseUI.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libFirebaseUI.a; sourceTree = BUILT_PRODUCTS_DIR; };
D8C579BB1B5837DF00899F86 /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; };
D8DA10F01B7AC50400D00954 /* FirebaseCollectionViewDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FirebaseCollectionViewDataSource.h; path = API/FirebaseCollectionViewDataSource.h; sourceTree = "<group>"; };
D8DB81A71B7EA357001429C6 /* XCodeMacros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XCodeMacros.h; sourceTree = "<group>"; };
D8DF55611B742DB40030E996 /* FirebaseCollectionViewDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FirebaseCollectionViewDataSource.m; path = Implementation/FirebaseCollectionViewDataSource.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -109,6 +111,7 @@
D8B6ACED1B583C33005CDDB2 /* FirebaseDataSource.h */,
D8B6ACEE1B583C33005CDDB2 /* FirebaseTableViewDataSource.h */,
D8DA10F01B7AC50400D00954 /* FirebaseCollectionViewDataSource.h */,
D8DB81A71B7EA357001429C6 /* XCodeMacros.h */,
);
name = API;
sourceTree = "<group>";
Expand Down Expand Up @@ -160,6 +163,7 @@
D87E4ABA1B7D832D00A53633 /* FirebaseUI.h in Headers */,
D8B6ACF91B583D3E005CDDB2 /* FirebaseDataSource.h in Headers */,
D8784C401B719F280025587E /* FirebaseArrayDelegate.h in Headers */,
D8DB81A81B7EA357001429C6 /* XCodeMacros.h in Headers */,
D8124F431B72B347003441AD /* FirebaseTableViewDataSource.h in Headers */,
D8DA10F11B7AC50400D00954 /* FirebaseCollectionViewDataSource.h in Headers */,
D8B6ACFB1B583D48005CDDB2 /* FirebaseArray.h in Headers */,
Expand Down
3 changes: 2 additions & 1 deletion FirebaseUI/API/FirebaseArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

#import <Foundation/Foundation.h>
#import <FirebaseUI/XCodeMacros.h>

#import "FirebaseArrayDelegate.h"

Expand All @@ -52,7 +53,7 @@
/**
* The delegate object that array changes are surfaced to.
*/
@property (strong, nonatomic) NSMutableArray<FDataSnapshot *> *snapshots;
@property (strong, nonatomic) __GENERIC(NSMutableArray, FDataSnapshot *) *snapshots;

#pragma mark -
#pragma mark Initializer methods
Expand Down
23 changes: 12 additions & 11 deletions FirebaseUI/API/FirebaseCollectionViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

#import <UIKit/UIKit.h>
#import <FirebaseUI/XCodeMacros.h>

#import "FirebaseDataSource.h"

Expand All @@ -40,22 +41,22 @@
/**
* The model class to coerce FDataSnapshots to (if desired). For instance, if the modelClass is set to [Message class] in Obj-C or Message.self in Swift, then objects of type Message will be returned instead of type FDataSnapshot.
*/
@property (strong, nonatomic, nonnull) Class modelClass;
@property (strong, nonatomic, __NON_NULL) Class modelClass;

/**
* The reuse identifier for cells in the UICollectionView.
*/
@property (strong, nonatomic, nonnull) NSString *reuseIdentifier;
@property (strong, nonatomic, __NON_NULL) NSString *reuseIdentifier;

/**
* The UICollectionView instance that operations (inserts, removals, moves, etc.) are performed against.
*/
@property (strong, nonatomic, nonnull) UICollectionView *collectionView;
@property (strong, nonatomic, __NON_NULL) UICollectionView *collectionView;

/**
* The callback to populate a subclass of UICollectionViewCell with an object provided by the datasource.
*/
@property (strong, nonatomic, nonnull) void(^populateCell)(__kindof UICollectionViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object);
@property (strong, nonatomic, __NON_NULL) void(^populateCell)(UICollectionViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object);

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates UICollectionViewCells with FDataSnapshots.
Expand All @@ -64,7 +65,7 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates UICollectionViewCells with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates a custom subclass of UICollectionViewCell with FDataSnapshots.
Expand All @@ -74,7 +75,7 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates a custom subclass of UICollectionViewCell with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref cellClass:(nullable Class)cell reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref cellClass:(__NULLABLE Class)cell reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates a custom xib with FDataSnapshots.
Expand All @@ -84,7 +85,7 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates a custom xib with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref nibNamed:(nonnull NSString *)nibName reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref nibNamed:(__NON_NULL NSString *)nibName reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates UICollectionViewCells with a custom model class.
Expand All @@ -94,7 +95,7 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates UICollectionViewCells with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates a custom subclass of UICollectionViewCell with a custom model class.
Expand All @@ -105,7 +106,7 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates a custom subclass of UICollectionViewCell with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model cellClass:(nullable Class)cell reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model cellClass:(__NULLABLE Class)cell reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* Initialize an instance of FirebaseCollectionViewDataSource that populates a custom xib with a custom model class.
Expand All @@ -116,12 +117,12 @@
* @param collectionView An instance of a UICollectionView to bind to
* @return An instance of FirebaseCollectionViewDataSource that populates a custom xib with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model nibNamed:(nonnull NSString *)nibName reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UICollectionView *)collectionView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model nibNamed:(__NON_NULL NSString *)nibName reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UICollectionView *)collectionView;

/**
* This method populates the fields of a UICollectionViewCell or subclass given an FDataSnapshot (or custom model object).
* @param callback A block which returns an initialized UICollectionViewCell (or subclass) and the corresponding object to populate the cell with.
*/
- (void)populateCellWithBlock:(nonnull void(^)( __kindof UICollectionViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object))callback;
- (void)populateCellWithBlock:(__NON_NULL void(^)(UICollectionViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object))callback;

@end
23 changes: 12 additions & 11 deletions FirebaseUI/API/FirebaseTableViewDataSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/

#import <UIKit/UIKit.h>
#import <FirebaseUI/XCodeMacros.h>

#import "FirebaseDataSource.h"

Expand All @@ -40,22 +41,22 @@
/**
* The model class to coerce FDataSnapshots to (if desired). For instance, if the modelClass is set to [Message class] in Obj-C or Message.self in Swift, then objects of type Message will be returned instead of type FDataSnapshot.
*/
@property (strong, nonatomic, nonnull) Class modelClass;
@property (strong, nonatomic, __NON_NULL) Class modelClass;

/**
* The reuse identifier for cells in the UITableView.
*/
@property (strong, nonatomic, nonnull) NSString *reuseIdentifier;
@property (strong, nonatomic, __NON_NULL) NSString *reuseIdentifier;

/**
* The UITableView instance that operations (inserts, removals, moves, etc.) are performed against.
*/
@property (strong, nonatomic, nonnull) UITableView *tableView;
@property (strong, nonatomic, __NON_NULL) UITableView *tableView;

/**
* The callback to populate a subclass of UITableViewCell with an object provided by the datasource.
*/
@property (strong, nonatomic, nonnull) void(^populateCell)(__kindof UITableViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object);
@property (strong, nonatomic, __NON_NULL) void(^populateCell)(UITableViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object);

/**
* Initialize an instance of FirebaseTableViewDataSource that populates UITableViewCells with FDataSnapshots.
Expand All @@ -64,7 +65,7 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates UITableViewCells with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* Initialize an instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with FDataSnapshots.
Expand All @@ -74,7 +75,7 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref cellClass:(nullable Class)cell reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref cellClass:(__NULLABLE Class)cell reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* Initialize an instance of FirebaseTableViewDataSource that populates a custom xib with FDataSnapshots.
Expand All @@ -84,7 +85,7 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates a custom xib with FDataSnapshots
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref nibNamed:(nonnull NSString *)nibName reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref nibNamed:(__NON_NULL NSString *)nibName reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* Initialize an instance of FirebaseTableViewDataSource that populates UITableViewCells with a custom model class.
Expand All @@ -94,7 +95,7 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates UITableViewCells with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* Initialize an instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with a custom model class.
Expand All @@ -105,7 +106,7 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates a custom subclass of UITableViewCell with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model cellClass:(nullable Class)cell reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model cellClass:(__NULLABLE Class)cell reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* Initialize an instance of FirebaseTableViewDataSource that populates a custom xib with a custom model class.
Expand All @@ -116,13 +117,13 @@
* @param tableView An instance of a UITableView to bind to
* @return An instance of FirebaseTableViewDataSource that populates a custom xib with a custom model class
*/
- (nonnull instancetype)initWithRef:(nonnull Firebase *)ref modelClass:(nullable Class)model nibNamed:(nonnull NSString *)nibName reuseIdentifier:(nonnull NSString *)identifier view:(nonnull UITableView *)tableView;
- (__NON_NULL instancetype)initWithRef:(__NON_NULL Firebase *)ref modelClass:(__NULLABLE Class)model nibNamed:(__NON_NULL NSString *)nibName reuseIdentifier:(__NON_NULL NSString *)identifier view:(__NON_NULL UITableView *)tableView;

/**
* This method populates the fields of a UITableViewCell or subclass given a model object (or FDataSnapshot).
* @param callback A block which returns an initialized UITableViewCell (or subclass) and the corresponding object to populate the cell with.
*/
- (void)populateCellWithBlock:(nonnull void(^)(__kindof UITableViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object))callback;
- (void)populateCellWithBlock:(__NON_NULL void(^)(UITableViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object))callback;

@end

8 changes: 4 additions & 4 deletions FirebaseUI/API/FirebaseUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@

#import <Foundation/Foundation.h>

#import "FirebaseArray.h"
#import "FirebaseDataSource.h"
#import "FirebaseTableViewDataSource.h"
#import "FirebaseCollectionViewDataSource.h"
#import <FirebaseUI/FirebaseArray.h>
#import <FirebaseUI/FirebaseDataSource.h>
#import <FirebaseUI/FirebaseTableViewDataSource.h>
#import <FirebaseUI/FirebaseCollectionViewDataSource.h>

@interface FirebaseUI : NSObject

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ -(NSInteger)collectionView:(nonnull UICollectionView *)collectionView numberOfIt
return [self.array count];
}

- (void)populateCellWithBlock:(nonnull void(^)( __kindof UICollectionViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object))callback;
- (void)populateCellWithBlock:(__NON_NULL void(^)(UICollectionViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object))callback;
{
self.populateCell = callback;
}
Expand Down
2 changes: 1 addition & 1 deletion FirebaseUI/Implementation/FirebaseTableViewDataSource.m
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
return [self.array count];
}

- (void)populateCellWithBlock:(nonnull void(^)( __kindof UITableViewCell * _Nonnull cell, __kindof NSObject * _Nonnull object))callback;
- (void)populateCellWithBlock:(__NON_NULL void(^)(UITableViewCell * __NON_NULL_PTR cell, NSObject * __NON_NULL_PTR object))callback;
{
self.populateCell = callback;
}
Expand Down
56 changes: 56 additions & 0 deletions FirebaseUI/XCodeMacros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Firebase UI Bindings iOS Library
*
* Copyright © 2015 Firebase - All Rights Reserved
* https://www.firebase.com
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binaryform must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY FIREBASE AS IS AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
* EVENT SHALL FIREBASE BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef XCodeMacros_h
#define XCodeMacros_h

#if __has_feature(nullability)
# define __ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
# define __ASSUME_NONNULL_END NS_ASSUME_NONNULL_END
# define __NULLABLE nullable
# define __NULLABLE_PTR __nullable
# define __NON_NULL nonnull
# define __NON_NULL_PTR __nonnull
#else
# define __ASSUME_NONNULL_BEGIN
# define __ASSUME_NONNULL_END
# define __NULLABLE
# define __NULLABLE_PTR
# define __NON_NULL
# define __NON_NULL_PTR
#endif

#if __has_feature(objc_generics)
# define __GENERIC(class, ...) class<__VA_ARGS__>
# define __GENERIC_TYPE(type) type
#else
# define __GENERIC(class, ...) class
# define __GENERIC_TYPE(type) id
#endif

#endif /* XCodeMacros_h */

0 comments on commit 33bd35d

Please sign in to comment.