Q:

UIPickerView is not populating

Hails,
I'm challenging to write clean code. Therefore i want to keep my datasource and deletegate in seperate class files and extensions. So want to keep closer to M-V-C style. Therefore my model is seperated from all my controller classes and view classes. But there is a problem with populating the pickerView object. Here is the code;
//My Delegate and Datasource
    import Foundation
    import UIKit
class MyPickerView: NSObject{
var data = PickerViewData.getData()

}
extension MyPickerView: UIPickerViewDataSource{
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
    return 1
}

func numberOfComponents(in pickerView: UIPickerView) -> Int {
    return self.data.count
}    
}

extension MyPickerView: UIPickerViewDelegate{
func pickerView(_ pickerView: UIPickerView, rowHeightForComponent 
component: Int) -> CGFloat {
    return 100
}

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, 
forComponent component: Int, reusing view: UIView?) -> UIView {

    let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    let dayLbl = UILabel(frame: CGRect(x: 0, y: 10, width: 100, height: 15))
    let priceLbl = UILabel(frame: CGRect(x: 0, y: 0, width: 100, height: 100))
    let petLbl = UILabel(frame: CGRect(x: 0, y: 78, width: 100, height: 15))
    dayLbl.text = data[row].dayName
    priceLbl.text = String(data[row].price)
    petLbl.text = data[row].petName

    dayLbl.textAlignment = .center
    priceLbl.textAlignment = .center
    petLbl.textAlignment = .center
    view.addSubview(dayLbl)
    view.addSubview(priceLbl)
    view.addSubview(petLbl)
    return view
}

}
//My Model
import Foundation

struct PickerViewModel{
var dayName:String!
var price:Double!
var petName:String!
init(dayName:String,price:Double,petName:String) {
    self.dayName = dayName
    self.price = price
    self.petName = petName
}

}
struct PickerViewData {
static func getData() -> [PickerViewModel]{
    let m = PickerViewModel(dayName: "Pazartesi", price: 32.3, 
petName: "Köpek")
    let p = PickerViewModel(dayName: "Salı", price: 32.3, petName: 
"Kuş")
    let z = PickerViewModel(dayName: "Çarşamba", price: 32.3, 
petName: "Kedi")
    let t = PickerViewModel(dayName: "Perşembe", price: 32.3, 
petName: "Domuz")
    let k = PickerViewModel(dayName: "Cuma", price: 32.3, petName: 
"Kanarya")
    return [m,p,z,t,k]
}
}

//My Controller
import UIKit

class FirstVC: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    self.view.backgroundColor = .white
    let pickerView = UIPickerView(frame: CGRect(x: 100, y: 100, 
width: 200, height: 500))
    let deldat = MyPickerView()
    pickerView.delegate = deldat
    pickerView.dataSource = deldat
    self.view.addSubview(pickerView)
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}    

} 

A:

The picker view's dataSource and delegate properties are declared as weak - this means that they don't retain your MyPickerView instance. Since your instance is a local variable, as soon as viewDidLoad exits, it will be released.
You need to hold your MyPickerView instance in an instance property, so that it is retained for the lifetime of your view controller:
import UIKit

class FirstVC: UIViewController {

    private var deldat: MyPickerView!

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = .white
        let pickerView = UIPickerView(frame: CGRect(x: 100, y: 100, 
width: 200, height: 500))
        self.deldat = MyPickerView()
        pickerView.delegate = deldat
        pickerView.dataSource = deldat
        self.view.addSubview(pickerView)
    }
}

