Estou tentando invocar um método em uma classe Objective-C da Swift. É para um pod chamado BoString, e aqui está o trecho
- (BOStringAttribute *(^)(NSParagraphStyle *))paragraphStyle
{
return ^BOStringAttribute *(NSParagraphStyle *paragraphStyle) {
return self.attribute(NSParagraphStyleAttributeName, paragraphStyle);
};
}
No Swift, estou tentando invocar esse método, mas o compilador reclama se eu tentar passar algum parâmetro em paragraphstyle
let str = BOStringMaker()
str.paragraphStyle() // OK
//*** error
str.paragraphStyle({(ps) -> BOStringAttribute in
// logic here
})
No Objective-C, usei
BOStringMaker *make = [BOStringMaker alloc] init]
make.paragraphStyle(ps);
Mas eu sou incapaz de fazer o mesmo no Swift
Respostas:
1 para resposta № 1No rápido, você faz exatamente a mesma coisa. Você recebe o paragraphStyle
qual é o bloco / função e simplesmente invoque-o e passe-o ps
ou qualquer instância de NSParagraphStyle
você atualmente possui como parâmetro:
formatText.paragraphStyle()(ps)