magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Changing to @import causes build errors #1139

Closed sbwilson closed 8 years ago

sbwilson commented 8 years ago

The changes in ffbe55154b1d6e078898e99d978654e5c5ccc682 cause my builds to break with the error:

error: use of '@import' when modules are disabled
@import Foundation;

This occurs in a cocoapods-based project (using the release/3.0 branch by :git/:branch) with Modules enabled in the build settings for this project (though not used anywhere else). The error occurs when compiling the application's PCH, using #import <MagicalRecord/MagicalRecord.h>. I've tried replacing that with @import MagicalRecord with the same error.

Any hints how to get around this? Since Xcode 6+ (and perhaps earlier) treats #import the same as @import, it doesn't make much sense as to why this change is needed...

Thanks!

tonyarnold commented 8 years ago

That's because CocoaPods completely ignores the Xcode project :frowning:

Telling Cocoapods to use frameworks would probably fix it, but I'll have a look when I have some time.

sbwilson commented 8 years ago

I'm already building with use_frameworks!. Here's my complete Podfile if it helps...

source 'https://github.com/CocoaPods/Specs.git'

workspace '../MyApp'
xcodeproj '../MyApp'

platform :osx, '10.10'
inhibit_all_warnings!
use_frameworks!

target :MyApp do
  pod 'Typhoon', '3.3.4'
  pod 'ReactiveCocoa', '~> 2.0'
  pod 'JLRoutes'
  pod 'GCDWebServer'
  pod 'NSLogger', '~> 1.5'
  pod 'CocoaLumberjack', '~> 1.9'
  pod 'MagicalRecord/Shorthand', :git => 'https://github.com/magicalpanda/MagicalRecord', :branch => 'release/3.0'
  pod 'RegexKitLite', '~> 4.0'
  pod 'JRSwizzle', '~> 1.0'
  pod 'RXCollections'
  pod 'YAML-Framework', '~> 0.0.1'
  pod 'CoreParse'
  pod 'MAKVONotificationCenter'
  pod 'sundown'
  pod 'DirectoryWatchdog', '~> 1.1'
end
tonyarnold commented 8 years ago

Yeah, there's probably some CocoaPods setting you could have fiddled with here, because not supporting @import seems like a massive oversight (and I don't believe that team would have overlooked this).

But I don't have time to muck about with CocoaPods, so I've just reverted to using the older framework import syntax. Let me know if this doesn't work for you.

sbwilson commented 8 years ago

That does seem to fix the problem. Thanks!

On further investigation, it seems that it may be a problem with ObjectiveC++ (which we use a fair amount of). An answer to a Stack Overflow question suggests that the flag -fcxx-modules is the solution. I've tried it with a blank Cocoa App, and confirm that @import in the AppDelegate.h (with AppDelegate.mm) does cause the same error, and -fcxx-modules in "Other C++ Flags" does fix said errors. However, it's no longer documented in the latest documentation, and given that the SO answer suggests that it is "EXPERIMENTAL and VERY BROKEN", I wonder if #import would be much preferred at this stage.