Re: Unit testing with mixed Swift & Objective C

2016-07-18 Thread David Catmull
I found another solution: set the header search paths in the test target so
it can find the App-Swift.h file from the app target, include that in the
ObjC tests that need the Swift classes (instead of the one generated for
the test target), and then remove all the app Swift files from the test
target.

Using an auto-generated header from another target is kind of a hack, but
it works, and it's the simplest solution so far, so I'm going with it for
now.

On Sun, Jul 17, 2016 at 2:16 PM, David Catmull 
wrote:

> After converting some parts of my project to Swift, I've run into some
> problems with my tests.
>
> The first problem was where an app (not test) function, in Swift, was
> iterating over an NSArray of instances of a Swift class, because that array
> was generated by Objective C code. It was throwing an exception because the
> objects were of the wrong type. I eventually figure out that it was because
> my Swift files are in both the app and test targets, so there are two
> versions of each Swift class.
>
> For Swift tests, I understand that you're now supposed to not have your
> Swift sources in the test target, and instead use "@testable import
> MyAppModule". But what about test written in Objective C that need to
> access my Swift classes? If they're not in the test target, they won't be
> in AppTest-Swift.h. Is there some other way to generate a Swift header file?
>
> Without that, I'm looking at two alternatives for the NSArray iterating
> scenario:
> - Rewrite the function that does the iterating, using Objective C so that
> it doesn't do the type checking.
> - Rewrite the function that creates the array, using Swift so that
> hopefully the classes will match.
>
> Any other recommendations?
>
> --
> David Catmull
> davidcatm...@gmail.com
> http://uncommonplace.com
___

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

Unit testing with mixed Swift & Objective C

2016-07-17 Thread David Catmull
After converting some parts of my project to Swift, I've run into some problems 
with my tests.

The first problem was where an app (not test) function, in Swift, was iterating 
over an NSArray of instances of a Swift class, because that array was generated 
by Objective C code. It was throwing an exception because the objects were of 
the wrong type. I eventually figure out that it was because my Swift files are 
in both the app and test targets, so there are two versions of each Swift class.

For Swift tests, I understand that you're now supposed to not have your Swift 
sources in the test target, and instead use "@testable import MyAppModule". But 
what about test written in Objective C that need to access my Swift classes? If 
they're not in the test target, they won't be in AppTest-Swift.h. Is there some 
other way to generate a Swift header file?

Without that, I'm looking at two alternatives for the NSArray iterating 
scenario:
- Rewrite the function that does the iterating, using Objective C so that it 
doesn't do the type checking.
- Rewrite the function that creates the array, using Swift so that hopefully 
the classes will match.

Any other recommendations?

-- 
David Catmull
davidcatm...@gmail.com
http://uncommonplace.com
___

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