• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Data, enumerateBytes: separate blocks?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Data, enumerateBytes: separate blocks?


  • Subject: Re: Data, enumerateBytes: separate blocks?
  • From: Daryle Walker <email@hidden>
  • Date: Fri, 22 Dec 2017 11:48:47 -0500

> On Dec 21, 2017, at 11:10 PM, Quincey Morris
> <email@hidden> wrote:
>
> On Dec 21, 2017, at 18:04 , Daryle Walker <email@hidden
> <mailto:email@hidden>> wrote:
>>
>> when multiple blocks are used
>
> At this point, I don’t understand what you don’t understand. Here’s a code
> fragment that works in a playground:
>
>> import Foundation
>>
>> let buffer1: [UInt8] = [1,2]
>> let buffer2: [UInt8] = [3,4,5,6]
>>
>> var data = DispatchData.empty
>> data.append (buffer1.withUnsafeBytes { DispatchData (bytesNoCopy: $0) })
>> data.append (buffer2.withUnsafeBytes { DispatchData (bytesNoCopy: $0) })
>>
>> print (data.count)
>> data.enumerateBytes {
>>      bytes, index, stop in
>>      print (bytes.count, index, bytes [0])
>> }
>
> producing this output:
>
>> 6
>> 2 0 1
>> 4 2 3
>
> Isn’t this what you were asking for: a loop enumerating each of the
> contiguous portions of a larger data set?

I already have the code as an extension of Data. In C, we can use pointer
type-punning shenanigans to convert between a dispatch_data_t and NSData*. To
trigger this code in a test that I would write in Swift, DispatchData would
need to be convertible to Data.  Is there a way to do the conversion in Swift?
It doesn’t seem obvious since DispatchData and Data are value types, not
pointer nor reference types.

I just checked it out with your code above in a playground.  I added an
extension to Data called “printHello” and called it with a Data object I also
added.  Sure enough, the DispatchData object could not call that same method.

—
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Data, enumerateBytes: separate blocks?
      • From: Quincey Morris <email@hidden>
References: 
 >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>)
 >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>)
 >Re: Data, enumerateBytes: separate blocks? (From: Daryle Walker <email@hidden>)
 >Re: Data, enumerateBytes: separate blocks? (From: Quincey Morris <email@hidden>)

  • Prev by Date: Re: Data, enumerateBytes: separate blocks?
  • Next by Date: Re: Data, enumerateBytes: separate blocks?
  • Previous by thread: Re: Data, enumerateBytes: separate blocks?
  • Next by thread: Re: Data, enumerateBytes: separate blocks?
  • Index(es):
    • Date
    • Thread