ํฌ์คํธ ๊ธฐ๋ฅ์ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ด๊ฐ๋ฐ๋ ๊ฒฐ๊ณผ๋ "failure(SwiftyInsta.GenericError.weakObjectReleased)"์ ๋๋ค.
๋ด๊ฐ ๋ญ ์๋ชปํ๊ณ ์์ฃ ? ์ด๊ฒ์ด ๋จ์ํ ์ค์๋ผ๋ฉด ์ฌ๊ณผ๋๋ฆฝ๋๋ค. ๋๋ ์ฌ๊ธฐ์์ ๋ชจ๋ ์ง๋ฌธ์ ๊ฒ์ํ๊ณ ์ด๊ฒ์ ๋ด๊ฐ ์ป์ ํ, ์ปดํ์ผํ์ง๋ง ํด๋น ์ค๋ฅ๋ฅผ ๋ฐํํฉ๋๋ค.
func uploadImage() {
let img = imageView.image!
let myCaption = "Sample Caption"
guard let key = UserDefaults.standard.string(forKey: "current.account") else { return print("`key` not found.") }
guard let cache = Authentication.Response.persisted(with: key) else { return print("`Authentication.Response` not found.") }
let handler = APIHandler()
handler.authenticate(with: .cache(cache)) { _ in
let img1: Upload.Picture = Upload.Picture(image: img, caption: myCaption, size: CGSize(width: 30,height: 30) )
handler.media.upload(photo: img1, completionHandler: { (result) in
print(result)
})
}
}
SwiftyInsta.GenericError.weakObjectReleased
๋ ์ผ๋ฐ์ ์ผ๋ก APIHandler
๊ฐ ๊ฐ๋ ฅํ๊ฒ ์ฐธ์กฐ๋์ง ์์ ๋ ํธ์ถ๋ฉ๋๋ค.
๊ทํ์ ์๊ฐ ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ ์๋ฏธํ๋ ๊ฒฝ์ฐ:
func someFunction(cache: Authentication.Response) {
let handler = APIHandler()
handler.authenticate(with: .cache(cache)) { _ in
}
}
์๋ฃ ํธ๋ค๋ฌ๊ฐ ํธ์ถ๋๋ฉด ๋น๋๊ธฐ์ ์ผ๋ก handler
๊ฐ ์ด๋ฏธ ํด์ ๋์์ต๋๋ค.
์ด๊ฒ์ด ์๋ํ๋ ค๋ฉด ์ด๋๊ฐ์ "์ง์"ํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด.
class SomeClass {
let handler = APIHandler()
func someFunction(cache: Authentication.Response) {
handler.authenticate(with: .cache(cache)) { _ in }
}
}
handler
๋ SomeClass
์ธ์คํด์ค๊ฐ ํ ๋น๋ ๋๊น์ง ํ ๋น ํด์ ๋์ง ์์์ ์๋ฏธํฉ๋๋ค.
๊ฐ์ฌํฉ๋๋ค. ์ด์ "failure(SwiftyInsta.GenericError.custom("Invalid response. 400"))"์ด ํ์๋ฉ๋๋ค. ์ด๊ฒ์ ๋ด viewController์ ๋๋ค. ์ด ์ค๋ฅ์ ๋ํ ๋ด ์ค๋ฅ๋ฅผ ๋ณด์ฌ์ฃผ์๊ฒ ์ต๋๊น ์๋๋ฉด ์ด๋ฏธ์ง๋ฅผ ๊ฒ์ํ๋ ์์ ๊ธฐ๋ฅ์ด ์๋ ๊ฒฝ์ฐ ์ ์๊ฒ ์์ฒญ๋ ๋์์ด ๋ ์๋ผ์ ๋ถ์ฌ๋ฃ์ ์ ์์ต๋๋ค.
import UIKit
import SwiftyInsta
class DeploymentViewController: UIViewController {
let handler = APIHandler()
<strong i="6">@IBOutlet</strong> weak var sampleImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
}
<strong i="7">@IBAction</strong> func test(_ sender: Any) {
guard let key = UserDefaults.standard.string(forKey: "current.account") else { return
print("`key` not found.") }
guard let cache = Authentication.Response.persisted(with: key) else { return
print("`Authentication.Response` not found.") }
handler.authenticate(with: .cache(cache)) { _ in }
let img1: Upload.Picture = Upload.Picture(image: self.sampleImage.image!, caption:
"sampleText", size: CGSize(width: 1080,height: 1080) )
self.handler.media.upload(photo: img1, completionHandler: { (result) in
print(result)
}) }
}
๊ทํ์ ์ ์์ธ์ ๋ํ ์ ๋ฌธ์ ๋ฅผ ์ด์์ต๋๋ค.
์๊ฐ๋๋๋๋ก ๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค :muscle: @trentona
์ง๊ธ๋ถํฐ #106์ ์ฐธ์กฐํ์ญ์์ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
SwiftyInsta.GenericError.weakObjectReleased
๋ ์ผ๋ฐ์ ์ผ๋กAPIHandler
๊ฐ ๊ฐ๋ ฅํ๊ฒ ์ฐธ์กฐ๋์ง ์์ ๋ ํธ์ถ๋ฉ๋๋ค.๊ทํ์ ์๊ฐ ๋ค์๊ณผ ๊ฐ์ ๊ฒ์ ์๋ฏธํ๋ ๊ฒฝ์ฐ:
์๋ฃ ํธ๋ค๋ฌ๊ฐ ํธ์ถ๋๋ฉด ๋น๋๊ธฐ์ ์ผ๋ก
handler
๊ฐ ์ด๋ฏธ ํด์ ๋์์ต๋๋ค.์ด๊ฒ์ด ์๋ํ๋ ค๋ฉด ์ด๋๊ฐ์ "์ง์"ํด์ผ ํฉ๋๋ค. ์๋ฅผ ๋ค์ด.
handler
๋SomeClass
์ธ์คํด์ค๊ฐ ํ ๋น๋ ๋๊น์ง ํ ๋น ํด์ ๋์ง ์์์ ์๋ฏธํฉ๋๋ค.