Swift - How to use SDataGridDataSourceHelper



I am having trouble getting SDataGridDataSourceHelper to work in Swift

I add SDataGridDataSourceHelperDelegate to my controller class

class GradingController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate, SDataGridDataSourceHelperDelegate {

and I created my grid and added SDataGridDataSourceHelper in my viewDidLoad:

let grid = ShinobiDataGrid(frame: self.view.bounds)
        grid?.numberOfFrozenColumns = 1
        grid?.defaultCellStyleForHeaderRow.font = UIFont (name: "Helvetica Neue", size: 18)
        let lots = SDataGridColumn(title: "Lot")
        lots?.propertyKey = "lot"
        let columnA = SDataGridColumn(title: "Column A")
        columnA?.propertyKey = "columnA"
        let columnB = SDataGridColumn(title: "Column B")
        columnB?.propertyKey = "columnB"
        let columnC = SDataGridColumn(title: "Column C")
        columnC?.propertyKey = "columnC"
        let cameraColumn = SDataGridColumn(title: "")
        cameraColumn?.propertyKey = "cameraColumn"
        let helper = SDataGridDataSourceHelper(dataGrid: grid!)
        helper?.delegate = self
        var array = [DataObject.init(fromString: "lot", columnA: "colum a", columnB: "colum b", columnC: "colum c", cameraColumn: "camera")] as Array

        array.append(DataObject.init(fromString: "lot", columnA: "colum a", columnB: "colum b", columnC: "colum c", cameraColumn: "camera"))

        helper?.data = array

Added this method:

func dataGridDataSourceHelper(_ helper: SDataGridDataSourceHelper!, populateCell cell: SDataGridCell!, withValue value: Any!, forProperty propertyKey: String!, sourceObject object: Any!) -> Bool {
        return false

and here is my DataObject:

class DataObject : NSObject

    @objc var lot: String
    @objc var columnA: String
    @objc var columnB: String
    @objc var columnC: String
    @objc var cameraColumn: String

    init(fromString lot: String, columnA: String, columnB: String, columnC: String, cameraColumn: String) {
        self.lot = lot
        self.columnA = columnA
        self.columnB = columnB
        self.columnC = columnC
        self.cameraColumn = cameraColumn

But I get this error: > [SDataGridDataSourceHelper respondsToSelector:]: message sent to deallocated instance

What am I doing wrong? Are there any examples for Swift for SDataGridDataSourceHelper?


Hi jsuske,

It looks like the issue is that you’re not holding on to your SDataGridDataSourceHelper instance. This means that when viewDidLoad exits, the helper is thrown away, so when the grid asks for its data, it tries to call a method on the deallocated instance of the helper.

If you create an instance property to hold your helper, it should work as expected.

Kind regards,



That worked! Thank you very much!