Re: NSData from dispatch_data_t?
Re: NSData from dispatch_data_t?
- Subject: Re: NSData from dispatch_data_t?
- From: Carl Hoefs <email@hidden>
- Date: Tue, 30 Oct 2018 19:48:05 -0700
It's ugly, but it compiles:
[NSData dataWithBytes:(__bridge const void * _Nullable)(data_t)
length:dispatch_data_get_size(data_t)];
Thanks!
-Carl
> On Oct 30, 2018, at 7:37 PM, Ryan Dignard <email@hidden>
> wrote:
>
> To get the size of the dispatch data you can call
> dispatch_data_get_size(dispatch_data_t) on it which would let you create an
> NSData object.
>
> https://developer.apple.com/documentation/dispatch/1452977-dispatch_data_get_size?language=objc
>
> -Ryan
>
> On Tue, Oct 30, 2018 at 7:26 PM Carl Hoefs <email@hidden>
> wrote:
> Is it possible to create an NSData object from a dispatch_data_t?
>
> I'm interfacing to a 3rd party library that returns only a dispatch_data_t
> object. Once upon a time you could simply cast that to (NSData *) and work
> with it that way, but Xcode now flags it as an error:
>
> dispatch_data_t data_t = BGRequestSidebandDL(channel);
> NSData *nsdata = data_t; <<<
>
> >>> Incompatible pointer types initializing 'NSData *' with an expression
> of type 'dispatch_data_t' (aka 'NSObject<OS_dispatch_data> *')
>
> Nor can I do this:
> NSData *nsdata = [[NSData alloc] initWithBytes:data_t length:size];
> because I don't know the size of the dispatch_data_t returned to me.
>
> Thx,
> -Carl
>
> _______________________________________________
>
> 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
_______________________________________________
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