Reputation: 265
Surprisingly, I'm having trouble searching for this. How do I place assisting classes in separate files in Swift? If I want to store an addition function in a separate math class in the same file, I can call math.add(), but if I want to store the class and function it in a math.swift file and reference it from the main file, what would I use?
Upvotes: 3
Views: 4753
Reputation: 19954
If you're simply looking to make a new file with your class and call it from main (or viewDidLoad). You can do the following.
Math.swift
import UIKit
class Math {
func add(param:Int, param: Int) {
//... your implementation
}
}
Then in main (or viewDidLoad) create an instance of your math class:
var myMathClass = Math()
then call your function:
myMathClass.add(5, 5) // you've called your function
There are quite a few different options. If you share some code and clarify your question I can help you better.
Upvotes: 2