1

What dose ViewControllerClass means here?

As far as I know this is not protocol, delegate or extension. Any one can explain how dose this work?

.h file:

@interface BaseViewControllerTest <ViewControllerClass> : XCTestCase @property ViewControllerClass viewController; - (void)setUpTestWithStroyboardName:(NSString *)viewControllerName; 

.m file:

@implementation BaseViewControllerTest - (void)setUpTestWithStroyboardName:(NSString *)viewControllerName {} 

Used like this:

#import "BaseViewControllerTest.h" @interface CTSelectChildAccountViewControllerTests : BaseViewControllerTest <CTSelectChildAccountViewController *> @end 
0

1 Answer 1

2

Starting with Xcode 7 Objective-C supports generics:

Objective-C has been updated to enable it and Swift to work together more easily and efficiently. The new Objective-C language features include:

  • Generics. Allow you to specify type information for collection classes such as NSArray, NSSet, and NSDictionary. The type information improves Swift access when you bridge from Objective-C and simplifies the code you have to write.

CTSelectChildAccountViewController is a ViewController. Dose that mean ViewControllerClass is defined as UIViewController?

The asterisk from the instantiation is relevant too, so ViewControllerClass viewController is interpreted as CTSelectChildAccountViewController* viewController.

What is the benefit except Swift?

Objective C compiler has more type information now, so it can perform better checks on the methods that you call. For instance, you can annotate Cocoa collections with the type that goes into them, e.g. NSArray<NSString*> *array, and have the compiler spot places where you insert a wrong type by accident.

And how is it useful with Swift?

Swift has built-in support for generics. Adding lightweight generics to your Objective-C API makes it easier to interface with Swift, because your API gets translated more precisely. For instance, translating your example from Swift would keep its generic nature, instead of replacing generic type parameter ViewControllerClass with its base type.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer. Can you please explain a bit further how this is useful in above example?
CTSelectChildAccountViewController is a ViewController. Dose that mean "ViewControllerClass" is defined as UIViewController? What is the benefit except swift? And how with swift is useful?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.