F
F
FlooDwm2016-10-24 10:13:56
iOS
FlooDwm, 2016-10-24 10:13:56

Swift Classes Initialization Import - ?

Comrades, explain to an incomprehensible person in an intelligible language.
1) It is not necessary to import classes in Swift3, are they added themselves?
2) Why does this not work:
file test.swift

class Dog {
    func bark() {
        print("woof") // This is a comment
    }
}

ViewController.swift file
class ViewController: UIViewController {
    
 
    let kit = Dog()
    kit.bark()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2016-10-24
@alexyat

I have not dealt with Swift yet, but it seems to me that

let kit = Dog()
    kit.bark()

you need to put in func viewDidLoad ()
and of course initialize the ViewController itself

D
Dmitry Donkovtsev, 2016-10-24
@Demetriy

Within the application code, classes do not need to be imported, because they are all considered inside the same module, so they see each other, but if you add another application to yours, then you already need to do import.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question