Classes and objects
Create a class:
class TheClass
{
var firstvar: Int
//making the constructor
//placed after properties
init (firstvar: Int)
{
self.firstvar = firstvar
}
func getFirstVar()
{
return self.firstvar
//self means this current class
}
}
instantiating the class:
var theClass = TheClass(firstvar: 100)
calling a function in the class:
var fv = theClass.getFirstVar()
class TheClass
{
var firstvar: Int
//making the constructor
//placed after properties
init (firstvar: Int)
{
self.firstvar = firstvar
}
func getFirstVar()
{
return self.firstvar
//self means this current class
}
}
instantiating the class:
var theClass = TheClass(firstvar: 100)
calling a function in the class:
var fv = theClass.getFirstVar()
Comments
Post a Comment