<Module auto-generated>-Swift.h file is generated with syntax errors

Hi,


I'm having some issue with Xcode8 that I wasn't having with Xcode7... I have a modified version of BSimagePicker Pod and the BSimagePicker-Swift.h is generated like this:


@class PHAssetCollection;
@class PHAsset;
@class NSCoder;
@class UIColor;
@class UIBarButtonItem;
@class UIButton;
@class UIViewController;
@class NSBundle;
/*
  BSImagePickerViewController.
  Use settings or buttons to customize it to your needs.
*/
SWIFT_CLASS("_TtC13BSImagePicker27BSImagePickerViewController")
@interface BSImagePickerViewController : UINavigationController
/*
  Want it to show your own custom fetch results? Make sure the fetch results are of PHAssetCollections
  \param fetchResults PHFetchResult of PHAssetCollections
*/
- (nonnull instancetype)initWithFetchResults:(NSArray<PHFetchResult<id> *> * _Nonnull)fetchResults;


showing error unknown type name PHFetchResult on line 20 and also to get rid of "<id>" from that line

If I add @class PHFetchResult; on the top and take out the "<id>" and build again the project works just fine. The thing is everytime I clean a build again the BSimagePicker-Swift.h is regenerated with those errors. So when I try to create an Archive from it it always fails...


Anyone knwo how to get around this?


Thanks in advance

Replies

What does the Swift side of this declaration look like?

If you extract BSImagePickerViewController into your own scratch framework, including just this

-initWithFetchResults:
method, what does that generated header look like?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo!


Thanks for the reply. The BSimagePicker.swift looks like this:


import UIKit
import Photos
/*
BSImagePickerViewController.
Use settings or buttons to customize it to your needs.
*/
@objc public final class BSImagePickerViewController : UINavigationController, BSImagePickerSettings {
    fileprivate let settings = Settings()

    fileprivate var doneBarButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
    fileprivate var cancelBarButton: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: nil, action: nil)
    fileprivate let albumTitleView: AlbumTitleView = bundle.loadNibNamed("AlbumTitleView", owner: nil, options: nil)!.first as! AlbumTitleView
    fileprivate var dataSource: SelectableDataSource?
    fileprivate let selections: [PHAsset]

    static let bundle: Bundle = Bundle(path: Bundle(for: PhotosViewController.self).path(forResource: "BSImagePicker", ofType: "bundle")!)!

    lazy var photosViewController: PhotosViewController = {
        let dataSource: SelectableDataSource
        if self.dataSource != nil {
            dataSource = self.dataSource!
        } else {
            dataSource = BSImagePickerViewController.defaultDataSource()
        }
   
        let vc = PhotosViewController(dataSource: dataSource, settings: self.settings, selections: self.selections)
   
        vc.doneBarButton = self.doneBarButton
        vc.cancelBarButton = self.cancelBarButton
        vc.albumTitleView = self.albumTitleView
   
        return vc
    }()
    /*
    Want it to show your own custom fetch results? Make sure the fetch results are of PHAssetCollections
    - parameter fetchResults: PHFetchResult of PHAssetCollections
    */
    public convenience init(fetchResults: [PHFetchResult<AnyObject>]) {
        self.init(dataSource: FetchResultsDataSource(fetchResults: fetchResults))
    }

    /*
    Do you have an asset collection you want to select from? Use this initializer!
    - parameter assetCollection: The PHAssetCollection you want to select from
    - parameter selections: Selected assets
    */
    public convenience init(assetCollection: PHAssetCollection, selections: [PHAsset] = []) {
        self.init(dataSource: AssetCollectionDataSource(assetCollection: assetCollection), selections: selections)
    }

    /*
    Sets up an classic image picker with results from camera roll and albums
    */
    public convenience init() {
        self.init(dataSource: nil)
        doneBarButton.tintColor = UIColor(red: 99.0/255, green: 194.0/255, blue: 155.0/255, alpha: 1.0)
        cancelBarButton.tintColor = UIColor(red: 99.0/255, green: 194.0/255, blue: 155.0/255, alpha: 1.0)
        albumTitleView.tintColor = UIColor(red: 99.0/255, green: 194.0/255, blue: 155.0/255, alpha: 1.0)
    }

    /*
    You should probably use one of the convenience inits
    - parameter dataSource: The data source for the albums
    - parameter selections: Any PHAsset you want to seed the picker with as selected
    */
    public required init(dataSource: SelectableDataSource?, selections: [PHAsset] = []) {
        if let dataSource = dataSource {
            self.dataSource = dataSource
        }
   
        self.selections = selections
   
        super.init(nibName: nil, bundle: nil)
    }
    /*
        */
    required public init?(coder aDecoder: NSCoder) {
        dataSource = BSImagePickerViewController.defaultDataSource()
        selections = []
        super.init(coder: aDecoder)
    }

    /*   ...   */


Sorry I didn't get what you said about extracting the BSImagePickerViewController into my own scratch framework... What do you mean by that?


Keep in mind that I automatically converted to Swift 3 and was fixing manually the generated errors from that conversion. the original file is at this link: https://github.com/mikaoj/BSImagePicker/blob/master/Pod/Classes/Controller/BSImagePickerViewController.swift


Thank you

The BSimagePicker.swift looks like this …

Thanks.

Sorry I didn't get what you said about extracting the BSImagePickerViewController into my own scratch framework... What do you mean by that?

I’m suggesting that you put just this declaration into a test framework, newly created from the Xcode project template, to see if that reproduces the problem.

I just tried that myself and, lo!, it does reproduce the problem; this tells us that there’s a general problem, not something caused by a weird build settings in your project.

It seems that this problem is tied to Swift’s header generation for Swift class that references generics that originate in Objective-C. This is clearly a bug and you should file it as such. Please post your bug number, just for the record.

If your Objective-C code can get away without

init(fetchResults:)
then you could just remove this method (or mark it
internal
). However, if you need this method on the Objective-C side then I’m at a bit of a loss how to fix this. If no one else has any clever suggestions my recommendation is that you raise this over on swift-users.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I'm having the same issue, did anyone report this bug?

Hi @ricrvo ,

Import Photos framework in your Project Brige-header.h file.

@import Photos;