缩进Swift代码

缩进只是个人喜好。 最好是遵循团队中使用的约定。 这是我缩进代码的方式。 让我知道你的想法😉

使用2个空格缩进

尽可能将编辑器配置为使用2 spaces作为tab size 。 你会喜欢它的❤️

将第一个参数移到新行

如果参数很多,请将第一个参数移到新行,然后对齐其他参数。 请记住,最后一个括号)应该与函数调用对齐

  let event = NSAppleEventDescriptor( 
eventClass:UInt32(kASAppleScriptSuite),
eventID:UInt32(kASSubroutineEvent),
targetDescriptor:目标,
returnID:Int16(kAutoGenerateReturnID),
transactionID:Int32(kAnyTransactionID)

您可以对函数声明执行相同的操作

  func collectionView( 
_ collectionView:UICollectionView,
viewForSupplementaryElementOfKind类型:字符串,
在indexPath:IndexPath)-> UICollectionReusableView {
//您的代码在这里
}

如果闭包超过2个,则不应使用结尾闭包

这是如何使用UIView.animate

  UIView.animate( 
withDuration:5
延误:5
usingSpringWithDamping:1,
initialSpringVelocity:1
选项:.curveEaseIn,
动画:{
self.tableView.alpha = 1
},
完成:{_
self.view.isHidden = true
}

这是使用RxSwift subscribe

  friendsObservable.subscribe( 
onNext:{个朋友
  }, 
onError:{错误
  }, 
onCompleted:{
  }, 
onDisposed:{
  } 

链接方法时不应使用结尾闭包

另外,下一个方法调用应从同一行开始

 让项目= [1,2,3,4,5] 
让结果= items.map({
返回字符串($ 0)
})。flatMap({
返回Int($ 0)
})。过滤({
返回$ 0> 2
} .sorted()