NSTextAlignment:无法从 objective-c 转换为 swift

NSTextAlignment: can't translate from objective-c to swift

我对自己很失望,但我无法将这段代码从 objective-c 翻译成 swift。 :-(

有人可以帮助我吗?我不知道,发现 nothing 和 Google。经过几个小时的沮丧,我请求你的帮助 ;-)

objective-c——代码:(看起来很简单[grrrrr])

-(void)setParagraphAlignment:(NSTextAlignment)newAlignment{
    NSRange selectedRange = [_textView selectedRange];
    NSMutableParagraphStyle *newParagraphStyle = [[NSMutableParagraphStyle alloc] init];
    [newParagraphStyle setAlignment:newAlignment];

    NSDictionary *dict = @{NSParagraphStyleAttributeName: newParagraphStyle};
    [textView.textStorage beginEditing];
    [textView.textStorage setAttributes:dict range:selectedRange];
    [textView.textStorage endEditing];
}

我唯一可以转换的行是 ;-(

textView.textStorage .beginEditing()
textView.textStorage .endEditing()
func selectParagraphAlignment(newAlignment:NSTextAlignment) {
    var selectedRange = textView.selectedRange
    var newParagraphStyle = NSMutableParagraphStyle()
    newParagraphStyle.alignment = newAlignment

    var dict = [NSParagraphStyleAttributeName: newParagraphStyle]
    textView.textStorage.beginEditing()
    textView.textStorage.setAttributes(dict, range: selectedRange)
    textView.textStorage.endEditing()

}

希望对您有所帮助 :D