Closed Taehyeon-Kim closed 1 year ago
// Static Methods
static func notoSansR(_ size: CGFloat) -> UIFont {
return UIFont(.regular, size)
}
static func notoSansM(_ size: CGFloat) -> UIFont {
return UIFont(.medium, size)
}
func setLineHeight(_ lineHeight: CGFloat) {
if let text = self.text {
let attributedString = NSMutableAttributedString(string: text)
let style = NSMutableParagraphStyle()
style.maximumLineHeight = lineHeight
style.minimumLineHeight = lineHeight
attributedString.addAttribute(
NSAttributedString.Key.paragraphStyle,
value: style,
range: .init(location: 0, length: attributedString.length)
)
self.attributedText = attributedString
}
}
그동안 JSON을 주고 받는데에만 익숙해져있어서 나는 당연히 application/json 이 형태로 보내는 것이 당연하다고 생각했는데 application/x-www-form-urlencoded 방식으로 보내는 경우도 있었다.
주고 받는 데이터 형식이 달라지기에 post 요청시에도 신경을 써줘야하는 부분이었다. (그동안 너무 일차원적인 생각을 한 것이지..)
// body parameters
/// application/x-www-form-urlencoded
if let parameters,
let dicts = try parameters.toDictionary() {
let output = dicts.lazy
.map { ($0.key, $0.value) }
.map { "\($0)=\($1)"}
.joined(separator: "&")
let data = output.data(using: .utf8)
urlRequest.httpBody = data
}