Re: [swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread Rick Mann via swift-users
ave Sweeris > >> On Aug 2, 2016, at 6:22 PM, Rick Mann via swift-users >> <swift-users@swift.org> wrote: >> >> I'm trying to define a protocol that has a read-only, immutable member >> "uuid" that can be set in the init() method, but I'm havin

[swift-users] Protocol with instance var that's set on construction, otherwise read-only

2016-08-02 Thread Rick Mann via swift-users
I'm trying to define a protocol that has a read-only, immutable member "uuid" that can be set in the init() method, but I'm having trouble. I have this: protocol Element { var uuid : { get } } extension Element { init(...) { self.uuid = ... } } I can't make it let,

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-02 Thread Rick Mann via swift-users
> On Aug 2, 2016, at 13:07 , Dave Abrahams via swift-users > wrote: > > > on Mon Aug 01 2016, Rick Mann wrote: > >>> On Aug 1, 2016, at 19:18 , Jack Lawrence wrote: >>> >>> Jens: Why? There are significant benefits to value semantics for >>> this

Re: [swift-users] More questions about protocol/value programming

2016-08-02 Thread Rick Mann via swift-users
header = parsedHeader >> } >> } > > Then, if you want to provide a nicer interface, do it with an extension: > >> protocol Element { >> var uuid : UUID{ get } >> var name : String? { get, set } >> } >> >> extension PartIn

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
d to see that change. I don't think I get to take advantage of value semantics, and it makes me wonder if any typical, non-trivial model's object graph really has no reference semantics. > > Jack >> On Aug 1, 2016, at 4:32 PM, Jens Alfke via swift-users >> <swift-users@swift.or

[swift-users] Why can't structs inherit from other structs?

2016-08-01 Thread Rick Mann via swift-users
It sure seems natural. Is there some reason the language can't allow a sub-struct to add member variables, such that the whole is treated like a contiguous set of members? In my case, I have a rect-like value type, but I'd rather it inherit from CGRect, rather than contain a CGRect. That makes

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 16:32 , Jens Alfke <j...@mooseyard.com> wrote: > > >> On Aug 1, 2016, at 1:19 AM, Rick Mann via swift-users >> <swift-users@swift.org> wrote: >> >> It seems like reference semantics are more appropriate here. > > Yes,

[swift-users] More questions about protocol/value programming

2016-08-01 Thread Rick Mann via swift-users
In my schematic capture app, I had a class hierarchy that started with Element. From that I derived PartDefinition and PartInstance. Element has an immutable UUID, name, and description. Element knows how to encode itself as XML by conforming to an XMLCoding protocol. Now I'm trying to make

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 02:25 , Rimantas Liubertas wrote: > > > I did. That's one of the two talks I mentioned. > > Well, so they did cover this, didn't they? You move item, you get the new > struct with the new position. And if you save the old one, you have a cheap > way

Re: [swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
> On Aug 1, 2016, at 02:14 , Rimantas Liubertas wrote: > > > Similarly, in the diagramming example from the WWDC videos, how would that > app handle the user editing existing Drawables in the Diagram? Let's say you > allow the user to click on a Drawable and drag it to

[swift-users] Are value semantics really appropriate in a diagramming app?

2016-08-01 Thread Rick Mann via swift-users
I watched the WWDC 2015 video about protocol-oriented programming and value semantics. Both of them use the example of a diagramming app, where the user can make a diagram of circles and polygons. They make a protocol for Drawable (makes sense), and then make Circle and Polygon structs. I'm

Re: [swift-users] Compact iteration of optional collection?

2016-07-28 Thread Rick Mann via swift-users
On Thu, Jul 28, 2016 at 2:55 PM, Rick Mann via swift-users > <swift-users@swift.org> wrote: > I often call methods that return an optional collection. I then iterate over > it. The problem is, it's a bit cumbersome to write: > > if let container = someOptio

[swift-users] Compact iteration of optional collection?

2016-07-28 Thread Rick Mann via swift-users
I often call methods that return an optional collection. I then iterate over it. The problem is, it's a bit cumbersome to write: if let container = someOptionalContainer { for item in container { } } I wish I could just write for item in

Re: [swift-users] Why there's no Character literals?

2016-07-10 Thread Rick Mann via swift-users
> On Jul 10, 2016, at 11:44 , Saagar Jha via swift-users > wrote: > > Well, what if you wanted to create a String with one character? There’s no > way to differentiate. That hardly seems like the justification. In that case, you'd specify the type: let s: String =

Re: [swift-users] object.self?

2016-07-09 Thread Rick Mann via swift-users
self." To me, for an instance, foo an foo.self should be equivalent in all respects (shouldn't it?). > > Best, > Austin > > > On Fri, Jul 8, 2016 at 9:38 AM, Rick Mann via swift-users > <swift-users@swift.org> wrote: > I just saw a question which brough

[swift-users] object.self?

2016-07-08 Thread Rick Mann via swift-users
I just saw a question which brought up something I didn't know about. Apparently sometimes you have to call object.self in a place that looks like you should just use "object." What does this usage mean? for subclassObject in objects { switch subclassObject.self {<--- Here, why not

Re: [swift-users] Why can't Swift instance methods call class methods without qualification?

2016-07-04 Thread Rick Mann via swift-users
> Karen Stone wrote: >> I believe there’s real value in being explicit about referencing class >> members. It helps both the reader of the code and it makes writing code >> with typical IDE conveniences like code completion less cluttered and more >> informative. Unfamiliar class methods

Re: [swift-users] C API returns null but optional thinks it's set anyway

2016-07-01 Thread Rick Mann via swift-users
sure seems like Swift could easily check for Unsafe Pointers with value == 0. > > Dan > > On Fri, Jul 1, 2016 at 2:59 AM, Rick Mann via swift-users > <swift-users@swift.org> wrote: > I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL &g

[swift-users] C API returns null but optional thinks it's set anyway

2016-07-01 Thread Rick Mann via swift-users
I have some Swift code (in Xcode 7.3) that's calling a C function in the GDAL library. It's declared like this: typedef void *GDALDatasetH; GDALDatasetH CPL_DLL CPL_STDCALL GDALOpen( const char *pszFilename, GDALAccess eAccess ) CPL_WARN_UNUSED_RESULT; I'm calling it with code like this: class

[swift-users] Why can't Swift instance methods call class methods without qualification?

2016-06-30 Thread Rick Mann via swift-users
Why can my instance methods not call class methods without the class specifier? class MyClass { func foo() { classMethod() } class func classMethod() { } } Why do I have to call MyClass.classMethod()? Just a choice made by the language designers to distinguish

<    1   2