Apple's Swift API Design Guidelines์ Ray Wenderlich Swift Style Guide๋ฅผ ๋ฐ๋ฅด๋ ๋ค์์ ์์ธ๋ก ํ๋ค.
-
๋จ์ํ
Boolean
๊ฐ์ ๋ณ๊ฒฝํ ๋๋ toggle()์ ์ฌ์ฉํ๋ค. -
if
,guard
๋ฌธ์ ์ฝค๋ง(,)๋ฅผ ์ด์ฉํด ์กฐ๊ฑด์ ์ถ๊ฐํ ๊ฒฝ์ฐ ์ฝค๋ง ๋ค์์ ๋ค์ ์ค๋ก ๋์ด๊ฐ๋ค.
// Bad
if results.isEmpty.not(), let delegate = seriesDelegate(byId: seriesId) {
books.append(delegate)
}
// Good
if results.isEmpty.not(),
let delegate = seriesDelegate(byId: seriesId) {
books.append(delegate)
}
if
,guard
๋ฌธ์ ์ฐ์์ ์ธlet
,var
๋ฅผ ์ ์ธํ ๋let
,var
๋ฅผ ์๋ตํ์ง ์๋๋ก ํ๋ค.
// Bad
if let userInfo = notification.userInfo,
bookId = userInfo["bookId"] as? String {
removeObject(forKey: bookId)
}
// Good
if let userInfo = notification.userInfo,
let bookId = userInfo["bookId"] as? String {
removeObject(forKey: bookId)
}
if
,guard
๋ฌธ์์&&
๋ ์ฝค๋ง๋ก ๋์ฒดํ๋ค.
// Bad
if book.isGrouped && book.seriesId != nil {
...
}
// Good
if book.isGrouped,
book.seriesId != nil {
...
}
-
์ฑ๊ธํค์
static let
์ ์ด์ฉํ๋ค. -
NS
์ ๋๊ฐ ๋ถ์ ํด๋์ค์ ์ฌ์ฉ์ ์ต๋ํ ์ง์ํ๋ค. -
Swift๊ฐ ObjC๋ก ๋ณํ๋๋ฉด์ ๋ ์ธ์ด๊ฐ ๋ค์ด๋ฐ ๊ท์น์ด ์ถฉ๋ํ ๊ฒฝ์ฐ Swift ๋ค์ด๋ฐ ๊ท์น์ ์ฐ์ ์ ํ๋ค.
// Swift์์ ๊ถ์ฅํ๋ ๋ค์ด๋ฐ
func removeUserShelf(at index: UInt)
// ์ ๋ฉ์๋๊ฐ xcbuild์ ์ํด ObjC๋ก ๋ณํ๋์ ๋์ ๋ค์ด๋ฐ
- (void)removeUserShelfAt:(NSUInteger)index;
// ObjC์์ ๊ถ์ฅํ๋ ๋ค์ด๋ฐ
- (void)removeUserShelfAtIndex:(NSUInteger)index;
Apple's Cocoa Coding Guidlines์ Google Objective-C Style Guide๋ฅผ ๋ฐ๋ฅด๋ ๋ค์์ ์์ธ๋ก ํ๋ค.
-
๋งคํฌ๋ก ์์ ์์
k
๋ฅผ ๋ถ์ด์ง ์๊ณ ๋๋ฌธ์์ ์ธ๋์ค์ฝ์ด(_
)๋ก ์ด๋ฃจ์ด์ง ์ด๋ฆ์ ์ฌ์ฉํ๋ค. -
Modern Objective-C Syntax๋ฅผ ์ฌ์ฉํ๋ค. (์ฃผ์ : nil์ด ์์ผ๋ฉด error)
NSArray *array = [[NSArray alloc] initWithObjects:@"value1", @"value2", nil];
NSArray *modernArray = @[@"value1", @"value2"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys:@"value1", @"key1", @"value2", @"key2", nil];
NSDictionary *modernDictionary = @{@"key1": @"value1", "key2": @"value2", ...};
NSNumber *number = [[NSNumber alloc] initWith...];
NSNumber *modernNumber = @5; // @.5, @1.5, @YES, @(4 + 2)
-
Tab Size๋ 4๋ก ํ๊ณ Space๋ฅผ ์ฌ์ฉํ๋ค.
-
Brace ๋ด ์ฝ๋๊ฐ ํ ์ค์ด๋๋ผ๋ Brace๋ก ๋ฐ๋์ ๊ฐ์ธ๋ ๊ฒ์ผ๋ก ํ๋ค.
if (condition) {
doSomething();
}
- ์์ค์ฝ๋ ์๋จ์ ์ ์๊ถ ๋ฐ ์ ์๋ฅผ ํ์ํ๋ ์ฃผ์์ ๋จ๊ธฐ์ง ์๋๋ค.
Swift API Design Guidelines์ Naming ์ฐธ๊ณ .
Apple's Cocoa Coding Guidlines์ Naming ํญ๋ชฉ๋ค ์ฐธ๊ณ .
- Asset ๋ช ์๋ UpperCamelCase๋ฅผ ์ฌ์ฉํ๋ค.
- Asset์ ํ์ผ๋ช ์ ๊ฐ๋ฅํ ๊ฒฝ์ฐ ์๋์ ๋ฆฌ๋ ๋ฆฌ์์ค ๋ค์ด๋ฐ์ ์ฌ์ฉํ๋ค.
- ์๋ฌธ์๋ง ์ฌ์ฉํ๋ค.
- ๊ณต๋ฐฑ์ ์ธ๋์ค์ฝ์ด(
_
)๋ก ๋์ฒดํ๋ค. - ์ ๋์ด์๋ ํด๋๋ช , ์ปดํฌ๋ํธ๋ช , ๋์์ธ ๊ณ ์ ๋ช ์ด ์๋ค.
- ๊ฐ ์ ๋์ด๋ ์ธ๋์ค์ฝ์ด๋ก ๊ตฌ๋ถ๋๋ค.
- ์ฌ๋ฌ ์ ๋์ด๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ 'ํด๋๋ช ', '์ปดํฌ๋ํธ๋ช ', '๋์์ธ ๊ณ ์ ๋ช ' ์์ผ๋ก ์ฌ์ฉํ๋ค.
- ํด๋๋ช
์ ๋ฆฌ์์ค๊ฐ ์ํ๋ ๋ทฐ๋ ๊ธฐ๋ฅ์ ์๋ฏธํ๋ค.
- share: ๋ฉ์ง๊ฒ ๊ณต์ ํ๊ธฐ ๋ฆฌ์์ค
- welcome: ์์ปด๋ทฐ ๋ฆฌ์์ค
- reader: ๋ทฐ์ด ๋ฆฌ์์ค
- ํด๋๋ช
์ ์์ ํด๋๋ช
๊น์ง ํฌํจํ๋ค.
- X) resources/reader/typo/*.png -> typo_xxx.png
- O) resources/reader/typo/*.png -> reader_typo_xxx.png
- O) resources/main/*.png -> main_xxx.png
- O) resources/*.png -> xxx.png
- ํด๋๋ช ์ด ์๋ ๊ฒฝ์ฐ๋ ๊ณต์ฉ ๋ฆฌ์์ค๋ฅผ ์๋ฏธํ๋ค.
- ํด๋๋ช ์ ์ธ๋์ค์ฝ์ด ์์ด ๋ถ์ฌ ์ด๋ค.
- ์ปดํฌ๋ํธ๋ช
์ HIG์์ ์ธ๊ธํ๋ UI Controls, UI Bars๋ฅผ ์งง๊ฒ ํํํ ๊ฒ์ด๋ค.
- navbar
- tabbar
- toolbar
- searchbar
- bar
- control
- btn
- switch
- stepper
- slider
- spinner
- ์ปดํฌ๋ํธ๋ช ๋ ์ธ๋์ค์ฝ์ด ์์ด ๋ถ์ฌ ์ด๋ค.
- ๋์์ธ ๊ณ ์ ๋ช
์ ์์ด์ฝ์ด๋ ๋ก๊ณ ์ ๊ฐ์ด ๋์์ธ์์ ํต์์ ์ผ๋ก ์ฐ์ด๋ ๊ณ ์ ๋ช
์ฌ์ด๋ค.
- icon
- logo
- bg
- ์ ๋ฏธ์ด์๋ ์์์ด๋ ํฌ๊ธฐ, ์์น, ์๋ฒ, ํ
๋ง, ์ํ๊ฐ ์๋ค.
- ์์: reader_color_black.png
- ํฌ๊ธฐ: welcome_logo_large.png
- ์์น: selection_arrow_left.png
- ์๋ฒ: customfont_tutorial_1.png
- ํ ๋ง: icon_pagination_left_d.png
- ์ํ: icon_freebook_on.png
- ์ ๋ฏธ์ด๋ ์ค์ฒฉํ ์ ์์ผ๋ฉฐ ์์๋ ์ฌ๋์ด๋ค.
- ํ
๋ง ์ ๋ฏธ์ด์๋ 'd'์ ์๋ต์ด ์๋ค.
- d: ๋คํฌ ํ ๋ง
- ์๋ต: ํ์ดํธ ํ ๋ง
- ์ํ ์ ๋ฏธ์ด์๋ ๋๋๋ก ๋ค์ ํญ๋ชฉ๋ง ์ฌ์ฉํ๋ค.
- normal
- highlighted
- X) pressed
- selected
- X) checked
- disabled
- on
- off
- ์ ํญ๋ชฉ๊ณผ ์ ์ฌํ ์๋ฏธ๊ฐ ์๋๋ผ๋ฉด ์ํ ์ ๋ฏธ์ด๋ก ์ธ ์ ์๋ค.
- bookmarked
- closed
- ์์๋ค
- main_searchbar_icon_clear_d.png
- main_tabbar_icon_settings.png
- main_library_btn_recent_list.png
- main_library_icon_download.png
- main_cloud_navbar_search.png
- reader_typo_btn_color_darkgray_selected.png
- reader_typo_stepper_plus.png
- reader_slider_thumb.png
- reader_bar_listen_label.png
- reader_rating_divider.png
- reader_tts_icon_arrow_up.png
- reader_shadow.png
- share_bg_10.jpg
- share_btn_sns_insta.png
- shortcut_icon_recent_book.png
- webview_bar_icon_refresh.png
- welcome_btn_login_highlighted.png
- welcome_logo_large.png
- ์ ๋ฏธ์ด์ orientaion, screenHeight, rate, interfaceIdiom์ด ์๋ค.
- ๊ฐ ์ ๋ฏธ์ด๋ ์ํฉ์ ๋ง์ถฐ ์ ํ์ ์ผ๋ก ์ฐ์ด๋ฉฐ ์ธ ๋๋ ์๋ง๋ ์ ๋์ด๋ฅผ ์ฌ์ฉํด์ผ ํ๋ค.
- -[orientaion]
- -[screenHeight]
- @[rate]
- ~[interfaceIdiom]
- ์ ๋ฏธ์ด๋ ์์์ ์ธ๊ธํ ์์๋๋ก ์ฌ์ฉ๋์ด์ผ ํ๋ค.
- X) name-[rate]-[orientaion]
- X) name-[interfaceIdiom]-[rate]
- O) name-[screenHeight]-[rate]
- orientaion์ ํน์ ํ์ ์ํ์๋ง ์ฐ์ผ ์ ์๋๋ก ํ๋ ์ ๋ฏธ์ด๋ค.
- name-Portrait.png // ์ธ๋ก ๋ชจ๋์์๋ง ์ฌ์ฉ
- name-Landscape.png // ๊ฐ๋ก ๋ชจ๋์์๋ง ์ฌ์ฉ
- name.png // ์๋ตํ์ ๋๋ ๋ชจ๋ ํ์ ์ํ์์ ์ฌ์ฉํจ์ ์๋ฏธ
- screenHeight๋ ์์ดํฐ ํฌ๊ธฐ๊ฐ ํํธํ๋๋ฉด์ ์๊ธด ๊ฒ์ผ๋ก ํน์ ํฌ๊ธฐ์๋ง ์ฐ์ผ ์ ์๋๋ก ํ๋ ์ ๋ฏธ์ด๋ค.
- name-568h.png // 3.5~4.0์ธ์น์์๋ง ์ฌ์ฉ
- name-667h.png // 4.7์ธ์น์์๋ง ์ฌ์ฉ
- name-736h.png // 5.5์ธ์น์์๋ง ์ฌ์ฉ
- name.png // ์๋ตํ์ ๋๋ ๋ชจ๋ ํฌ๊ธฐ์์ ์ฌ์ฉํจ์ ์๋ฏธ
- rate๋ ํน์ ํ๋ฉด ๋ฐฐ์จ์์ ์ฐ์ผ ์ ์๋๋ก ํ๋ ์ ๋ฏธ์ด๋ค.
- name@3x.png // 3x์์ ์ฌ์ฉ
- name@2x.png // 2x์์ ์ฌ์ฉ
- name.png // ์๋ตํ์ ๋๋ 1x์์ ์ฌ์ฉํจ์ ์๋ฏธ
- interfaceIdiom์ ํน์ ๋๋ฐ์ด์ค(iPhone/iPod, iPad)์์๋ง ์ฐ์ผ ์ ์๋๋ก ํ๋ ์ ๋ฏธ์ด๋ค.
- name~ipad.png // iPad์์๋ง ์ฌ์ฉ
- name~iphone.png // iPhone/iPod์์๋ง ์ฌ์ฉ
- name.png // ์๋ตํ์ ๋๋ ๋ชจ๋ ๋๋ฒ์ด์ค์์ ์ฌ์ฉํจ์ ์๋ฏธ
- ์์๋ค
- reader_paper_bg@2x.png
- memo_bg_2-Landscape@2x.png
- memo_bg_2-Landscape-667h@2x.png
- shelf_new_tag~ipad.png