Xcode 6.3 - Auto property synthesis will not synthesize property
Asked Answered
M

2

8

Error : Auto property synthesis will not synthesize property 'delegate'. It will be implemented by its superclass, use @dynamic to acknowledge intention

Code with Error : @property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;

Any help would be appreciated, thanks!

Here is my code:

#import "JBChartView.h"

@class JBBarChartView;

@protocol JBBarChartViewDataSource <JBChartViewDataSource>

@required

/**
 *  The number of bars in a given bar chart is the number of vertical views shown along the x-axis.
 *
 *  @param barChartView     The bar chart object requesting this information.
 *
 *  @return Number of bars in the given chart, displayed horizontally along the chart's x-axis.
 */
- (NSUInteger)numberOfBarsInBarChartView:(JBBarChartView *)barChartView;

@optional

/**
 *  A UIView subclass representing the bar at a particular index.
 *
 *  Default: solid black UIView.
 *
 *  @param barChartView     The bar chart object requesting this information.
 *  @param index            The 0-based index of a given bar (left to right, x-axis).
 *
 *  @return A UIView subclass. The view will automatically be resized by the chart during creation (ie. no need to set the frame).
 */
- (UIView *)barChartView:(JBBarChartView *)barChartView barViewAtIndex:(NSUInteger)index;

@end

@protocol JBBarChartViewDelegate <JBChartViewDelegate>

@required

/**
 *  Height for a bar at a given index (left to right). There is no ceiling on the the height;
 *  the chart will automatically normalize all values between the overal min and max heights.
 *
 *  @param barChartView     The bar chart object requesting this information.
 *  @param index            The 0-based index of a given bar (left to right, x-axis).
 *
 *  @return The y-axis height of the supplied bar index (x-axis)
 */
- (CGFloat)barChartView:(JBBarChartView *)barChartView heightForBarViewAtIndex:(NSUInteger)index;

@optional

/**
 *  Occurs when a touch gesture event occurs on a given bar (chart must be expanded).
 *  and the selection must occur within the bounds of the chart.
 *
 *  @param barChartView     A bar chart object informing the delegate about the new selection.
 *  @param index            The 0-based index of a given bar (left to right, x-axis).
 *  @param touchPoint       The touch point in relation to the chart's bounds (excludes footer and header).
 */
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index touchPoint:(CGPoint)touchPoint;
- (void)barChartView:(JBBarChartView *)barChartView didSelectBarAtIndex:(NSUInteger)index;

/**
 *  Occurs when selection ends by either ending a touch event or selecting an area that is outside the view's bounds.
 *  For selection start events, see: didSelectBarAtIndex...
 *
 *  @param barChartView     A bar chart object informing the delegate about the deselection.
 */
- (void)didDeselectBarChartView:(JBBarChartView *)barChartView;

/**
 *  If you already implement barChartView:barViewAtIndex: delegate - this method has no effect.
 *  If a custom UIView isn't supplied, a flat bar will be made automatically (default color black).
 *
 *  Default: if none specified - calls barChartView:barViewAtIndex:.
 *
 *  @param barChartView     The bar chart object requesting this information.
 *  @param index            The 0-based index of a given bar (left to right, x-axis).
 *
 *  @return The color to be used to color a bar in the chart.
 */
- (UIColor *)barChartView:(JBBarChartView *)barChartView colorForBarViewAtIndex:(NSUInteger)index;

/**
 *  The selection color to be overlayed on a bar during touch events.
 *  The color is automatically faded to transparent (vertically). The property showsVerticalSelection
 *  must be YES for the color to apply.
 *
 *  Default: white color (faded to transparent).
 *
 *  @param barChartView     The bar chart object requesting this information.
 *
 *  @return The color to be used on each bar selection.
 */
- (UIColor *)barSelectionColorForBarChartView:(JBBarChartView *)barChartView;

/**
 *  Horizontal padding between bars.
 *
 *  Default: 'best-guess' algorithm based on the the total number of bars and width of the chart.
 *
 *  @param barChartView     The bar chart object requesting this information.
 *
 *  @return Horizontal width (in pixels) between each bar.
 */
- (CGFloat)barPaddingForBarChartView:(JBBarChartView *)barChartView;

@end

@interface JBBarChartView : JBChartView

//These Two Lines Have The Error
@property (nonatomic, weak) id<JBBarChartViewDataSource> dataSource;
@property (nonatomic, weak) id<JBBarChartViewDelegate> delegate;
//.

/**
 *  Vertical highlight overlayed on bar during touch events.
 *
 *  Default: YES.
 */
@property (nonatomic, assign) BOOL showsVerticalSelection;

/*
 *  Bars can be (vertically) positoned top to bottom instead of bottom up.
 *  If this property is set to YES, both the bar and the selection view will be inverted.
 *  For the inverted orientation to take effect, reloadData must be called.
 *
 *  Default: NO.
 */
@property (nonatomic, assign, getter=isInverted) BOOL inverted;

@end
Mindy answered 20/5, 2015 at 0:7 Comment(2)
It sounds like you're are trying to declare a delegate property on a class when your superclass already has a property by that name. However it would be more helpful if you included the definition of the class you are trying to implement; the rest of us here have no idea what your super class is or what you are trying to accomplish with this property.Disorientate
just undoing the down voting SO jerks.Jacobo
J
11

You can use either explicitly synthesize or dynamic to fix this kind of warning. Here is the code:

@interface JBBarChartView : JBChartView

//These Two Lines Have The Error
@property (nonatomic, weak) id<JBBarChartViewDataSource, superclassDataSourceIfAvailable> dataSource;
@property (nonatomic, weak) id<JBBarChartViewDelegate, superclassDelegateIfAvailable> delegate;

@end

//MARK:dynamic
@implementation JBBarChartView
@dynamic dataSource;
@dynamic delegate;
@end

//MARK:explicitly synthesize
@implementation JBBarChartView
@synthesize dataSource;
@synthesize delegate;
@end

Check this doc to find more about clang

Jarvis answered 20/5, 2015 at 1:21 Comment(2)
Which lines do I implement this into the Objective-C file? Sorry, i'm fairly new to coding and mostly have experience with Swift, not Objective-C. @XiangfengMindy
@Mindy Swift is just a single file approach, however Objective-C being king of c family has both a header file and implementation file. I provide two solution separated by "//MARK",you can choose either, and put that in your JBBarChartView.m file. check this doc to find the syntax about class definition in Obj-CChristmann
D
1

If we look at JBChartView we can see that it already has a delegate (of type id<JBChartViewDelegate>) and dataSource (of type id<JBChartViewDataSource>). JBBarChartView here is attempting to redeclare those properties as conforming to more specific protocols. I think Overriding @property declarations in Objective-C has a nice answer to the same problem.

Disorientate answered 20/5, 2015 at 1:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.