How to override the lazy load dataArr by swift in the new swift file?

WP Scriptor Forums Programmer How to override the lazy load dataArr by swift in the new swift file?

Tagged: 

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #357
    Osama Aslam
    Participant

    I am learning Swift.
    I create the first swift file in my iOS APP project.
    The swift file is a subclass. The swift father class is ao objective-c class.
    In the objective-c file.m, I use a lazy array;

    like this:

    - (NSArray *)dataArr{
    if(_dataArr == nil){
    NSDictionary *dic1 = @{@"title":@"dog1",
    @"message":@"the dog1"
    };
    NSDictionary *dic2 = @{@"title":@"dog2",
    @"message":@"the dog2"
    };
    NSDictionary *dic3 = @{@"title":@"dog3",
    @"message":@"the dog3"
    };
    _dataArr = @[dic1, dic2, dic3];
    }
    return _dataArr;
    }

    In the OC file, I use the dataArr to set the tableView contents.

    Due to my new swift file is like the OC father file, except the array content.

    I want the override the array to make the swift file table view show the new content.

    My swift file code like this:

    class testSwift: theOCFatherClass {

    override func viewDidLoad() {

    let dic1:Dictionary = ["title":"dog1",
    "message":"the dog1"
    ];
    let dic2:Dictionary = ["title":"dog2",
    "message":"the dog2"
    ];
    let dic3:Dictionary = ["title":"dog3",
    "message":"the dog3"]

    func getdataArray() -> Array<Any>{
    return [dic1, dic2, dic3]
    }

    var dataArr = getdataArray()

    super.viewDidLoad()
    }
    }

    I click into the swift page on my iPhone, the content of the swift file is my OC array.

    My question is how to override the dataArr by swift in the new swift file.

    If you will, please write a good example.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.