简体   繁体   中英

How to use a class category Objective C in Swift?

I have a class category wrote in Objective C. I need use this in Swift. But I don't know how to declare this to call.

      var vcfPart: NSDictionary = [kSKPSMTPPartContentTypeKey:"video/quicktime;\r\n\tx-unix-mode=0644;\r\n\tname=\"video.mp4\"", kSKPSMTPPartContentTypeKey:"attachment;\r\n\tfilename=\"video.mp4\"", kSKPSMTPPartContentDispositionKey: self.rep ,kSKPSMTPPartMessageKey:"base64", kSKPSMTPPartContentTransferEncodingKey: "8bit"]

data is of type NSData. I need encode this with NSData+Base64Additions https://github.com/kailoa/iphone-smtp/blob/master/Classes/NSData%2BBase64Additions.m

in objective c call:

 NSDictionary * vcfPart3 = [NSDictionary dictionaryWithObjectsAndKeys:@"video/quicktime;\r\n\tx-unix-mode=0644;\r\n\tname=\"video.mp4\"",kSKPSMTPPartContentTypeKey,
                           @"attachment;\r\n\tfilename=\"video.mp4\"",kSKPSMTPPartContentDispositionKey, [data encodeWrappedBase64ForData], kSKPSMTPPartMessageKey, @"base64", kSKPSMTPPartContentTransferEncodingKey, nil];

I don't know how to declare this in Swift with an extension..

How can use this in Swift?

Thanks!

Extensions can't contain stored properties, as I'm sure the compiler has already informed you. If this is actually a constant, express it as a computed property and you'll be fine.

In other words, this is illegal in an extension:

let i = 4

But this is legal:

var i : Int {
    return 4
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM