-
Notifications
You must be signed in to change notification settings - Fork 8
Code Convention
-
λ€μ¬μ°κΈ°μλ ν(tab)μ μ¬μ©ν©λλ€.
-
μ½λ‘ (
:)μ μΈ λμλ μ½λ‘ μ μ€λ₯Έμͺ½μλ§ κ³΅λ°±μ λ‘λλ€.let names: [String: String]?
-
ν¨μ μ μκ° μ΅λ κΈΈμ΄λ₯Ό μ΄κ³Όνλ κ²½μ°μλ μλμ κ°μ΄ μ€λ°κΏν©λλ€.
func collectionView( _ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath ) -> UICollectionViewCell { // doSomething() } func animationController( forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController ) -> UIViewControllerAnimatedTransitioning? { // doSomething() }
-
ν¨μ νΈμΆ μ½λκ° μ΅λ κΈΈμ΄λ₯Ό μ΄κ³Όνλ κ²½μ°μλ νλΌλ―Έν° μ΄λ¦μ κΈ°μ€μΌλ‘ μ€λ°κΏν©λλ€.
let actionSheet = UIActionSheet( title: "μ λ§ κ³μ μ μμ νμ€ κ±΄κ°μ?", delegate: self, cancelButtonTitle: "μ·¨μ", destructiveButtonTitle: "μμ ν΄μ£ΌμΈμ" )
-
if letΒ κ΅¬λ¬Έμ΄ κΈΈ κ²½μ°μλ μ€λ°κΏνκ³ ν μΉΈ λ€μ¬μλλ€.if let user = self.veryLongFunctionNameWhichReturnsOptionalUser(), let name = user.veryLongFunctionNameWhichReturnsOptionalName(), user.gender == .female { // ... }
-
guard letΒ κ΅¬λ¬Έμ΄ κΈΈ κ²½μ°μλ μ€λ°κΏνκ³ ν μΉΈ λ€μ¬μλλ€.ΒelseλΒguardμ κ°μ λ€μ¬μ°κΈ°λ₯Ό μ μ©ν©λλ€.guard let user = self.veryLongFunctionNameWhichReturnsOptionalUser(), let name = user.veryLongFunctionNameWhichReturnsOptionalName(), user.gender == .female else { return }
-
μΈμκ° μλ ν¨μμ μ°μμ νΈμΆμ κ°νμ νμ§ μλλ€.
someThing.firstFunc().secondFunc().End()
λ¨, SwiftUI Viewμ Modifierλ μμΈλ₯Ό λλ€.
``` swift Text("This is Text") .bold() .padding() ``` -
μΈμκ° μλ ν¨μμ νΈμΆκ³Ό νν ν΄λ‘μ κ° μλ κ²½μ°μ κ°νμ νλ€. λ¨, 첫λ²μ§Έ νΈμΆλλ μ½λμ λν΄μλ μμΈλ₯Ό λλ€.
// ex. 1 someThing.singleFunc(with: parameter) .secondFunc(with: someValue) .End(to: endValue) // ex. 2 someThing.map { $0 * 2 } .reduce(0) { result, intValue in result + intValue }
-
self,Selfν€μλμλ κ°νμ νμ§ μκ³ , μμ±ν©λλ€.self.myProperty.setting() Self.self
-
ν μ€μ μ΅λ 120μλ₯Ό λμ§ μμμΌ ν©λλ€.
- λ¨,
if let,guard letꡬ문μ μ΅λ 70μλ‘ μ ν
XcodeμΒ Preferences β Text Editing β Displayμ 'Page guide at column' μ΅μ μ νμ±ννκ³ 120μλ‘ μ€μ νλ©΄ νΈλ¦¬ν©λλ€.
- λ¨,
λͺ¨λ μν¬νΈλ μνλ²³ μμΌλ‘ μ λ ¬ν©λλ€.
λ΄μ₯ νλ μμν¬λ₯Ό λ¨Όμ μν¬νΈνκ³ , λΉ μ€λ‘ ꡬλΆνμ¬ μλνν° νλ μμν¬λ₯Ό μν¬νΈν©λλ€.
- ν΄λμ€ μ΄λ¦μλ UpperCamelCaseλ₯Ό μ¬μ©ν©λλ€.
- ν΄λμ€ μ΄λ¦μλ μ λμ¬λ₯Ό λΆμ΄μ§ μμ΅λλ€.
-
ν¨μ μ΄λ¦μλ lowerCamelCaseλ₯Ό μ¬μ©ν©λλ€.
-
ν¨μ μ΄λ¦ μμλ λλλ‘μ΄λ©΄Β
getμ λΆμ΄μ§ μμ΅λλ€.-
μ’μ μ:
func name(for user: User) -> String?
-
λμ μ:
func getName(for user: User) -> String?
-
-
Action ν¨μμ λ€μ΄λ°μ 'μ£Όμ΄ + λμ¬ + λͺ©μ μ΄' ννλ₯Ό μ¬μ©ν©λλ€.
- Tap(λλ λ€ λ)*μΒ
UIControlEventsμΒ.touchUpInsideμ λμνκ³ , *Press(λλ¦)*λΒ.touchDownμ λμν©λλ€. - will~μ νΉμ νμκ° μΌμ΄λκΈ° μ§μ μ΄κ³ ,Β did~λ νΉμ νμκ° μΌμ΄λ μ§νμ λλ€.
-
should~λ μΌλ°μ μΌλ‘Β
Boolμ λ°ννλ ν¨μμ μ¬μ©λ©λλ€.
μ’μ μ:
func backButtonDidTap() { // ... }
λμ μ:
func back() { // ... } func pressBack() { // ... }
- Tap(λλ λ€ λ)*μΒ
- λ³μ μ΄λ¦μλ lowerCamelCaseλ₯Ό μ¬μ©ν©λλ€.
-
μμ μ΄λ¦μλ lowerCamelCaseλ₯Ό μ¬μ©ν©λλ€.
μ’μ μ:
let maximumNumberOfLines = 3
λμ μ:
let MaximumNumberOfLines = 3 let MAX_LINES = 3
-
enumμ κ° caseμλ lowerCamelCaseλ₯Ό μ¬μ©ν©λλ€.
μ’μ μ:
enum Result { case .success case .failure }
λμ μ:
enum Result { case .Success case .Failure }
-
μ½μ΄λ‘ μμνλ κ²½μ° μλ¬Έμλ‘ νκΈ°νκ³ , κ·Έ μΈμ κ²½μ°μλ νμ λλ¬Έμλ‘ νκΈ°ν©λλ€.
μ’μ μ:
let userID: Int? let html: String? let websiteURL: URL? let urlString: String?
λμ μ:
let userId: Int? let HTML: String? let websiteUrl: NSURL? let URLString: String?
-
View, ViewModelμ ν΄λΉνλ κ°λ μ λμ View, ViewModelμ λΆμΈλ€.
ex) class SoundViewModel class SettingView
-
Modelμ ν΄λΉνλ κ°λ μ Modelμ λΆμ΄μ§ μκ³ , κ°λ κ·Έλλ‘λ₯Ό μ΄λ¦μΌλ‘ μ¬μ©νλ€.
ex) struct Sound struct PlayList
-
Singleton κ°μ²΄λ Manager, Controller, Service μ€ νλλ₯Ό λΆμΈλ€.
ex) enum NetworkManager struct AppController struct BackgroundSoundController class NotificationService
- ν΄λμ€μ ꡬ쑰체 λ΄λΆμμλΒ
selfλ₯Ό λͺ μμ μΌλ‘ μ¬μ©ν©λλ€. - λ΄μ₯ λΌμ΄λΈλ¬λ¦¬κ° μ‘΄μ¬νλ€λ©΄, λΆνμν μ΄κΈ°ν ν¨μλ₯Ό μ¬κ΅¬μ± νμ§ μμ΅λλ€.
let frame = CGRect(x: 0, y: 0, width: 100, height: 100)-
Array<T>μΒDictionary<T: U> 보λ€λΒ[T],Β[T: U]λ₯Ό μ¬μ©ν©λλ€.// μ’μ μ: var messages: [String]? var names: [Int: String]? // λμ μ: var messages: Array<String>? var names: Dictionary<Int, String>?
-
Int,Float,String,Boolνμ μ λ³μ/μμ μ μΈ μ, λͺ μνμ§ μμ΅λλ€.var isShowAnyView = false var referenceCount = 0
-
νλΌλ―Έν°μ λ¦¬ν΄ νμ μ΄ μλ Closure μ μμμλΒ
() -> Voidλ₯Ό μ¬μ©ν©λλ€.let completionBlock: (() -> Void)?
-
Closure μ μμ κ°ννμ¬ μ½λ λΈλμ μμ±ν©λλ€.
μ’μ μ
intArray.map { $0 * 2 }
λμμ
intArray.map { $0 * 2 }
-
Closure μΈμ μμ± μ, κ°λ₯ν κ²½μ° νμ μ μλ₯Ό μλ΅ν©λλ€.
intArray.map { $0 * 2 }
-
μΈμ λΌλ²¨μ μ μλ νμκ° μλ κΆμ₯μ¬νμ΄μ§λ§, Closure λ΄μ μ½λλΈλμ΄ 2μ€ μ΄μμΈ κ²½μ° λ°λμ λΌλ²¨μ μ¬μ©ν©λλ€.
intArray.map { intValue in let isOdd = (intValue % 2 == 1) return isOdd }
-
-
Closure μ μμ νλΌλ―Έν°μλ κ΄νΈλ₯Ό μ¬μ©νμ§ μμ΅λλ€.
{ operation, responseObject in // doSomething() }
-
Closure νΈμΆμ λ λ€λ₯Έ μ μΌν Closureλ₯Ό λ§μ§λ§ νλΌλ―Έν°λ‘ λ°λ κ²½μ°(νν ν΄λ‘μ ), νλΌλ―Έν° μ΄λ¦μ μλ΅ν©λλ€.
μ’μ μ:
UIView.animate(withDuration: 0.5) { // doSomething() }
λ¨, νλΌλ―Έν°μ νν ν΄λ‘μ κ° 2κ° μ΄μ μ‘΄μ¬νλ κ²½μ°μλ μλ λ κ°μ§ 쑰건μ μ€μν©λλ€.
- λͺ¨λ ν΄λ‘μ λ μΆμ½ ννμ μ¬μ©ν©λλ€.
- λλ²μ§Έ ν΄λ‘μ λΆν°λ μμ μλ ν΄λ‘μ μ λ
}μμ μ€λ°κΏμ νμ§ μκ³ λΌλ²¨μ νμν©λλ€.
// UIView.animate(withDuration: TimeInterval, animations: () -> Void, completion: ((Bool) -> Void)?) UIView.animate(withDuration: 0.25) { // doSomething() about animations } completion: { finished in // doSomething() } // SwiftUI Button Button { } label: { }
-
μμλ₯Ό μ μν λμλΒ
enumλ₯Ό λ§λ€μ΄ λΉμ·ν μμλΌλ¦¬ λͺ¨μλ‘λλ€. μ¬μ¬μ©μ±κ³Ό μ μ§λ³΄μ μΈ‘λ©΄μμ ν° ν₯μμ κ°μ Έμ΅λλ€.ΒstructΒ λμ Βenumμ μ¬μ©νλ μ΄μ λ, μμ±μκ° μ 곡λμ§ μλ μλ£νμ μ¬μ©νκΈ° μν΄μμ λλ€. -
λμ΄μ μμμ΄ λ°μνμ§ μλ ν΄λμ€λ νμΒ
finalΒ ν€μλλ‘ μ μΈν©λλ€. -
νλ‘ν μ½μ μ μ©ν λμλ extensionμ λ§λ€μ΄μ κ΄λ ¨λ λ©μλλ₯Ό λͺ¨μλ‘λλ€.
μ’μ μ
final class MyViewController: UIViewController { // ... } // MARK: UITableViewDataSource extension MyViewController: UITableViewDataSource { // ... } // MARK: UITableViewDelegate extension MyViewController: UITableViewDelegate { // ... }
λμ μ
final class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { // ... }