Specta is dead?

Today I opened my previous project and just ran all unit tests. I was so proud that they working with new XCode, even with some warnings.



But waiiiit….they all are passed.

I just wrote

and it passed too.

I found a long conversation in Github, as I know guys from Quick fixed same bug, but Specta seems still broken. I recommend you do not trust to its results. problems that I’ve found:

  • run single test file – always pass
  • you can’t run one test item – it doesn’t work
  • f prefix doesn’t work too!
  • if the test failed it disappears from Test Results tab

Related GitHub issues:

Hard to say, but I used to switch back to XCTestCase. You can check some examples here: https://github.com/oks/Alister

Better Unit testing with negative scenarios.

Today I was surprised, that a lot of devs miss negative test cases

Let’s take a look at example of testing simple class:



Nothing special, yeah?

Let’s try to make a full test suite for this class.

Step1. Determine test cases for this method


  • add object @“test” and expect that model.objects contain this object.
  • add object @“test” and expect that model.objects count = 1.
  • new instance expects model.objects != nil
  • new instance expects model.objects.count = 0

That’s great, but not enough, Xcode tool will tell us that we have 100% full test coverage for this class, but in reality, it’s not enough.

All sense of testing is avoided problems when something goes wrong but we keep testing only “good cases”. Why?!
Let’s go through negatives.

  • add nil and expect no crash

If we have a public method we must be sure, that it will not crash the application if any input parameter is invalid!

You can say – “It’s not a problem for me, I will check it in another class before calling this method.” When you will add a new class that will work with this method directly, and you forget about this? Or you plan to copy-paste this checks everywhere? That smells bad…
You can live with it, but it’s not great when your app crashes and you get bad reviews.

Step2. Write code


The first thing that you need to do with unit testing it’s a catch error before QA team and application users.

I strongly recommend follow with structure “Given-When-Then” to keep your test case code logically ordered and consistent.

And meanwhile, I prepare the post about proper work with tables and collections you can check daily updates in my repo.

More about unit testing you can find here: https://www.objc.io/issues/15-testing/

UITextView going crazy…


Today I stuck with some interesting UITextField behaviour. So when you call:

And your current in this moment not visible, for example you don’t use scrolling in textView and text hidden by parent frame, you can get Infinite origin for cursorRect. It seems to be not so valid, as usually inline rect and values return in case of error.

Was very strange to receive in this case.

So I was used to update textView’s frame before calling caretRectForPosition:
Also if your caret is not visible you can get some strange origin – ex. {0, -800}, when your textView content height in this moment about {320, 90}.

Asset catalog system file names

Sometimes IOS become not so obvious and not clear. The same happens to me, when I try to load default splash screen.

Example for icons:

Xcode build script using

It’s not a secret, that Xcode can run BASH scripts on some events.

But, sometimes when you add your script to Xcode, you don’t think about future modification, git blame, and merge conflict. I hate it. Very.

Xcode screen shot

So in my projects I’m using next way. Add Run Script build phase, but DON’T put your code directly in Xcode text view, you need to create a new file, with extension .sh , add execution permissions via chmod command ( chmod +x <your_file_name>.sh), and in your Xcode text view you need just to paste path to your script file:

Or if it in the project’s root directory:

Now every time when you build your project, your script will be executing.

ReactiveCocoa and NSURLSession


Working with RAC can be very helpfull, but sometimes, you need avoid completion blocks that iOS requires. I don’t like delegate methods in top of them, because theirs realization takes a lot of boliepriate code, methods, checks etc.
So here is my realization of NSURLSession for working with RAC.
Read more ReactiveCocoa and NSURLSession