Re: Swift description

2015-07-13 Thread Roland King
> > Note that there is a distinction between "print an object" and "perform > string interpolation on an object and print that string". > >print(c)// I have the lot >print("\(c)") // I have the lot >debugPrint(c) // I am CustomDebugStringConvertible >debu

Re: Swift description

2015-07-12 Thread Greg Parker
> On Jul 11, 2015, at 6:29 PM, Roland King wrote: > >> >> However, Roland got it slightly wrong, according to the documentation. This: >> >> print (“\(myObj)”) >> >> never uses debugDescription, only description. To use debugDescription (if >> it exists, or description instead): >> >>

Re: Swift description

2015-07-11 Thread Roland King
> > However, Roland got it slightly wrong, according to the documentation. This: > > print (“\(myObj)”) > > never uses debugDescription, only description. To use debugDescription (if it > exists, or description instead): > > debugPrint (“\(myObj)”) Dunno about the documentation -

Re: Swift description

2015-07-11 Thread Quincey Morris
On Jul 11, 2015, at 11:51 , Jens Alfke wrote: > > I think William asked how to implement a custom description, not how to print > it. Roland was pointing out that Swift uses the custom description for string interpolation, which is the equivalent of using a “%@“ format string in Obj-C. That d

Re: Swift description

2015-07-11 Thread Jens Alfke
I think William asked how to implement a custom description, not how to print it. The method is the same (for compatibility): description(). But since Swift is stricter about typing, you have to implement the Printing (sp?) protocol, which contains just that one method, to signal that your clas

Re: Swift description

2015-07-11 Thread Roland King
> On 11 Jul 2015, at 22:24, William Squires wrote: > > In ObjC, I can have a class implement the description message so I can do: > > MyClass *myObj = [[MyClass alloc] init]; > > NSLog("%@", myObj); > > and it will be as if I did: > > NSString *aDesc = [myObj description]; > NSLog("%@", aDes

Swift description

2015-07-11 Thread William Squires
In ObjC, I can have a class implement the description message so I can do: MyClass *myObj = [[MyClass alloc] init]; NSLog("%@", myObj); and it will be as if I did: NSString *aDesc = [myObj description]; NSLog("%@", aDesc); What's the Swift equivalent? _