NSData vs Data write to string differently?


#1

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


(Shawn Erickson) #2

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


(Joe Groff) #3

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


(Martin R) #4

I had filed a related bug

  https://bugs.swift.org/browse/SR-2514
  Add a "hex dump" method to `Data`

as a result of the discussion starting at

  https://lists.swift.org/pipermail/swift-users/Week-of-Mon-20160822/003035.html

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