ViewController 함수 호출

외부 class에서 ViewController의 함수를 직접 호출 할 수 없다.

Instance member cannot be used on type 'ViewController' 이런 오류 메세지를 내보낸다.

이럴때는 ViewController class의 내부에 class를 하나더 만들어서 호출한다.

ViewController 안에

class locationSign {

        func MonitorOn() {
            print(" ======= 모니터링 시작 =======")

            //ViewController 함수 호출 할때
            let VC = ViewController()
            VC.ViewController함수()

        }

        func MonitorOff() {
            print(" ======= 모니터링 종료 =======")
        }

    }

외부 class에서 호출은 다음과 같이.....

let ls = ViewController.locationSign()

ls.MonitorOn()

results matching ""

    No results matching ""