You should set paragraphStyle.spacing = 0
for first line then paragraphStyle.spacing = 20
and paragraphStyle.spacing = 0
for the third line. So basically spacing changes the space after the line it was set for not before.
let line1 = NSMutableAttributedString(string: "Test first line\n")
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.spacing = 0
attrStr.setAttributes([.paragraphStyle: paragraphStyle,
.font: UIFont.systemFont(ofSize: 15, weight: .regular),
.foregroundColor: UIColor.black],
range: NSMakeRange(0, line1))
let line2 = NSMutableAttributedString(string: "Test new line.\n")
let paragraphStyle2 = NSMutableParagraphStyle()
paragraphStyle2.lineSpacing = 20
line2.setAttributes([.paragraphStyle: paragraphStyle2,
.font: UIFont.systemFont(ofSize: 15, weight: .regular),
.foregroundColor: UIColor.black],
range: NSMakeRange(0, line2.string.count))
let line3 = NSMutableAttributedString(string: "Test new paragraph")
let paragraphStyle3 = NSMutableParagraphStyle()
paragraphStyle3.spacing = 0
line3.setAttributes([.paragraphStyle: paragraphStyle3,
.font: UIFont.systemFont(ofSize: 15, weight: .regular),
.foregroundColor: UIColor.black],
range: NSMakeRange(0, line3.string.count))
line1.append(line2)
line1.append(line3)
textView.attributedText = line1