Swift application that needs properties for ShinobiChart and ShinobiGrid in ViewController for use outside viewDidLoad method


#1

Hello, 

In Objective-C I can create properties on my ViewController

@interfaceViewController () 

@property (nonatomic,strong)ShinobiDataGrid* shinobiDataGrid;

@property (nonatomic,strong)ShinobiChart* shinobiChart;

@end

and initialize them in viewDidLoad() as in your examples.  This way I can use the properties to access them outside the viewDidLoad method.

In Swift:  when I try to declare properties:

var chart : ShinobiChart

var datagrid : ShinobiDataGrid

I get errors that they need to be initialized with a frame.  So I tried,

    @IBOutlet weak var topView: UIView!

    @IBOutlet weak var bottomView: UIView!

    var chart : ShinobiChart

    var datagrid : ShinobiDataGrid

    

    required init(coder aDecoder: NSCoder)

    {

        chart = ShinobiChart(frame: CGRectInset(topView.bounds, 15, 15))

        datagrid = ShinobiDataGrid(frame: CGRectInset(bottomView.bounds, 15, 15))

        super.init(coder: aDecoder)

    }

This builds but at runtime it crashes since topView and bottomView are nil until viewDidLoad.

Any ideas of how I can have properties for the grid and the chart in the ViewController for use outside the viewDidLoad method?


#2

Hi rcroteau0,

I would set your top and bottom view variables to reference your chart and datagrid - this is more of a swift question than a question related to a Shinobi control though - you might find it easier to ask on a swift related forum :slight_smile:

Kind regards,

Rob