NSData vs Data write to string differently?

Hi,

I’ve run into a problem when updating to new Swift in Xcode 8. There was some NSData in a string like this:
   
    “ … \(data) … “

It changed to type `Data`, and the string went from hexadecimal bytes to writing “20 bytes”. I’m doing a quick bug fix app release now. I can’t remember if Xcode auto converted this for me. I thought it did. ? Either way… seems like they should behave the same here, no?

Rob

In general you shouldn't depend on what description returns for classes,
etc. outside of your control unless it is documented (e.g. part of the API
contract). If you want a specific output you should code up something to
format the output as you need.

-Shawn

···

On Thu, Sep 22, 2016 at 3:33 PM Robert Nikander via swift-users < swift-users@swift.org> wrote:

Hi,

I’ve run into a problem when updating to new Swift in Xcode 8. There was
some NSData in a string like this:

    “ … \(data) … “

It changed to type `Data`, and the string went from hexadecimal bytes to
writing “20 bytes”. I’m doing a quick bug fix app release now. I can’t
remember if Xcode auto converted this for me. I thought it did. ? Either
way… seems like they should behave the same here, no?

Rob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

In general you shouldn't depend on what description returns for classes, etc. outside of your control unless it is documented (e.g. part of the API contract). If you want a specific output you should code up something to format the output as you need.

This is good advice, but the printing behavior of Data nonetheless strikes me as a bug. NSData's printing behavior seems much more useful than Data's. If either of you have a moment, would you be able to file a bug about this?

-Joe

···

On Sep 22, 2016, at 4:04 PM, Shawn Erickson via swift-users <swift-users@swift.org> wrote:

-Shawn

On Thu, Sep 22, 2016 at 3:33 PM Robert Nikander via swift-users <swift-users@swift.org> wrote:
Hi,

I’ve run into a problem when updating to new Swift in Xcode 8. There was some NSData in a string like this:

    “ … \(data) … “

It changed to type `Data`, and the string went from hexadecimal bytes to writing “20 bytes”. I’m doing a quick bug fix app release now. I can’t remember if Xcode auto converted this for me. I thought it did. ? Either way… seems like they should behave the same here, no?

Rob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

I had filed a related bug

  [SR-2514] Add a "hex dump" method to `Data` · Issue #4115 · apple/swift-corelibs-foundation · GitHub
  Add a "hex dump" method to `Data`

as a result of the discussion starting at

  [swift-users] No hex dump anymore in Data description

Martin

···

On 23 Sep 2016, at 03:47, Joe Groff via swift-users <swift-users@swift.org> wrote:

On Sep 22, 2016, at 4:04 PM, Shawn Erickson via swift-users <swift-users@swift.org> wrote:

In general you shouldn't depend on what description returns for classes, etc. outside of your control unless it is documented (e.g. part of the API contract). If you want a specific output you should code up something to format the output as you need.

This is good advice, but the printing behavior of Data nonetheless strikes me as a bug. NSData's printing behavior seems much more useful than Data's. If either of you have a moment, would you be able to file a bug about this?

-Joe

-Shawn

On Thu, Sep 22, 2016 at 3:33 PM Robert Nikander via swift-users <swift-users@swift.org> wrote:
Hi,

I’ve run into a problem when updating to new Swift in Xcode 8. There was some NSData in a string like this:

   “ … \(data) … “

It changed to type `Data`, and the string went from hexadecimal bytes to writing “20 bytes”. I’m doing a quick bug fix app release now. I can’t remember if Xcode auto converted this for me. I thought it did. ? Either way… seems like they should behave the same here, no?

Rob

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users

_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users