Skip to content

Commit

Permalink
Created NI_WEAK & NI_STRONG
Browse files Browse the repository at this point in the history
  • Loading branch information
yosit committed Oct 15, 2012
1 parent 452e5c4 commit f0ac768
Show file tree
Hide file tree
Showing 25 changed files with 89 additions and 70 deletions.
10 changes: 5 additions & 5 deletions src/core/src/NIDataStructures.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

// The internal representation of a single node.
@interface NILinkedListNode : NSObject
@property (nonatomic, readwrite, retain) id object;
@property (nonatomic, readwrite, retain) NILinkedListNode* prev;
@property (nonatomic, readwrite, retain) NILinkedListNode* next;
@property (nonatomic, readwrite, NI_STRONG) id object;
@property (nonatomic, readwrite, NI_STRONG) NILinkedListNode* prev;
@property (nonatomic, readwrite, NI_STRONG) NILinkedListNode* next;
@end

@implementation NILinkedListNode
Expand Down Expand Up @@ -61,8 +61,8 @@ - (BOOL)isEqual:(id)object {

@interface NILinkedList()
// Exposed so that the linked list enumerator can iterate over the nodes directly.
@property (nonatomic, readonly, retain) NILinkedListNode* head;
@property (nonatomic, readonly, retain) NILinkedListNode* tail;
@property (nonatomic, readonly, NI_STRONG) NILinkedListNode* head;
@property (nonatomic, readonly, NI_STRONG) NILinkedListNode* tail;
@property (nonatomic, readwrite, assign) NSUInteger count;
@property (nonatomic, readwrite, assign) unsigned long modificationNumber;
@end
Expand Down
12 changes: 6 additions & 6 deletions src/core/src/NIInMemoryCache.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@

@interface NIMemoryCache()
// Mapping from a name (usually a URL) to an internal object.
@property (nonatomic, readwrite, retain) NSMutableDictionary* cacheMap;
@property (nonatomic, readwrite, NI_STRONG) NSMutableDictionary* cacheMap;
// A linked list of least recently used cache objects. Most recently used is the tail.
@property (nonatomic, readwrite, retain) NILinkedList* lruCacheObjects;
@property (nonatomic, readwrite, NI_STRONG) NILinkedList* lruCacheObjects;
@end


Expand All @@ -49,12 +49,12 @@ @interface NIMemoryCacheInfo : NSObject
/**
* @brief The object stored in the cache.
*/
@property (nonatomic, readwrite, retain) id object;
@property (nonatomic, readwrite, NI_STRONG) id object;

/**
* @brief The date after which the image is no longer valid and should be removed from the cache.
*/
@property (nonatomic, readwrite, retain) NSDate* expirationDate;
@property (nonatomic, readwrite, NI_STRONG) NSDate* expirationDate;

/**
* @brief The last time this image was accessed.
Expand All @@ -64,12 +64,12 @@ @interface NIMemoryCacheInfo : NSObject
* images. When the memory limit is reached, we sort the cache based on the last access times and
* then prune images until we're under the memory limit again.
*/
@property (nonatomic, readwrite, retain) NSDate* lastAccessTime;
@property (nonatomic, readwrite, NI_STRONG) NSDate* lastAccessTime;

/**
* @brief The location of this object in the least-recently used linked list.
*/
@property (nonatomic, readwrite, retain) NILinkedListLocation* lruLocation;
@property (nonatomic, readwrite, NI_STRONG) NILinkedListLocation* lruLocation;

/**
* @brief Determine whether this cache entry has past its expiration date.
Expand Down
2 changes: 1 addition & 1 deletion src/core/src/NIOperations+Subclassing.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
//

@interface NIOperation()
@property (readwrite, retain) NSError* lastError;
@property (readwrite, NI_STRONG) NSError* lastError;
@end
6 changes: 4 additions & 2 deletions src/core/src/NIOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "NIPreprocessorMacros.h" /* for NI_WEAK */

@class NIOperation;

typedef void (^NIOperationBlock)(NIOperation* operation);
Expand Down Expand Up @@ -48,8 +50,8 @@ typedef void (^NIOperationDidFailBlock)(NIOperation* operation, NSError* error);
*/
@interface NIOperation : NSOperation

@property (readwrite, assign) id<NIOperationDelegate> delegate;
@property (readonly, retain) NSError* lastError;
@property (readwrite, NI_WEAK) id<NIOperationDelegate> delegate;
@property (readonly, NI_STRONG) NSError* lastError;
@property (readwrite, assign) NSInteger tag;

@property (readwrite, copy) NIOperationBlock didStartBlock;
Expand Down
17 changes: 17 additions & 0 deletions src/core/src/NIPreprocessorMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,23 @@ NI_FIX_CATEGORY_BUG(UIViewController_MyCustomCategory);
*/
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

/**
* A helper macro to keep the interfaces compatiable with pre ARC compilers.
* Useful when you put nimbus in a library and link it to a GCC LLVM compiler.
*/

#if defined(__has_feature) && __has_feature(objc_arc_weak)
#define NI_WEAK weak
#define NI_STRONG strong
#elif defined(__has_feature) && __has_feature(objc_arc)
#define NI_WEAK __unsafe_unretained
#define NI_STRONG retain
#else
#define NI_WEAK assign
#define NI_STRONG retain
#endif


///////////////////////////////////////////////////////////////////////////////////////////////////
/**@}*/// End of Preprocessor Macros //////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
4 changes: 3 additions & 1 deletion src/core/src/NISnapshotRotation.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "NIPreprocessorMacros.h" /* for NI_WEAK */

/**
* An object designed to easily implement snapshot rotation.
*
Expand Down Expand Up @@ -48,7 +50,7 @@
// Designated initializer.
- (id)initWithDelegate:(id<NISnapshotRotationDelegate>)delegate;

@property (nonatomic, readwrite, assign) id<NISnapshotRotationDelegate> delegate;
@property (nonatomic, readwrite, NI_WEAK) id<NISnapshotRotationDelegate> delegate;

@property (nonatomic, readonly, assign) CGRect frameBeforeRotation;
@property (nonatomic, readonly, assign) CGRect frameAfterRotation;
Expand Down
4 changes: 2 additions & 2 deletions src/core/src/NISnapshotRotation.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ @interface NISnapshotRotation()
@property (nonatomic, readwrite, assign) CGRect frameBeforeRotation;
@property (nonatomic, readwrite, assign) CGRect frameAfterRotation;

@property (nonatomic, readwrite, retain) UIImageView* snapshotViewBeforeRotation;
@property (nonatomic, readwrite, retain) UIImageView* snapshotViewAfterRotation;
@property (nonatomic, readwrite, NI_STRONG) UIImageView* snapshotViewBeforeRotation;
@property (nonatomic, readwrite, NI_STRONG) UIImageView* snapshotViewAfterRotation;
@end


Expand Down
2 changes: 1 addition & 1 deletion src/core/src/NIViewRecycler.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#endif

@interface NIViewRecycler()
@property (nonatomic, readwrite, retain) NSMutableDictionary* reuseIdentifiersToRecycledViews;
@property (nonatomic, readwrite, NI_STRONG) NSMutableDictionary* reuseIdentifiersToRecycledViews;
@end


Expand Down
7 changes: 0 additions & 7 deletions src/core/src/NimbusCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ view.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin
| UIViewAutoresizingFlexibleBottomMargin);
@endcode
*/
#if __has_feature(objc_arc_weak)
#define YT_WEAK weak
#elif __has_feature(objc_arc)
#define YT_WEAK __unsafe_unretained
#else
#define YT_WEEK assign
#endif

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
Expand Down
12 changes: 7 additions & 5 deletions src/models/src/NICellBackgrounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

#import "NIPreprocessorMacros.h" /* for NI_WEAK */

// Flags set on the cell's backgroundView's tag property to indicate placement of the cell.
typedef enum {
NIGroupedCellBackgroundFlagIsLast = (1 << 0),
Expand All @@ -36,12 +38,12 @@ typedef enum {

- (UIImage *)imageForFirst:(BOOL)first last:(BOOL)last highlighted:(BOOL)highlighted;

@property (nonatomic, retain) UIColor* innerBackgroundColor; // Default: [UIColor whiteColor]
@property (nonatomic, retain) NSMutableArray* highlightedInnerGradientColors; // Default: RGBCOLOR(53, 141, 245), RGBCOLOR(16, 93, 230)
@property (nonatomic, NI_STRONG) UIColor* innerBackgroundColor; // Default: [UIColor whiteColor]
@property (nonatomic, NI_STRONG) NSMutableArray* highlightedInnerGradientColors; // Default: RGBCOLOR(53, 141, 245), RGBCOLOR(16, 93, 230)
@property (nonatomic, assign) CGFloat shadowWidth; // Default: 4
@property (nonatomic, retain) UIColor* shadowColor; // Default: RGBACOLOR(0, 0, 0, 0.3)
@property (nonatomic, retain) UIColor* borderColor; // Default: RGBACOLOR(0, 0, 0, 0.07)
@property (nonatomic, retain) UIColor* dividerColor; // Default: RGBCOLOR(230, 230, 230)
@property (nonatomic, NI_STRONG) UIColor* shadowColor; // Default: RGBACOLOR(0, 0, 0, 0.3)
@property (nonatomic, NI_STRONG) UIColor* borderColor; // Default: RGBACOLOR(0, 0, 0, 0.07)
@property (nonatomic, NI_STRONG) UIColor* dividerColor; // Default: RGBCOLOR(230, 230, 230)
@property (nonatomic, assign) CGFloat borderRadius; // Default: 5

@end
Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NICellBackgrounds.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
static const CGSize kCellImageSize = {44, 44};

@interface NIGroupedCellBackground()
@property (nonatomic, retain) NSMutableDictionary* cachedImages;
@property (nonatomic, NI_STRONG) NSMutableDictionary* cachedImages;
@end


Expand Down
6 changes: 3 additions & 3 deletions src/models/src/NICellCatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef CGFloat (^NICellDrawRectBlock)(CGRect rect, id object, UITableViewCell*
- (id)initWithBlock:(NICellDrawRectBlock)block object:(id)object;
+ (id)objectWithBlock:(NICellDrawRectBlock)block object:(id)object;
@property (nonatomic, copy) NICellDrawRectBlock block;
@property (nonatomic, retain) id object;
@property (nonatomic, NI_STRONG) id object;
@end

/**
Expand All @@ -47,7 +47,7 @@ typedef CGFloat (^NICellDrawRectBlock)(CGRect rect, id object, UITableViewCell*
+ (id)objectWithTitle:(NSString *)title image:(UIImage *)image;
+ (id)objectWithTitle:(NSString *)title;
@property (nonatomic, copy) NSString* title;
@property (nonatomic, retain) UIImage* image;
@property (nonatomic, NI_STRONG) UIImage* image;
@end

/**
Expand Down Expand Up @@ -85,7 +85,7 @@ typedef CGFloat (^NICellDrawRectBlock)(CGRect rect, id object, UITableViewCell*
* @ingroup TableCellCatalog
*/
@interface NIDrawRectBlockCell : UITableViewCell <NICell>
@property (nonatomic, retain) UIView* blockView;
@property (nonatomic, NI_STRONG) UIView* blockView;
@end

/**
Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NICellCatalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ - (BOOL)shouldUpdateCellWithObject:(id)object {
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface NIDrawRectBlockView : UIView
@property (nonatomic, copy) NICellDrawRectBlock block;
@property (nonatomic, retain) id object;
@property (nonatomic, NI_STRONG) id object;
@property (nonatomic, assign) UITableViewCell* cell;
@end

Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NICellFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ _model.delegate = (id)[NICellFactory class];
+ (id)objectWithCellClass:(Class)cellClass userInfo:(id)userInfo;
+ (id)objectWithCellClass:(Class)cellClass;

@property (nonatomic, readonly, retain) id userInfo;
@property (nonatomic, readonly, NI_STRONG) id userInfo;

@end

Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NICellFactory.m
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ + (id)objectFromKeyClass:(Class)keyClass map:(NSMutableDictionary *)map {
///////////////////////////////////////////////////////////////////////////////////////////////////
@interface NICellObject()
@property (nonatomic, assign) Class cellClass;
@property (nonatomic, retain) id userInfo;
@property (nonatomic, NI_STRONG) id userInfo;
@end


Expand Down
24 changes: 12 additions & 12 deletions src/models/src/NIFormCellCatalog.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
@property (nonatomic, assign) float value;
@property (nonatomic, assign) float minimumValue;
@property (nonatomic, assign) float maximumValue;
@property (nonatomic, assign) id didChangeTarget;
@property (nonatomic, NI_WEAK) id didChangeTarget;
@property (nonatomic, assign) SEL didChangeSelector;

@end
Expand Down Expand Up @@ -155,8 +155,8 @@

@property (nonatomic, copy) NSString *labelText;
@property (nonatomic, assign) NSInteger selectedIndex;
@property (nonatomic, retain) NSArray *segments;
@property (nonatomic, assign) id didChangeTarget;
@property (nonatomic, NI_STRONG) NSArray *segments;
@property (nonatomic, NI_WEAK) id didChangeTarget;
@property (nonatomic, assign) SEL didChangeSelector;

@end
Expand Down Expand Up @@ -200,9 +200,9 @@
+ (id)datePickerElementWithID:(NSInteger)elementID labelText:(NSString *)labelText date:(NSDate *)date datePickerMode:(UIDatePickerMode)datePickerMode;

@property (nonatomic, copy) NSString *labelText;
@property (nonatomic, retain) NSDate *date;
@property (nonatomic, NI_STRONG) NSDate *date;
@property (nonatomic, assign) UIDatePickerMode datePickerMode;
@property (nonatomic, assign) id didChangeTarget;
@property (nonatomic, NI_WEAK) id didChangeTarget;
@property (nonatomic, assign) SEL didChangeSelector;

@end
Expand All @@ -219,7 +219,7 @@
* @ingroup TableCellCatalog
*/
@interface NIFormElementCell : UITableViewCell <NICell>
@property (nonatomic, readonly, retain) NIFormElement* element;
@property (nonatomic, readonly, NI_STRONG) NIFormElement* element;
@end

/**
Expand All @@ -232,7 +232,7 @@
* @ingroup TableCellCatalog
*/
@interface NITextInputFormElementCell : NIFormElementCell <UITextFieldDelegate>
@property (nonatomic, readonly, retain) UITextField* textField;
@property (nonatomic, readonly, NI_STRONG) UITextField* textField;
@end

/**
Expand All @@ -245,7 +245,7 @@
* @ingroup TableCellCatalog
*/
@interface NISwitchFormElementCell : NIFormElementCell <UITextFieldDelegate>
@property (nonatomic, readonly, retain) UISwitch* switchControl;
@property (nonatomic, readonly, NI_STRONG) UISwitch* switchControl;
@end

/**
Expand All @@ -258,7 +258,7 @@
* @ingroup TableCellCatalog
*/
@interface NISliderFormElementCell : NIFormElementCell <UITextFieldDelegate>
@property (nonatomic, readonly, retain) UISlider* sliderControl;
@property (nonatomic, readonly, NI_STRONG) UISlider* sliderControl;
@end

@interface NITableViewModel (NIFormElementSearch)
Expand All @@ -276,7 +276,7 @@
* @ingroup TableCellCatalog
*/
@interface NISegmentedControlFormElementCell : NIFormElementCell
@property (nonatomic, readonly, retain) UISegmentedControl *segmentedControl;
@property (nonatomic, readonly, NI_STRONG) UISegmentedControl *segmentedControl;
@end

/**
Expand All @@ -287,7 +287,7 @@
* @ingroup TableCellCatalog
*/
@interface NIDatePickerFormElementCell : NIFormElementCell <UITextFieldDelegate>
@property (nonatomic, readonly, retain) UITextField *dateField;
@property (nonatomic, readonly, retain) UIDatePicker *datePicker;
@property (nonatomic, readonly, NI_STRONG) UITextField *dateField;
@property (nonatomic, readonly, NI_STRONG) UIDatePicker *datePicker;
@end

2 changes: 1 addition & 1 deletion src/models/src/NIFormCellCatalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,7 @@ - (void)selectedSegmentDidChangeValue {


@interface NIDatePickerFormElementCell()
@property (nonatomic, readwrite, retain) UITextField* dumbDateField;
@property (nonatomic, readwrite, NI_STRONG) UITextField* dumbDateField;
@end


Expand Down
6 changes: 3 additions & 3 deletions src/models/src/NIMutableTableViewModel+Private.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

@interface NIMutableTableViewModel (Private)

@property (nonatomic, retain) NSMutableArray* sections; // Array of NITableViewModelSection
@property (nonatomic, retain) NSMutableArray* sectionIndexTitles;
@property (nonatomic, retain) NSMutableDictionary* sectionPrefixToSectionIndex;
@property (nonatomic, NI_STRONG) NSMutableArray* sections; // Array of NITableViewModelSection
@property (nonatomic, NI_STRONG) NSMutableArray* sectionIndexTitles;
@property (nonatomic, NI_STRONG) NSMutableDictionary* sectionPrefixToSectionIndex;

@end

Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NIMutableTableViewModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ NSIndexSet* indexSet = [self.model addSectionWithTitle:@"New section"];

- (void)updateSectionIndex;

@property (nonatomic, assign) id<NIMutableTableViewModelDelegate> delegate;
@property (nonatomic, NI_WEAK) id<NIMutableTableViewModelDelegate> delegate;

@end

Expand Down
2 changes: 1 addition & 1 deletion src/models/src/NIRadioGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
// Designated initializer.
- (id)initWithController:(UIViewController *)controller;

@property (nonatomic, assign) id<NIRadioGroupDelegate> delegate;
@property (nonatomic, NI_WEAK) id<NIRadioGroupDelegate> delegate;

#pragma mark Mapping Objects

Expand Down
Loading

0 comments on commit f0ac768

Please sign in to comment.