[英]cast of objective-c pointer type nsoutputstream* to c pointer type cfwritestreamref exception after __bridge
i am working on a project that t¨sends a photo with smtp . 我正在从事一个使用smtp发送照片的项目。 In the beginning automatic reference counting was disabled and the project was running without problems .
在开始自动引用计数被停用,该项目可以毫无问题地运行。 When i enabled automatic reference counting i got many compilation errors.
当我启用自动引用计数时,出现很多编译错误。 One of the most common was Cast of Objective-C pointer type 'NSOutputStream*' to C pointer type CFWriteStreamRef (aka 'struct_CFWriteStream*' requires a bridged cast) at the lines
最常见的一种是在行中将Objective-C指针类型'NSOutputStream *'转换为C指针类型CFWriteStreamRef(aka'struct_CFWriteStream *'需要桥接转换)
if (CFWriteStreamWriteFully(( CFWriteStreamRef)outputStream, (const uint8_t *)[ehlo
UTF8String], [ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0)
When i write if (CFWriteStreamWriteFully((__bridge CFWriteStreamRef)outputStream, (const uint8_t *) 当我写if(CFWriteStreamWriteFully((__ bridge CFWriteStreamRef)outputStream,(const uint8_t *)
[ehlo UTF8String], [ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0) [ehlo UTF8String],[ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding])<0)
it compiles but i get a runtime exception when i press the send button to send an email with smtp. 它可以编译,但是当我按下发送按钮以smtp发送电子邮件时,出现运行时异常。 I was wondering if you could help me with this problem.
我想知道您是否可以帮助我解决这个问题。 I would appreciate any help.
我将不胜感激任何帮助。 Thank you in advance, Best regards
预先谢谢您,最好的问候
How can you be sure it's a wrong typeCast? 您如何确定这是错误的typeCast? Try to keep the ownership of [ehlo UTF8String] as long as the stream is writing, maybe that can help
只要流正在写入,请尝试保留[ehlo UTF8String]的所有权,也许可以帮上忙
const UInt8 *buffer = (const UInt8 *)[ehlo UTF8String];
if (CFWriteStreamWriteFully(( CFWriteStreamRef)outputStream, buffer, [ehlo lengthOfBytesUsingEncoding:NSUTF8StringEncoding]) < 0)
By the way i haven't fount CFWriteStreamWriteFully() declaration anywhere. 顺便说一句,我还没有在任何地方提供CFWriteStreamWriteFully()声明。 Only CFIndex
只有CFIndex
CFWriteStreamWrite (
CFWriteStreamRef stream,
const UInt8 *buffer,
CFIndex bufferLength
);
Are there related? 有关系吗? UInt8 and uint8_t are both unsigned char.
UInt8和uint8_t都是无符号字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.