0
네트워크 관리자 클래스 (싱글 톤)가 있습니다.클래스의 모든 기능에서 동일한 코드를 호출하십시오.
응용 프로그램이 만들어야하는 모든 API 호출에 대해이 네트워크 관리자와 다른 기능이 호출됩니다.
이 NM의 모든 기능은 각 기능의 완료 처리기에 도달 할 때까지 활동 표시기를 표시함으로써 시작됩니다. 사용자에게 요청이 수행되고 있음을 보여줍니다.
어떻게 할 수 있습니까?
Alamofire 포드가 도움이 될 수 있다면 사용하고 있습니다.
func loadSetting(for user: String, completionHandler: (UserSetting?) ->()) {
myActivityIndicator.start //a line I'd like to perform in every function of this class
let parameters = ["UUID": user]
_ = Alamofire.request(.POST, "http://www.google.com/users", parameters: parameters)
.responseObject { (response: Response<UserSetting, NSError>) in
if let userSetting = response.result.value {
print("User Setting found remotely")
completionHandler(userSetting)
} else {
print("Couldn't fetch remote User Setting")
completionHandler(nil)
}
myActivityIndicator.stop //a line I'd like to perform in every function of this class
}
}
감사 : 여기
내 API 호출 중 하나의 예이다.
하나의 솔루션은 모든 예를 들어 기능 요청에서 NetworkManager의 요청을 처리 할 수 있으며 그 안에는 활동 표시기를 처리 할 수 있습니다. –
예, 해결책이 될 수 있습니다. Victor에게 감사드립니다. 그런 다음 각 요청 (요청 유형, URL, 매개 변수, 파일 ...)을 전달하기 위해 많은 매개 변수를 전달해야합니다. 그렇지 않습니까? – Tulleb
예. 실제로 Alamofire가하는 것처럼 기본 선택 값으로 정의 할 수 있습니다. –