I have a class that contains data about some entrepreneurs in a separate fast file that is part of the same project.
It looks like this:
class Entrepreneur:NSObject {
var name:String?
var netWorth = (0.0, "")
var company:String?
var summary: [String]
var age: Int?
override init() {
name = ""
company = ""
summary = [""]
age = 1;
}
In the same file, I have a function that returns an NSMutableArray that contains instances of the entrepreneur class as follows:
func populateArray() -> NSMutableArray {
var entreprenuersArray: NSMutableArray = []
let markZuckerBerg = Entrepreneur()
markZuckerBerg.name = "Mark Zuckerberg"
markZuckerBerg.age = 19
markZuckerBerg.company = "Facebook"
markZuckerBerg.netWorth = (35.7, "Billion")
entreprenuersArray.addObject(markZuckerBerg)
print (entreprenuersArray)
in my ViewController.swift file . I create a constant called entrepreneurs, and give it the type of the Entrepreneur class created above and initialize it as follows:
let entrepreneuerss:Entrepreneur = Entrepreneur()
Then I access one method of the class, the "populateArray" function, and try to print an array of entrepreneurs as follows:
entrepreneuerss.populateArray()
print (entrepreneuerss)
, , ... - :. : 0x7f88d0e3ecc0 > "
, , . ViewController.swift .