8

I have a project with both, Swift and Objective-C code. I have no warnings except one file with the project name and then the suffix -Swift.h, it is the auto generated header from the Swift files.

This file is not in my project navigator nor in the folder of the project in the Finder. I can not find it in the Build Phases to add -fno-objc-arc.

Changing the file and adding code to suppress the warning will be deleted the next time I build the app.

At the top of the file is the line

// Generated by Swift version 1.0 (swift-600.0.47.8)

How can I get rid of this warning without disabling the helpful warnings for the other files in my project?


Warning exmaples:

Default property attribute 'assign' not appropriate for non-GC object

No 'assign', 'retain', or 'copy' attribute is specified - 'assign' is assumed


Swift code:

@objc class ... {
    internal var label: Identifier
}

Autogenerated code (both warning types):

SWIFT_CLASS("_TtC12...")
@interface ...
@property (nonatomic) Identifier * label; // warnings here
@end
Binarian
  • 12,296
  • 8
  • 53
  • 84
  • 2
    What warnings do you get that you want to suppress? (And adding -fno-objc-arc to a .h file does not make sense because they are not compiled on its own, they are included by .m or other source files.) – Martin R Aug 22 '14 at 17:36
  • @MartinR Added the warning types to the description – Binarian Aug 22 '14 at 18:15
  • 2
    Perhaps you can give a (minimal) example of Swift code, the corresponding bridged code and the exact locations of the warnings. – Martin R Aug 22 '14 at 18:19
  • 1
    I have difficulties to reproduce the issue. What is `Identifier`? Do you have non-default warning flags set, like -Weverything? – Martin R Aug 22 '14 at 18:43
  • @MartinR Hmm you are right, it only shows warning on custom Swift types (like `Identifier`). Yes some non-default warnings are activated. If I change `Identifier` to `NSInteger` there is no warning, when I use `NSString` there is `copy` as property attribute and therefore also no warning. Maybe I have to say it should be retain/strong, but how in Swift. – Binarian Aug 22 '14 at 19:10
  • I am still waiting for a minimal *self-contained* example ... – Martin R Aug 22 '14 at 19:12
  • I'm also having this problem.. Any progress? – zavié Sep 18 '14 at 11:59
  • @zavié Nope sorry, I could not reproduce the error in a very small testing project. If you could, that would be great. – Binarian Sep 18 '14 at 12:00
  • 8
    I had this issue the same. It turns out that I have an old objective-c class which I set -fno-objc-arc compiler flag to and this objective-c class imports -swift.h which causes this warning very reasonably. Eventually I made the objective-c class to support ARC and the warning is gone. – Berby Huang Sep 19 '14 at 05:18
  • @BerbyHuang That is what I have too. So the warning is maybe caused only by Objective-C classes with `-fno-objc-arc` and code special to manual reference counting. – Binarian Sep 19 '14 at 13:37

2 Answers2

2

You need to import UIKit in the file that is throwing the error.

Swift:

import UIKit

Obj C:

#import <UIKit/UIKit.h>

Also, take a look at my previous post: How to import Swift code to Objective-C

Given the above, try to disable "Defines Module", clean your project, and re-enable "Defines Module". Hope this helps.

Community
  • 1
  • 1
Andrei Papancea
  • 2,214
  • 1
  • 15
  • 12
1

This comment on the original question solved it for me. Once I converted the non-ARC Objective-C classes that were importing the generated Swift.h file to ARC the warnings went away.

I had this issue the same. It turns out that I have an old objective-c class which I set -fno-objc-arc compiler flag to and this objective-c class imports -swift.h which causes this warning very reasonably. Eventually I made the objective-c class to support ARC and the warning is gone. – Berby Huang Sep 19 '14 at 5:18

Jeff Mark
  • 111
  • 1
  • 4