Re: How to do isKindOfClass in Swift

2016-09-12 Thread Gerriet M. Denkmann

> On 13 Sep 2016, at 00:14, Quincey Morris 
>  wrote:
> 
> On Sep 12, 2016, at 03:17 , Gerriet M. Denkmann  wrote:
>> 
>> The I got back to the real project: and could also not reproduce it there.
>> 
>> One explanation: working with Swift, I quite often (a few times per day) see 
>> strange (runtime) errors. Cleaning the project, then building again 
>> invariable fixes these.
>> Maybe this was one of those.
> 
> What version of Xcode are you using?

Version 7.3.1 (7D1014) on macOS 11.6.

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 12:57 , Greg Parker  wrote:
> 
> Did you file a bug report?

It’s a little awkward. The case I ran into was one of those breakpoint 
instruction crashes that I think the compiler inserts when it wants to crash 
deliberately, such as a fatalError() call, but the backtrace was lying to me 
about where it happened so I don’t really know. After I cleaned the build 
folder, the problem did not recur, so I lost the opportunity to report that 
problem.

That seems to be the pattern in the developer forums. People are complaining 
about problems that occur repeatedly until they clean the build folder.

So I don’t really know how to bug-report that. “Swift 3 is apparently broken” 
doesn’t really seem like the right way to do it, but that’s all I’ve got.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Greg Parker

> On Sep 12, 2016, at 10:14 AM, Quincey Morris 
>  wrote:
> 
>> On Sep 12, 2016, at 03:17 , Gerriet M. Denkmann  wrote:
>> 
>> The I got back to the real project: and could also not reproduce it there.
>> 
>> One explanation: working with Swift, I quite often (a few times per day) see 
>> strange (runtime) errors. Cleaning the project, then building again 
>> invariable fixes these.
>> Maybe this was one of those.
> 
> What version of Xcode are you using? FWIW, it’s pretty clear that the version 
> of Swift in the Xcode 8 GM is generating incorrect code or incorrect debug 
> information or corrupting its own indexes. I’ve seen it in my own projects, 
> and problems have been reported in the developer forums that sound similar. 
> Typically, it appears, cleaning the build folder fixes the problem.

Did you file a bug report?


-- 
Greg Parker gpar...@apple.com  Runtime 
Wrangler


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 10:27 , Jens Alfke  wrote:
> 
> At least it doesn’t catch fire, does it?

I wouldn’t rule that out.

I’m not much of an alarmist, but for anyone using Swift that hasn’t moved to 
Xcode 8 yet, I’d suggest holding off for a week or two to see if there’s any 
kind of emergency patch, or other resolution of the difficulties.

It’s also worth noting that not every Swift Evolution change approved for Swift 
3 made it into the current release. That means — it turns out, though I’m sure 
it was not planned to be this way — that the syntax upheavals aren’t quite over 
yet. Another reason to delay for Swift 3.1 if you haven’t made the jump yet.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Jens Alfke

> On Sep 12, 2016, at 10:14 AM, Quincey Morris 
>  wrote:
> 
> FWIW, it’s pretty clear that the version of Swift in the Xcode 8 GM is 
> generating incorrect code or incorrect debug information

Well, that’s comforting to hear. O_o
At least it doesn’t catch fire, does it?

—Jens

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 03:17 , Gerriet M. Denkmann  wrote:
> 
> The I got back to the real project: and could also not reproduce it there.
> 
> One explanation: working with Swift, I quite often (a few times per day) see 
> strange (runtime) errors. Cleaning the project, then building again 
> invariable fixes these.
> Maybe this was one of those.

What version of Xcode are you using? FWIW, it’s pretty clear that the version 
of Swift in the Xcode 8 GM is generating incorrect code or incorrect debug 
information or corrupting its own indexes. I’ve seen it in my own projects, and 
problems have been reported in the developer forums that sound similar. 
Typically, it appears, cleaning the build folder fixes the problem.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Gerriet M. Denkmann

> On 12 Sep 2016, at 15:51, Quincey Morris 
>  wrote:
> 
> On Sep 12, 2016, at 01:32 , Gerriet M. Denkmann  wrote:
>> 
>> In my real (as opposed to playground) code, each class lives in a different 
>> file.
> 
> I just tried it with classes in different files, and no compile error. I 
> don’t think this is a Swift 2 thing, because the “is” has been around since 
> the beginning.

I also tried a small test project: and could NOT reproduce the compiler warning 
(“classes are unrelated”).
The I got back to the real project: and could also not reproduce it there.

One explanation: working with Swift, I quite often (a few times per day) see 
strange (runtime) errors. Cleaning the project, then building again invariable 
fixes these.
Maybe this was one of those.

Thanks for your help and your patience!

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 01:32 , Gerriet M. Denkmann  wrote:
> 
> In my real (as opposed to playground) code, each class lives in a different 
> file.

I just tried it with classes in different files, and no compile error. I don’t 
think this is a Swift 2 thing, because the “is” has been around since the 
beginning.

> So maybe this makes the Swift 2.x compiler think that these classes are 
> unrelated.

I very much doubt it. There’s something else going on, but I have no idea what.

> By the way: was there is the last keynote a mention of the time for macOS 12?

Hmm, not that I recall. But it says the 20th here: 
http://www.apple.com/macos/sierra/

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Gerriet M. Denkmann

> On 12 Sep 2016, at 15:10, Quincey Morris 
>  wrote:
> 
> On Sep 12, 2016, at 01:00 , Gerriet M. Denkmann  wrote:
>> 
>> This is what I wanted to write:
>> 
>> if self is SArray { … }
>> But the compiler warns me: Cast from ‘SBase.Type’ to unrelated type 'SArray' 
>> always fails.
>> It is right: the test always fails. And wrong: they are NOT unrelated: 
>> SArray is subclass of SBase.
> 
> I typed this into a playground:
> 
>> class SBase {
>>  func a ()   {
>>  if self is SArray { print ("SArray") } else { print ("not 
>> SArray") }
>>  }
>> }
>> 
>> class SArray: SBase {
>> }
>> 
>> let s1 = SBase ()
>> s1.a ()
>> let s2 = SArray ()
>> s2.a ()
> 
> and got this output:
> 
>> not SArray
>> SArray
> 
> So you’re doing something different. Can you show a code fragment that 
> demonstrates the problem in a playground?

I tried it in a playground and got exactly the same results as you.

I seem to remember that in the last WWDC videos there was some mention that 
Swift 3 would do module-wide optimisation.
If this is correct, then this might imply that Swift 2.x cannot do this.

In my real (as opposed to playground) code, each class lives in a different 
file.
So maybe this makes the Swift 2.x compiler think that these classes are 
unrelated.

By the way: was there is the last keynote a mention of the time for macOS 12?

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 01:00 , Gerriet M. Denkmann  wrote:
> 
> This is what I wanted to write:
> 
> if self is SArray { … }
> But the compiler warns me: Cast from ‘SBase.Type’ to unrelated type 'SArray' 
> always fails.
> It is right: the test always fails. And wrong: they are NOT unrelated: SArray 
> is subclass of SBase.

I typed this into a playground:

> class SBase {
>   func a ()   {
>   if self is SArray { print ("SArray") } else { print ("not 
> SArray") }
>   }
> }
> 
> class SArray: SBase {
> }
> 
> let s1 = SBase ()
> s1.a ()
> let s2 = SArray ()
> s2.a ()

and got this output:

> not SArray
> SArray

So you’re doing something different. Can you show a code fragment that 
demonstrates the problem in a playground?

(I am using Swift 3, but this behavior should be the same in Swift 2.)

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Gerriet M. Denkmann

> On 12 Sep 2016, at 14:55, Quincey Morris 
>  wrote:
> 
> On Sep 12, 2016, at 00:50 , Gerriet M. Denkmann  wrote:
>> 
>> I would much prefer to have the semantics of “isKindOf”.
> 
> Yes, I know, that’s why you should be using:
> 
>   if self is SArray
> 
> It has the semantics of isKindOf. That was what (I thought) I said.

Sorry: I wanted to follow your advice, but made a mess of it.

This is what I wanted to write:

if self is SArray { … }
But the compiler warns me: Cast from ‘SBase.Type’ to unrelated type 'SArray' 
always fails.
It is right: the test always fails. And wrong: they are NOT unrelated: SArray 
is subclass of SBase.

The test is in SBase, which has a subclass SArray, which has subclasses 
SArray1, SArray2, …

I am still using Swift < 3.

Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 00:50 , Gerriet M. Denkmann  wrote:
> 
> I would much prefer to have the semantics of “isKindOf”.

Yes, I know, that’s why you should be using:

if self is SArray

It has the semantics of isKindOf. That was what (I thought) I said.




___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Gerriet M. Denkmann

> On 12 Sep 2016, at 14:27, Quincey Morris 
>  wrote:
> 
> On Sep 12, 2016, at 00:08 , Gerriet M. Denkmann  wrote:
>> 
>> I want to do:
>> if self.dynamicType == SomeClass { … }
>> 
>> But the compiler won’t accept this (or any number of variations thereof).
> 
> Try this:
> 
>   if self is SomeClass { … }
> 
> Typically, if you need to use a class in an expression, you’ll need to refer 
> to the metatype instance:
> 
>   if self.dynamicType == SomeClass.self { … }
> 
> but this would be an exact match. If you want the semantics of “isKindOf” 
> (that is, the object is of the specified class or a subclass) then “is” is 
> the way to go.


if self.dynamicType == SArray.self 
{
print("Test1 \(self.dynamicType) is a subclass of SArray")
}
else
{
print("Test1 \(self.dynamicType) is NOT subclass of SArray")
}

prints: Test1 SArray2 is NOT subclass of SArray
Not quite what I expected.

But this works:

if self.dynamicType == SArray1.self || self.dynamicType == SArray2.self || 
self.dynamicType == SArray3.self 
{
print("Test2 \(self.dynamicType) is a subclass of SArray")
}
else
{
print("Test2 \(self.dynamicType) is NOT subclass of SArray")
}

prints: Test2 SArray2 is a subclass of SArray

The only problem: It is kind of fragile. When I create a new class SArray5 then 
I must remember to fix this test.
I would much prefer to have the semantics of “isKindOf”.


Kind regards,

Gerriet.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: How to do isKindOfClass in Swift

2016-09-12 Thread Quincey Morris
On Sep 12, 2016, at 00:08 , Gerriet M. Denkmann  wrote:
> 
> I want to do:
> if self.dynamicType == SomeClass { … }
> 
> But the compiler won’t accept this (or any number of variations thereof).

Try this:

if self is SomeClass { … }

Typically, if you need to use a class in an expression, you’ll need to refer to 
the metatype instance:

if self.dynamicType == SomeClass.self { … }

but this would be an exact match. If you want the semantics of “isKindOf” (that 
is, the object is of the specified class or a subclass) then “is” is the way to 
go.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com