As I'm working through a test-driven development exercise to gain better understanding of how objects can be initialized and used I've run across a test case where I create an object such as a UITableView but I didn't have to use the init function of UITableView.
Here is a sample of the code:
import XCTest
@testable import PassionProject
class ItemListDataProviderTests: XCTestCase {
var sut: ItemListDataProvider!
var tableView: UITableView!
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
sut = ItemListDataProvider()
tableView = UITableView()
sut.itemManager = ItemManager()
tableView.dataSource = sut
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func tests_numberOfSectionsIsTwo(){
let numberOfSections = tableView.numberOfSections
XCTAssertEqual(numberOfSections, 2)
}
As I'm learning the swift language and OOP in general, I know initializers come in different flavors and I ASSUMED that in order to use an instance we will need to initialize it. However above I was able to create a UITableView instance and store it's memory inside a variable. I was even allowed to access it properties such as tableview.datasource.
I'd like to know am I correct in thinking that in order to use instance of any type of class, it must be initialized (if the stored properties aren't set by default)?
What did I just do in layman terms? Did I just allocate the memory?
Where I became confused is when reading Apple's documentation, this class has an initializer which I never had to use because I never set the frame or the style: init(frame: CGRect, style: UITableViewStyle)
Thanks in advance for commenting or answering.