์ด ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ Swift 3์์ ์ด๋ป๊ฒ ์ฌ์ฉํ ์ ์์ต๋๊น?
Objective-C ๋ธ๋ฆฌ์ง ํค๋๋ฅผ ์ถ๊ฐํ ๋ ๋๋กญํ๋ฉด ์๋ํฉ๋๋ค! :)
์ด๋ ์์ ์์ API ๋์์ธ์ ๊ฐ์ ํ์ฌ ๋ 'Swifty'ํ๊ฒ ๋ง๋ค ์ ์๋์ง ํ์ธํฉ๋๋ค.
cocoapods๋ฅผ ํตํด Swift 3 ํ๋ก์ ํธ์์ TOCropViewController๋ฅผ ์ฌ์ฉํ๊ณ ์๋๋ฐ ์ค๋ฅ ์์ด ์ ์๋ํฉ๋๋ค.
์ฐ๋ฆฌ๋ ๋น ๋ฅธ ๋ฒ์ ์ ๊ธฐ๋ํฉ๋๋ค # @akovalov :) :) :)
@osmanyildirim ๋ฌด๋ฃ ์คํ ์์ค ํ๋ก์ ํธ์ ๋ํด '๊ธฐ๋'ํ๋ ๊ฒ์ ์ค์ ๋ก ๋ถ๊ฐ๋ฅํฉ๋๋ค. ;)
๊ธฐ๋ณธ Swift 3 ์ง์์ด ์ ์คํ ํ์ํ ๊ฒฝ์ฐ ์ง์ ๊ตฌํํ์ญ์์ค. :NS
์ด ํ๋ก์ ํธ๋ Objective-C๋ก ์์ฑ๋์์ผ๋ฉฐ Swift 3 ๋๋ ๋ค๋ฅธ Swift ๋ฒ์ ์ฝ๋์์ ์ฌ์ฉํ๊ธฐ ์ํด ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ ํ์๊ฐ ์์ต๋๋ค. ํ๋ก์ ํธ. ๋ฐ๋ผ์ CocoaPods๋ฅผ ํตํด ์ฌ์ฉํ๋ ๊ฒฝ์ฐ Swift์ Readme์์ '๊ธฐ๋ณธ ๊ตฌํ' ์์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
import TOCropViewController
func presentCropViewController() {
let image: UIImage = ... // Load an image
let cropViewController = TOCropViewController(image: image)
cropViewController.delegate = self
present(cropViewController, animated: true, completion: nil)
}
func cropViewController(_ cropViewController: TOCropViewController!, didCropTo image: UIImage!, with cropRect: CGRect, angle: Int) {
// 'image' is the newly cropped version of the original image
}
์์ค๋ฅผ Swift ํ๋ก์ ํธ์ ๋ณต์ฌํ๋ ๊ฒฝ์ฐ https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html์์ 'Objective-C๋ฅผ Swift๋ก ๊ฐ์ ธ์ค๊ธฐ' ์น์ ์
๋๋ ์ด ํ๋ก์ ํธ์ ๋ ๋์ Swift ์ํธ ์ด์ฉ์ฑ์ ์ถ๊ฐํ๋ ๋ฐ ์ฝ๊ฐ์ ๋
ธ๋ ฅ์ ๊ธฐ์ธ์์ต๋๋ค. NS_SWIFT_NAME
์ฌ์ฉํ์ฌ ๋ฉ์๋ ์ด๋ฆ์ ์์ ํ ๋ฆฌํฉํ ๋งํ๋ ๊ฒ ์ธ์๋ ์ฐ๋ฆฌ๊ฐ ํ ์ ์๋ ๋งํผ๋ง ํ๋ฉด ๋๋ค๊ณ ์๊ฐํฉ๋๋ค.
Swift interop์ ๊ฐ์ ํ๋ ๋ฐ ํ์ํ ๋ค๋ฅธ ์ฌํญ์ด ์๊ฐ๋์๋ฉด PR์ ์ ์ถํ์ธ์. :)
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์ด ํ๋ก์ ํธ๋ Objective-C๋ก ์์ฑ๋์์ผ๋ฉฐ Swift 3 ๋๋ ๋ค๋ฅธ Swift ๋ฒ์ ์ฝ๋์์ ์ฌ์ฉํ๊ธฐ ์ํด ์ฝ๋๋ฅผ ๋ณ๊ฒฝํ ํ์๊ฐ ์์ต๋๋ค. ํ๋ก์ ํธ. ๋ฐ๋ผ์ CocoaPods๋ฅผ ํตํด ์ฌ์ฉํ๋ ๊ฒฝ์ฐ Swift์ Readme์์ '๊ธฐ๋ณธ ๊ตฌํ' ์์ ๋ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
์์ค๋ฅผ Swift ํ๋ก์ ํธ์ ๋ณต์ฌํ๋ ๊ฒฝ์ฐ https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/MixandMatch.html์์ 'Objective-C๋ฅผ Swift๋ก ๊ฐ์ ธ์ค๊ธฐ' ์น์ ์