首页 \ 问答 \ 将NSData复制到UnsafeMutablePointer (copy NSData to UnsafeMutablePointer)

将NSData复制到UnsafeMutablePointer (copy NSData to UnsafeMutablePointer)

你好stackoverflowers。 我正在实现一个安全传输的包装器,我坚持使用一些C - > Swift语法。

func sslReadCallback(connection: SSLConnectionRef,
    data: UnsafeMutablePointer<Void>,
    var dataLength: UnsafeMutablePointer<Int>) -> OSStatus
{
    //let bytesRequested = dataLength.memory
    let transportWrapper:SecureTransportWrapper = UnsafePointer(connection).memory
    let bytesRead:NSData = transportWrapper.readFromConnectionFunc(transportWrapper.connection)

    dataLength = UnsafeMutablePointer<Int>.alloc(1)
    dataLength.initialize(bytesRead.length)

    if (bytesRead.length == 0)
    {
        return OSStatus(errSSLClosedGraceful)
    }
    else
    {
        data.alloc(sizeof(bytesRead.length)) //<----compile error here
        return noErr
    }
}

我已经标记了编译错误的位置。 我不怪错误,我在这里猜测:P。 我正在尝试将NSData复制到数据:UnsafeMutablePointer。 我怎么做?

编译错误:

/Users/*/SecureTransportWrapper.swift:108:9:静态成员'alloc'不能用于'UnsafeMutablePointer'类型的实例(又名'UnsafeMutablePointer <()>')

万分感谢!

================

更新:这是sslReadCallback应该做的api文档:

连接:连接参考。

data:返回时,您的回调应该使用从连接读取的数据覆盖此位置的内存。

dataLength:输入时,指向表示数据长度的整数的指针,以字节为单位。 返回时,您的回调应该用实际传输的字节数覆盖该整数。

摘自这里


Hi there stackoverflowers. I'm implementing a wrapper for Secure Transport and I'm stuck on some of the C -> Swift syntax.

func sslReadCallback(connection: SSLConnectionRef,
    data: UnsafeMutablePointer<Void>,
    var dataLength: UnsafeMutablePointer<Int>) -> OSStatus
{
    //let bytesRequested = dataLength.memory
    let transportWrapper:SecureTransportWrapper = UnsafePointer(connection).memory
    let bytesRead:NSData = transportWrapper.readFromConnectionFunc(transportWrapper.connection)

    dataLength = UnsafeMutablePointer<Int>.alloc(1)
    dataLength.initialize(bytesRead.length)

    if (bytesRead.length == 0)
    {
        return OSStatus(errSSLClosedGraceful)
    }
    else
    {
        data.alloc(sizeof(bytesRead.length)) //<----compile error here
        return noErr
    }
}

I've marked the location of the compile error. I don't blame it for erring, I was kind of guessing here :P. I'm trying to copy the the NSData to the data:UnsafeMutablePointer. How do I do that?

Compile error:

/Users/*/SecureTransportWrapper.swift:108:9: Static member 'alloc' cannot be used on instance of type 'UnsafeMutablePointer' (aka 'UnsafeMutablePointer<()>')

Thanks a ton!

================

Update: here is the api doc for what the sslReadCallback is supposed to do:

connection: A connection reference.

data: On return, your callback should overwrite the memory at this location with the data read from the connection.

dataLength: On input, a pointer to an integer representing the length of the data in bytes. On return, your callback should overwrite that integer with the number of bytes actually transferred.

Excerpt from here


原文:https://stackoverflow.com/questions/37470378
更新时间:2022-07-10 06:07

最满意答案

最好的方法是为IE8创建一个单独的样式表

 <!--[if IE 8]>
    <link rel="stylesheet" type="text/css" href="ie8.css">
 <![endif]-->

在页面中还有许多其他内容,例如您需要添加元标记

 <meta http-equiv="X-UA-Compatible" content="IE=edge" />

还有一件事请将你的一些代码发布在一个小提琴中,这样我们就能更好地追踪问题的实际原因。

更新:

添加此修复后也检查..

 <!--[if lt IE 8]>
    <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>
 <![endif]-->

我希望这会增加一些积极的东西。

更新:

在检查jsTree Demo之后,我可以在jQuery版本中再遇到一个问题。

如果您使用的是jQuery v1.10.1或更高版本。 jQuery没有像IE8这样的老浏览器的支持,因为必须使用v.1.9.1,这是支持IE8的最后一个版本。


The best way is create a separate style sheet for IE8

 <!--[if IE 8]>
    <link rel="stylesheet" type="text/css" href="ie8.css">
 <![endif]-->

there are many other things like in page like you need to add meta tag

 <meta http-equiv="X-UA-Compatible" content="IE=edge" />

and one more thing please post some of your code in a fiddle so that we can better trace the actual cause of problem.

Update:

also check after adding this fix..

 <!--[if lt IE 8]>
    <script src="http://ie7-js.googlecode.com/svn/version/2.1(beta4)/IE8.js"></script>
 <![endif]-->

I hope this will add something positive.

Update:

After checking jsTree Demo I can conclude one more problem the jQuery Version.

If you are using jQuery v1.10.1 or later. that jQuery does not have support from older browsers like IE8 for that one must use v.1.9.1 which is the last version which supports IE8.

相关问答

更多
  • 您无法直接链接到ember中的公共目录,因为在构建过程中处理目录的方式。 我从我的URL中删除了公共目录,但它确实有效。 jsTreeConfig: { themes: { name: 'my-theme', url: '../../my-theme/style.css', }, }, You can't link directly to the public directory in ember because of the way that directo ...
  • 最后,我能够通过在css中更改背景位置来渲染图像。 这里是我找到用于从精灵渲染图像的CSS代码的工具。 雪碧牛 打开你的图像并选择部分。 之后,我创建了独立的类并使用了后台位置css。 .jstree-folder-open { background-image: url('32px.png') !important; background-position: -105px -70px !important; } .jstree-folder-closed { background-image: url( ...
  • 你必须等待DOM加载,否则jQuery将无法找到该元素: $(document).ready(function () { /* your code */ }) You have to wait for the DOM to load, otherwise jQuery won't be able to find the element: $(document).ready(function () { /* your code */ })
  • 你的例子的工作演示: JSFiddle1和JSFiddle2 请检查参考资料以及您是如何称呼它的。 这棵树应该和你正在寻找的一模一样。 其余所有文档的来源可以在这里找到: http : //www.jstree.com/ 包括下面提到的文件。 在这里看到演示 。