user1586843
user1586843

Reputation:

xcode 7 Type arguments cannot be applied to non-parameterized class

I'm getting this error in my xcode project today... I have never got it before. The only change I've made since the last successful build is that I imported the iAD framework (I did that this morning before I tried to do a fresh build, so I'm not sure if it had anything to do with it. I doubt it though.) All of the issues are with NSSet/NSArray/NSDictionary and are all contained in UIKit's UIEvent and CoreImage's CIImage. If anyone has any idea what might be going on here, I would appreciate the input.

Edit: I forgot to mention the specific errors. Here they are:

"Type arguments cannot be applied to non-parameterized class 'NSSet'",

"Type arguments canot be applied to non-parameterized class 'NSArray'",

"Type arguments canot be applied to non-parameterized class 'NSDictionary'"

Edit 2: I did not realize that the app store automatically updated xcode from 6.4 to 7.0, so I changed to title to reflect the correct xcode version.

Here's where it's happening in UIEvent.h (lines 50, 51, 52, 53, 56, 59):

- (nullable NSSet <UITouch *> *)allTouches;
- (nullable NSSet <UITouch *> *)touchesForWindow:(UIWindow *)window;
- (nullable NSSet <UITouch *> *)touchesForView:(UIView *)view;
- (nullable NSSet <UITouch *> *)touchesForGestureRecognizer:        (UIGestureRecognizer *)gesture NS_AVAILABLE_IOS(3_2);

// An array of auxiliary UITouch’s for the touch events that did not get delivered for a given main touch. This also includes an auxiliary version of the main touch itself.
- (nullable NSArray <UITouch *> *)coalescedTouchesForTouch:(UITouch *)touch NS_AVAILABLE_IOS(9_0);

// An array of auxiliary UITouch’s for touch events that are predicted to occur for a given main touch. These predictions may not exactly match the real behavior of the touch as it moves, so they should be interpreted as an estimate.

Here's where it's happening in UIResponder.h (lines 31-34):

// Generally, all responders which do custom touch handling should override all four of these methods.
// Your responder will receive either touchesEnded:withEvent: or touchesCancelled:withEvent: for each
// touch it is handling (those touches it received in touchesBegan:withEvent:).
// *** You must handle cancelled touches to ensure correct behavior in your application.  Failure to
// do so is very likely to lead to incorrect behavior or crashes.
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;
- (void)touchesCancelled:(nullable NSSet<UITouch *> *)touches withEvent:(nullable UIEvent *)event;

Also happening in UIREsponder.h (line 79):

@interface UIResponder (UIResponderKeyCommands)
@property (nullable,nonatomic,readonly) NSArray<UIKeyCommand *>     *keyCommands NS_AVAILABLE_IOS(7_0); // returns an array of UIKeyCommand objects<
@end

Here's where it's happening in CIImage.h lines 97 and 102:

/* Creates a new image from the contents of 'image'. */
+ (CIImage *)imageWithCGImage:(CGImageRef)image;
+ (CIImage *)imageWithCGImage:(CGImageRef)image
                  options:(nullable CI_DICTIONARY(NSString*,id) *)options;

/* Creates a new image from the contents of 'layer'. */
+ (CIImage *)imageWithCGLayer:(CGLayerRef)layer NS_DEPRECATED_MAC(10_4,10_11);
+ (CIImage *)imageWithCGLayer:(CGLayerRef)layer
                  options:(nullable CI_DICTIONARY(NSString*,id) *)options NS_DEPRECATED_MAC(10_4,10_11);

Upvotes: 8

Views: 6150

Answers (3)

turingtested
turingtested

Reputation: 7154

I know that it's an old question but since no one actually tried to answer it I will have a go.

The error messages is about the type parameters, for example <UITouch *>in the declaration of allTouches in UIEvent.h, which tells you to expect a set of touches from this method. The compiler is complaining however because it cannot find any such corresponding declaration in NSSet.h.

So probably the first line in NSSet.h looks something like this (in Xcode 6):

@interface NSSet : NSObject <NSCopying, NSMutableCopying, NSSecureCoding, NSFastEnumeration>

But it should look like this (to make this particular warning to go away):

@interface NSSet<UITouch> : NSObject <NSCopying, NSMutableCopying ...

But hey, sets can contain other than touches, so it actually uses a generic type parameter <ObjectType> (since Xcode 7):

@interface NSSet<__covariant ObjectType> : NSObject <NSCopying, NSMutableCopying ...

The keyword __covariant means that subtypes of ObjectType also is acceptable, so basically anything goes here.

So to answer to original question: upgrade Xcode. And the reason how this error could've occurred is most certainly that the guys that made that framework had a beta version version of Xcode with a higher number than you.

But the reason why I'm answering this question is that this error could occur when you start using type parameters in your own method declarations, which is probably a more common scenario today. Then you should go to the class declaration (of the "non-parameterized class") and add either a type parameter or a generic type parameter as shown above for NSSet.

Upvotes: 2

Renetik
Renetik

Reputation: 6373

I had also this error, and I just changed @class to #import for problematic class and then clean and build and it was ok again... some bug I think... The class with problem was my own parametrised class.

Upvotes: 2

user1586843
user1586843

Reputation:

I have revisited this issue and it appears others have addressed it in different threads & on github.

The problem was that the Parse/Bolts framework that I had included in my project was out of date and that I had them saved locally in my project. The version that I had in my project conflicted with xcode 7.

After removing all local copies and adding "pod 'Parse'" to my pod file and running 'pod install', this specific issue was resolved.

For anyone having a related issue, you should try updating the old dependancies that you have remaining in your project and see which fixes this issue for you.

Here are some related threads that discuss this issue in more detail:

Type arguments cannot be applied to non-parameterized class BFTask in PFAnalytics and PFObject

https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/297

Upvotes: 0

Related Questions