iOS ์ฑ์์ RxSchoolMeal๋ฅผ ์ฌ์ฉํ๋ ค๋ฉด RxSchoolMeal ํ์ผ์ ์๋์ ๊ฐ์ด ์ํฌํธ(import)ํด์ผ ํฉ๋๋ค. ๋ํ ํ๊ต์ด๋ฆ์ ์ด์ฉํด RxSchoolMeal๋ฅผ ์ด๊ธฐํ ํ๋ ๊ณผ์ ์ด ํ์ํฉ๋๋ค. ๋ค์ ์์ ๋ฅผ ์ฐธ๊ณ ํ์ฌ AppDelegate.swift์ RxSchoolMeal๋ฅผ ์ด๊ธฐํํ๋ ์ฝ๋๋ฅผ ์ถ๊ฐํฉ๋๋ค.
import RxSchoolMeal
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
ใ
ค...
SchoolCommon.initSchool(schoolName: <#ํ๊ต์ด๋ฆ#>)
ใ
ค...
ใ
ค
}
๊ธ์ ์ ๋ณด๋ฅผ ๊ฐ์ ธ์ค๋ ์ฝ๋์ ๊ธฐ๋ณธ์ ์ธ ํํ์ ๋๋ค.
MEAL.getMeal(<#๋ ์ง#>, timePart: <#์์ฌ๊ตฌ๋ถ#>).subscribe(onSuccess: { meal in
print(meal)
})
.disposed(by: disposeBag)
- ์
<#๋ ์ง#>
๋ผ๊ณ ์์ฑ ๋์ด์๋ ๋ถ๋ถ์๋MealDate
๋ผ๋ ์ด๋ฆ์ผ๋ก ์ ์๋ enum์ ์ ๋ ฅํฉ๋๋ค.Raw Value Description .today
์ค๋์ ๋ํ๋ ๋๋ค. .anotherDate(date: Date)
์ํ๋ ๋ ์ง๋ฅผ Date ํ์ ์ผ๋ก ๋ฐ์ต๋๋ค. .plusMinusDay(day: Int)
์ค๋์ ๊ธฐ์ค์ผ๋ก ์กฐํํ๊ณ ์ถ์ ๋ ์ง๊ฐ ๋ช์ผ ํ์ธ์ง, ๋ช์ผ ์ ์ธ์ง๋ฅผ Intํ์์ผ๋ก ๋ฐ์ต๋๋ค. - ์
getMeal()
ํจ์๋timePart: <#์์ฌ๊ตฌ๋ถ#>
๋ถ๋ถ์ ์์ฑํ์ง ์์๋ ๋๋๋ก ์ค๋ฒ๋ก๋ฉ ๋์ด์์ต๋๋ค. ๋ง์ฝMealModel
๋ผ๋ ์ด๋ฆ์ผ๋ก ์ ์๋ struct๋ก ์์นจ, ์ ์ฌ, ์ ๋ ๋ฉ๋ด๋ฅผ ๋ชจ๋ ๋ฐ๊ณ ์ถ๋ค๋ฉด ์์ฑํ์ง ์์ผ์๋ฉด ๋ฉ๋๋ค. ํ์ง๋ง ์์นจ, ์ ์ฌ, ์ ๋ ์ค ํ๋๋ฅผ[String]
ํํ๋ก ๋ฐ์๋ณด๊ณ ์ถ๋ค๋ฉด ์์ฑํ์๋ฉด ๋ฉ๋๋ค. <#์์ฌ๊ตฌ๋ถ#>
๋ผ๊ณ ์์ฑ ๋์ด์๋ ๋ถ๋ถ์๋MealPartTime
์ด๋ผ๋ ์ด๋ฆ์ผ๋ก ์ ์๋ enum์ ์ ๋ ฅํฉ๋๋ค.Raw Value Description .breakfast
์์นจ๋ฐฅ ์ ๋๋ค. .lunch
์ ์ฌ๋ฐฅ ์ ๋๋ค. .dinner
์ ๋ ๋ฐฅ ์ ๋๋ค.
Examples
์๋ ์ธ ์์ ๋ ๋ชจ๋ ์ค๋์ ๊ธ์์ ์กฐํํฉ๋๋ค.
MEAL.getMeal(.today).subscribe(onSuccess: { meal in
print(meal)
}, onFailure: { err in
print(err)
})
.disposed(by: disposeBag)
MEAL.getMeal(.anotherDate(date: Date())).subscribe(onSuccess: { meal in
print(meal)
}, onFailure: { err in
print(err)
})
.disposed(by: disposeBag)
MEAL.getMeal(.plusMinusDay(day: 0)).subscribe(onSuccess: { meal in
print(meal)
}, onFailure: { err in
print(err)
})
.disposed(by: disposeBag)
์๋ ์์ ๋ ์ด์ ์ ๊ธ์์ค ์ ์ฌ๋ง ๊ฐ์ ธ์ค๋ ์์ ์ ๋๋ค.
MEAL.getMeal(.plusMinusDay(day: -1), timePart: .lunch).subscribe(onSuccess: { meal in
print(meal)
}, onFailure: { err in
print(err)
})
.disposed(by: disposeBag)
# Podfile
use_frameworks!
target 'YOUR_TARGET_NAME' do
pod 'RxSchoolMeal', '1.0.3'
end
Replace YOUR_TARGET_NAME
and then, in the Podfile
directory, type:
$ pod install
Add this to Cartfile
github "kimxwan0319/RxSchoolMeal" "1.0.3"
$ carthage update
// Package.swift
dependencies: [
.package(url: "https://github.com/kimxwan0319/RxSchoolMeal", from: "1.0.3")
]
semicolondsmkr, kimxwan0319@naver.com
RxSchoolMeal is available under the MIT license. See the LICENSE file for more info.