• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Unit testing with mixed Swift & Objective C
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Unit testing with mixed Swift & Objective C


  • Subject: Unit testing with mixed Swift & Objective C
  • From: David Catmull <email@hidden>
  • Date: Sun, 17 Jul 2016 14:16:53 -0600

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
email@hidden
http://uncommonplace.com
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Unit testing with mixed Swift & Objective C
      • From: David Catmull <email@hidden>
  • Prev by Date: Re: Keyboard/Mouse Event Interaction
  • Next by Date: Re: Root URL and URLByDeletingLastPathComponent
  • Previous by thread: Re: Keyboard/Mouse Event Interaction
  • Next by thread: Re: Unit testing with mixed Swift & Objective C
  • Index(es):
    • Date
    • Thread