Use of unresolved identifier false warning Swift 3 xcode - ios

So I edited my post to be more clear. I am new in xcode and Swift 3 and I am facing to a strange problem. My project contains several swift files. I put all my simple common methods to Utils.swift, for instance simple string functions, etc. For many days I had no problems but after a point xcode is all the time complaining with red exclamation marks in all the files where I use my method if I am calling my methods from Utils.swift file: "Use of unresolved identifier 'xxx'".
// debug is a bool variable declared before
Utils.swift:
func log(_ message: String) {
if debug {
print(message)
}
}
ViewController.swift:
log("Error happened")
This gives an error "Use of unresolved identifier 'Log' ". Obviously the function is there so I don't understand why I get this red warning with exclamation mark during coding however when I click on Build, it is successful, and it runs perfectly and the warning is gone. As soon as I start typing again in the code area, the red error comes back. If I build it once more it is successful again. It doesn't make any sense to me.
I thought it is maybe a cache problem, xcode live issues function doesn't recognise my Utils.swift or something like this... so I cleaned the build folder (cmd + shift + option + K), I cleaned the project (Product > Clean), restarted xcode, restarted Mac, removed Utils.swift, re-added Utils.swift to the project but can not get rid of these false warnings during coding but if build the project it is OK. I don't have this problem in my other projects. Any idea?

Okay I found the answer myself. Clicking on the swift file (now Utils.swift) I had to select "Location Relative to Group" in file inspector and set the appropriate target memberships as well.
It is weird that despite the previous 'wrong' settings the build completes with success however it gives an error in the code area.

Related

"help to fix ' error: unable to read property list from file: info.plist

I added Admob Google extension in to my Game Maker 2 project, when I try to test it on xcode for iOS, I am getting the error from xcode : unable to read property list from file: ...
Tried to fiddle around with the build settings in Xcode for plist to make it XML/Binary and same as input but nothing helped.
Made sure that the extensions in game maker have IOS enabled
Tried to clean build folder
Changed Locations: of Derived data to Relative
Looked for similar problems on google and stack overflow, but nothing exactly with the same issue
Below is the code given by Gamemaker
if os_type == os_ios
{
ads_app_id = "ca-app-pub-4724502015965127~5126911475";
banner_id = "ca-app-pub-4337965814269841/5893054134";
interstitial_id = "ca-app-pub-4724502015965127/8852681295";
rewarded_id = "ca-app-pub-4724502015965127/3717109960";
}
else
{
ads_app_id = "ca-app-pub-4337965814269841~8766033395";
banner_id = "ca-app-pub-4337965814269841/5893055122";
interstitial_id = "ca-app-pub-4337965814269841/5893055258";
rewarded_id = "ca-app-pub-4337965814269841/5893055399";
}
GoogleMobileAds_Init(interstitial_id, ads_app_id);
GoogleMobileAds_LoadInterstitial();
interstitial_loaded = false;
error:
unable to read property list from file:
/Users/faisalnaamani/GameMakerStudio2/iOS/GMS2IOS/Pixel_Bricks_iOS/Pixel_Bricks_iOS/Pixel_Bricks_iOS/Supporting
Files/Pixel_Bricks_iOS-Info.plist: The operation couldn’t be
completed. (XCBUtil.PropertyListConversionError error 1.)
The error is happening at Build time
I opened the plist file with ATOM, the one generated by GameMaker Studio when I noticed xcode could not read it. I noticed a bit of code that was causing an error and when I deleted it xcode was able to build. The code is below:
<key>NSAppTransportSecurity</key>\n\r<dict>\n\r
<key>NSAllowsArbitraryLoads</key>\n\r <true/>\n\r
<key>NSAllowsArbitraryLoadsForMedia</key>\n\r <true/>\n\r
<key>NSAllowsArbitraryLoadsInWebContent</key>\n\r <true/>\n\r</dict>
But I am not sure how to fix it to make it look correct. I am afraid if I delete it somehow the code will not be correct. Does anyone have a solution? And how would I fix it from GameMaker.
As Faisal suggested, the file cannot be read if it's malformed.
Trying to open the file with Xcode helped me find the problem: a syntax error. Xcode was very explicit about where the error might be: at line 32.
After fixing the error in another IDE I was able to open the file with Xcode and build/run my app.

Xcode 6.0.1 Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1

I am getting this error on archive:
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
How to solve it?
Please see the screenshot.
This problem occurs when the Swift optimization level is not set to None for Release. Set the value to None and the issue goes away.
Open up your project and click on the projects root directory.
Click the build settings tab.
Search for Swift Compiler - Code Generation and under Optimization Level make sure Release is set to None.
EDIT
After upgrading to Xcode 6.1 these instructions caused other issues when archiving (building for debug/device worked fine). Setting the optimization to Fastest allowed me to archive again. There are apparent issues with Swift compiling still (archiving specifically).
Can't archive working 6.0.1 Swift project in Xcode 6.1 / Segmentation fault: 11
EDIT
I was not able to fund the Build Settings tab, until I read this answer.
how to find the build settings tab
This occurred for me when I had two of the exact same files, and also when I was missing I file I didn't know I had deleted. I clicked on the error message, and just above the error, it shows you what file you have more than 1 of or are missing.
You can click the Product in the navigation and choose the "Clean" button; it will clean all compile error in your project. Then, you can debug for the latest error.
Deleted files reference keep in Build Phase and that's why it gives this error. Remove reference from there as well.
Project> Target > Build Phase
Under this section you will find your deleted files in red colour. Remove these files error will resolve.
I am not sure if it has one solution.
I recommend you to check the differences between your last git commit, and comment on/off the changes.
In my case, my code was
let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
for aDict : NSDictionary in anArray {
let anObject = ObjectType(ObjectDict: aDict)
objectList.addObject(aDict)
}
no warning on the line, i got the same exit 1 compile error
then i changed it to the below it has compiled.
let anArray = ResultDict["ResultSet"] as [[NSDictionary : AnyObject]]
for aDict in anArray {
let anObject = ObjectType(ObjectDict: aDict)
objectList.addObject(aDict)
}
I don't know if this is really an answer, but...
I had the same issue. App worked when building/running, but archiving failed with "...swiftc failed with exit code 1", with no other helpful message at all. Luckily, when I tried to build my app with Nomad's ipa build, I got:
The following build commands failed:
CompileSwift normal arm64 /path/to/erroneous/TableViewController.swift
So I started commenting out sections of that file and tracked the problem down to a tuple assignment.
// MARK: - Table Data
private var tableData: [(sectionName: String, item:ListItem)] = []
private func refreshTableData() {
// let labor = ("Labor", laborListItem) // DOESN'T ARCHIVE
let labor = (sectionName: "Labor", item: laborListItem) // ARCHIVES
tableData = [labor]
tableView.reloadData()
}
So apparently the compiler wanted the elements in thast tuple named (as defined by the type of tableData).. but only for archiving? The Dumb thing is, I use this same pattern in other view controllers, and the compiler seems to be fine with those.
For the record my Code Generation -> Optimization Level was set to None for debug and release.
Hope this helps someone! It took hours to figure this out.
It happened to me when I didn't put the parenthesis at the end of a call of a function:
let var = self.getNextPrimeNumber
solved it by:
let var = self.getNextPrimeNumber()
In my case, it was caused by duplicate files, using the same name, in my project directory. As soon as I removed them, the error was gone.
This happened to me when I used static inline function from swift file
The function looks like this
static inline void openURLInSafari(NSString * _Nonnull urlString) {
[[UIApplication sharedApplication]openURL:[NSURL URLWithString:urlString]];}
I just had the same thing occur. I hunted down the cause to one file that caused the error even when empty. Examining the file, I discovered it had the wrong character set. When I set it to UTF-8, the error vanished. I think that it was decoding it with the wrong character set.
From this I surmise that the error simply indicates that something has happened that the compiler was unprepared for. Sorry that isn't very helpful to most people, but it may help to check your characters sets.
one more case that can lead to this error which just took me hours to track down: a failable initializer that always returns nil.
i had an initializer that looked like this:
init?(object: MyObject) {
if object.importantProperty {
// initialize
}
return nil
}
when what i meant was:
init?(object: MyObject) {
if object.importantProperty {
// initialize
}
else {
return nil
}
}
fixing the initializer made the error go away.
If using Core Data:
I had a Core Data entity for which I created the NSManagedObject subclasses (with Xcode's help). In addition, the entity was configured to generate code automatically (see screenshot), so basically 2 classes existed during runtime. Just switch the option to Manual/None and it won't generate it.
This error occurred for me after I noticed that a few of my .swift files were inexplicably in the wrong directory -- one level above my Xcode project directory. When I noticed this, I moved them into the main project directory and cleaned the project, thinking everything would be fine. However, upon building the project I got the above-mentioned "failed with exit code 1" error. Just above the error message it listed the files I had just moved, indicating that it couldn't find them in the directory where they used to be. In addition to the error message, the files I moved were now showing up as red in the file navigation pane.
For each of the files in question what I did to resolve this was:
- Select the file from the list of files in the Xcode file navigation pane,
- Click on the little page icon in the rightmost pane of Xcode, which opens a file attributes pane,
- Click on the little folder icon underneath where it says "Location" in the file attributes pane,
- Choose the new location for the file,
- RESTART Xcode for the above changes to really do anything.
this error comes from missing files so the compiler couldn't find the files and keep alerting.
Follow these steps to rebuild your app:
Look up for the red and invisible files within workspace
Remove their reference
Re-add files
Re-compile
I experienced this error after performing a git merge. I solved new Xcode warnings and the project can be compiled.
Xcode 7.2.1 is used in my case.
In my way the error was due to UIDevice.currentDevice() in ((UIDevice.currentDevice().systemVersion as NSString).floatValue >= 8.0)
After commenting this all starts work fine.
XCode 7.2
in my case , at your project target Build Setttings, in Other Swift Flags,jsut delete the String "-serialize-debuggin-options"
enter image description here
I had a resolution very similar to RyanM, where with an excess of hubris I tried to assign a variable to the default value of an inner function:
Fails to compile (though does not crash SourceKit):
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func itemCell(_ indexPath: IndexPath = indexPath) -> UITableViewCell {//...}
Succeeds:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
func itemCell(_ indexPath: IndexPath) -> UITableViewCell {//...}
One possible reason that this can happen is perhaps because you have deleted a file but not removed references to it. This will mess up the pbxproj file. I would check to see if that is the case.
check "Development Pods" Folder all listed Frameworks path.
In my case swift development snapshot was selected instead of xcode 9.2. here are the steps and image.
keep xcode on screen and click on xcode top menu bar.
Than go to toolchains option and check on xcode 9.2. thats it.
Happy Coding!!!
So, I had the above and narrowed it down to a TFS issue with locking the file but only when I pasted or did any other edits besides small copies or manual typing. I noticed the original file would compile, but my edits wouldn't, even though they were syntactic OK. Also related is unable to save document: xcode The document "..." could not be saved
The fix for both was:
Duplicate working version.
Paste fully-merged new code into duplicate.
Copy and paste old file over new one. (I personally just renamed the old one to something else, then pasted duplicate and renamed it, too. Guessing both work since I pasted directly earlier for reverts during tests to see).
Voila. Lazy way to bypass merge-locking issue. Apparently full file-pastes are just fine, while edits aren't. Shared since the other answers don't seem to be as lazy as this. ;)
Note: I am suspecting a non-UTF-8 character made its way somewhere, but pastes worked in older versions so I don't know where, or if relevant.
In my case, the error was the result of missing files that were generated by Xcode. I tried the regular clean Opt+Shift+K and it didn't clean up all the errors. I found a post on the Apple Developer site that recomended going to the Product Menu in Xcode, holding down the opt key, and selecting Clean Build Folder. This appears to be a more comprehensive build as it pops up a modal dialog for you to confirm.
Just go to the "project setting" and click on the "build phaces" after that you will find targets in that u have to delete the test file like my project name "WER" so its showing like this WER&TEST so just delete that and clean ur project and run .........

swift failed with exit code 1 while compiling in Xcode - possibly related to Bridging-Headers

I have an Obj-C Project I'm trying to migrate to Swift. I did succeed with various classes but recently ran into an issue I can't seem to make sense of. When I try to compile my current code base I get the following (SUPER UNHELPFUL ERROR MESSAGE)
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
My only assumption is its somehow related to my bridging-headers but Xcode isn't giving me enough information to figure out if this is actually true.
I'm using Cocoapods to add the CorePlot to my project. I'm trying to migrate the following class to Swift:
Obj-C Class (ScatterPlotContainer.h)
#import <Foundation/Foundation.h>
#class CPTScatterPlot;
#interface ScatterPlotContainer : NSObject
#property (nonatomic, strong) CPTScatterPlot *ahrsAlt;
#property (nonatomic, strong) CPTScatterPlot *calibration;
#property (nonatomic, strong) CPTScatterPlot *coreAlt;
#property (nonatomic, strong) CPTScatterPlot *pitch;
#property (nonatomic, strong) CPTScatterPlot *roll;
#property (nonatomic, strong) CPTScatterPlot *slip;
#end
Obj-c Class (ScatterPlotContainer.m)
#import <CorePlot/CPTScatterPlot.h>
#import "ScatterPlotContainer.h"
#implementation ScatterPlotContainer {
}
#end
Swift Conversion
import Foundation
class ScatterPlotContainer : NSObject {
public var ahrsAlt : CPTScatterPlot;
public var calibration : CPTScatterPlot;
public var coreAlt : CPTScatterPlot;
public var pitch : CPTScatterPlot;
public var roll : CPTScatterPlot;
public var slip : CPTScatterPlot;
}
My bridging headers file
#import <CorePlot/CPTScatterPlot.h>
What I've tried thus far
When I comment out the #import <CorePlot/CPTScatterPlot.h> from the Bridging headers file - I get an error in swift because it doesn't know what CPTScatterPlot is
I've also tried #import <CPTScatterPlot.h> which didn't work either.
Thoughts
So the only thing I can think of is perhaps because I'm using a cocoa pod there is some sort of module name I need to add. The error message really isn't that useful. Does anybody have a suggestion about some blaring error I've made or how to get a more descriptive error message to figure out what is going on?
I did the same all answer says but mine issue was not resolved. I did figured out that issue was related to broken function call.
A function syntax was not wrong but its calling mechanism was wrong.
To check the exact error for this issue check following:
Select issue navigator > Click on error will show logs for error > In that select All Messages tab.
This will show all detail logs for this error.
Scroll down and You got logs like, in my case
So, by reading this I figure out that something wrong with function calling. I browse my code and resolved it, Below was correct and wrong code.
Wrong Way:
var region = MKCoordinateRegionMake(self.mapView.userLocation.coordinate, span)
// It will not shown error here but when you build project compiler shows error.
Right Way:
let region = MKCoordinateRegion(center: self.mapView.userLocation.coordinate, span: span)
I run into this last night and nothing above was solving my problem.
I was about to do something very bad at my laptop when I saw, all by pure luck, that ONE (1) file was is text encoding set to UTF-16 ?!?! WTF??
This was the last file I was working on, and probably, one bad cut/paste "import" a strange character into the arena. I did a cut/paste of my code in this file to a bare bone text editor. I deleted the file, recreate it and paste back my code... and voilà! it work.
So do the above, but also check your file encoding! :-)
I had the same error message.
What helped, was to set the optimization level in the swift compiler settings to None.
This is not really a solution for me and I think that's one of the many bugs in the swift compiler.
Another solution for this issues is to check that you don't have 2 or more files with the same file names. It solved the problem for me.
Thank you #Kampai for the advice on going through the error log message. I read through, and some files were missing:
<unknown>:0: error: no such file or directory:
Somehow, some files were removed during a pull from GitHub. The files are in the directory, but not in the Xcode project.
Right click on a folder and click 'Add files to ...' to manually add missing files to Xcode. That fixed the problem for me.
This happened to me several times already, but now I know how to fix it \o/
I was getting the same error for including this code in a didSet block:
didSet {
// Test whether this view is currently visible to the user.
if super.isViewLoaded() && (super.view.window != nil) {
// (build fails even if this block is empty)
}
}
It took a lot of trial/error to hunt this down. Removing super. allowed the build to proceed.
had a horrible time with this bug for over 3 hours by meticulously going from file to file and reverting the changes and seeing if that file had the issue in it. I tried the first answer but didn't give me any answers. Found the issue and it was because I had a non computed property named the same as a computed property of a subclass. I really hope the debugger becomes more robust with handling these sorts of cases in future updates :(
Simply deleting derived data and cleaning helped me
1) Identify the file there the problem is. You can copy and paste the compilation instruction to the console and the last screen will contain the error description. Note the pid number there the problem was identified. Then scroll up and find the pid and related instruction - there will be one file per pid, so you will find the file you have problem it.
2) Look through the file and check all you last changes. If you have git initialized you can use
git diff <file name>
As for #Kampal, I'm still struggling to figure out how much to specify in a function call. For instance, creating a UIColor object sometimes requires that UIColor be specified, and sometimes doesn't.
These both work:
playButton.backgroundColor = .darkGrayColor()
playButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal)
This yields the exit code 1 error on compilation, without any debugger warning. #time-sucking debug vortex
playButton.setTitleColor(.whiteColor(), forState: UIControlState.Normal)
So I have a new rule: when using a function that takes more than one parameter, be explicit.
Now back to playing swift: AVOID THE VORTEX
Since everyone else has been showing theirs, I'll show mine:
class Foo : UIView {
var pathPosition:Double = 0.0 { didSet {
pathPosition = min(max(0.0, pathPosition), 1.0) // crashes if this line is present
self.pathPosition = min(max(0.0, pathPosition), 1.0) // but not here
}}
}
Incredibly, this does not come up in Playground, but does fail when placed in code in a framework. Although it is legal syntax (used to work, still works in playground), the Swift compiler seems to want pathPosition to be qualified with self.. Note that is (relatively) old code and used to compile, maybe something broke in 6.1.
Edit:
I feel like I am going insane, but it feels like there is a greater complexity problem going on here, where surrounding code can impact this problem. I saw things compile last night, changed some code and settings again today, and it failed on me again. Today, I had to hack in a bunch of really stupid code to get it to work:
var pathPosition:Double = 0.0 { didSet {
// bug: insane!! - have to clobber the value before resetting!
let bugOldValue = pathPosition
self.pathPosition = 1.0 // fails without this nonsensical line!
self.pathPosition = min(max(0.0, bugOldValue), 1.0)
}}
For what it's worth, the actual error message I got, per the helpful instructions above, was:
PHI node has multiple entries for the same basic block with different incoming values!
%14 = phi double [ 1.000000e+00, %10 ], [ %11, %10 ], [ 1.000000e+00, %9 ], [ 0.000000e+00, %9 ], !dbg !4818
label %10
double 1.000000e+00
%11 = phi double [ %7, %entry ], !dbg !4815
LLVM ERROR: Broken function found, compilation aborted!
I'm scared for tomorrow.
I just had this same error, the problem was that I had overridden a method with a non-optional parameter and had made the parameter optional in the override. (the method parameter below)
func logNetworkCallDurationForMethod(method:String, path:String, milliseconds: UInt) {
}
override func logNetworkCallDurationForMethod(method:String?, path:String, milliseconds: UInt) {
}
Ran into this issue today actually. Was the result of a recent pull from git on a project where a file had been deleted, but it didn't update in my local project.
Clicking on the error brought up the location of the "missing" file, went and deleted it's reference in the Project Navigator. Fixed the error, did a clean, and compiled successfully.
This happened to me when trying to reference a method from an inmutable protocol argument(by mistake, I thought the member was a property):
Having an interface as follows:
public protocol NSValidatedUserInterfaceItem {
func tag() -> Int
}
Compilation crash
func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
print(anItem.tag) // oopsie, tag is a function
return false
}
Compilation success
func validateUserInterfaceItem(anItem: NSValidatedUserInterfaceItem) -> Bool {
print(anItem.tag()) // this is cool for swift
return false
}
This happened to me and after reading the log in issue navigator I found out that I have two swift files with same name. This was creating the issue and I was getting build failed.
I got this error due to a missing file in my project. Added this file again and voila everything worked.
In my case it was wrong method overriding. Base class:
open func send(_ onSuccess: #escaping ((SomeType) -> Void)) -> SomeType { }
Subclass:
open override func send(_ onSuccess: ((SomeType) -> Void)) -> SomeType { }
As you see #escaping is missing. Swift3 converter in XCode8 doesn't consider inheritance relations, moreover, that type mistakes aren't marked as errors.
In My Case it was Simulator bug just uninstall app from simulator and clean project then run project.
I had accidentally dragged symlinks (aliases) to source files into the project instead of the actual files.
I had CoreData generated files twice (and added myself). Check the files are not duplicate.
Unfortunately this error is often caused by a glitch inside Swift's compiler. It is not always easy to find the reason. If cleaning doesn't work, my suggestion is to try to comment the last code you wrote (even the whole file if necessary). Usually commenting the last code you entered would restore the compilation and you'll get more meaningful errors. From there on you have to try to uncomment the code piece by piece until you get to the instruction which caused this error. The Swift compiler is still pretty young and from time to time it reports weird errors. These kind of errors are completely useless, because instead of helping the developers they only confuse them even more. I would suggest Apple to change the compiler to give more detailed information and avoid this annoying error from appearing anymore.
NSString const *kGreenColor = #"#00C34E";
I had above line in my Constant.h file. which was meant for preprocessors only.
Removing that line worked for me.
moving the Bridge file to project level resolve my problem.
In my case I had renamed a file. After committing I found that the file name still hasn't changed in the Xcode project (not sure why), the file was greyed out. Changing the name and committing again did the trick.
So we have to keep an eye out for this error, when making changes to files using source control.
In my case deleted a couple of files directly from SourceTree but their reference was still there in Xcode. Logs show their names. Removed them and error went away.

Duplicate symbols for architecture x86_64 under Xcode

I now have the same question with above title but have not found the right answer yet. I got the error:
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
duplicate symbol _OBJC_METACLASS_$_MoboSDK in:
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Intermediates/TestMoboSDK-Client.build/Debug-iphonesimulator/TestMoboSDK-Client.build/Objects-normal/x86_64/MoboSDK.o
/Users/nle/Library/Developer/Xcode/DerivedData/TestMoboSDK-Client-cgodalyxmwqzynaxfbbewrooymnq/Build/Products/Debug-iphonesimulator/libMoboSDK.a(MoboSDK.o)
ld: 75 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Any help is appreciated.
Finally I find out the reason of this error cause I added -ObjC to the Other Linker Flags. After remove this value then I can build my project successfully, but I don't know why. Can anyone explain this?
For me, changing 'No Common Blocks' from Yes to No ( under Targets->Build Settings->Apple LLVM - Code Generation ) fixed the problem.
Stupid one, but make sure you haven't #imported a .m file by mistake somewhere
75 duplicate symbols for architecture x86_64
Means that you have loaded same functions twice.
As the issue disappear after removing -ObjC from Other Linker Flags,
this means that this option result that functions loads twice:
from Technical Q&A
This flag causes the linker to load every object file in the library
that defines an Objective-C class or category. While this option will
typically result in a larger executable (due to additional object code
loaded into the application), it will allow the successful creation of
effective Objective-C static libraries that contain categories on
existing classes.
https://developer.apple.com/library/content/qa/qa1490/_index.html
In my case, I just created a header file to define constant strings like this:
NSString *const AppDescriptionString = #"Healthy is the best way to keep fit";
I solved this scenario by using static:
static NSString *const AppDescriptionString = #"Healthy is the best way to keep fit";
Happens also when you declare const variables with same name in different class:
in file Message.m
const int kMessageLength = 36;
#implementation Message
#end
in file Chat.m
const int kMessageLength = 20;
#implementation Chat
#end
I have same problem.
In Xcode 7.2 in path Project Target > Build Setting > No Common Blocks, i change it to NO.
I found the accepted answer touches on the problem but didn't help me solve it, hopefully this answer will help with this very frustrating issue.
duplicate symbol _OBJC_IVAR_$_BLoginViewController._hud in:
17 duplicate symbols for architecture x86_64
"Means that you have loaded same functions twice. As the issue disappear after removing -ObjC from Other Linker Flags, this means that this option result that functions loads twice:"
In layman's terms this means we have two files in our project with exactly the same name. Maybe you are combining one project into another one? Have a look at the errors above the "duplicate symbols" error to see which folder is duplicated, in my case it was BLoginViewController.
For example, in the image below you can see I have two BImageViewControllers, for me this is what was causing the issue.
As soon as I deleted one then the issue vanished :)
This occurred on me when I accepted "recommended settings" pop-up on a project that I develop two years ago in Objective-C.
The problem was that when you accepted the "recommended settings" update, Xcode automatically changed or added some build settings, including GCC_NO_COMMON_BLOCKS = YES;.
This made the build failed with the duplicate symbol error in my updated project. So I changed No Common Block to NO in my build settings and the error was gone.
I experienced this issue after installing Cocoapods. Now happens everytime I update some pods. Solution I've found:
Go to terminal:
1) pod deintegrate
2) pod install
Also, check the item "Always Embed Swift Libraries" in your Build Settings. It should be "faded" indicating it is using the default configuration. If its set to a manual YES, hit delete over it to revert it to the default configuration. This stopped the behavior.
Fastest way to find the duplicate is:
Go to Targets
Go to Build Phases
Go to Compile Sources
Delete duplicate files.
Go to Targets
Select Build Settings
Search for "No Common Blocks", select it to NO.
It worked for me
Following steps solved the issue for me.
Go to Build Phases in Target settings.
Go to “Link Binary With Libraries”.
Check if any of the libraries exist twice.
Build again.
Remove -ObjC from Other Linker Flags or
Please check you imported any .m file instead of .h by mistake.
Update answer for 2021, Xcode 12.X:
pod deintegrate
pod install
Hope this helps!
My situation with some legacy project opened in Xcode 7.3 was:
duplicate symbol _SomeEnumState in:
followed with list of two unrelated files.o, then this was repeated couple of times, then finally:
ld: 8 duplicate symbols for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
What solved it for me was changing enum declaration from:
enum SomeEnumState {
SomeEnumStateActive = 0,
SomeEnumStateUsed = 1,
SomeEnumStateHidden = 2
} SomeEnumState;
to this:
typedef NS_ENUM(NSUInteger, SomeEnumState) {
SomeEnumStateActive = 0,
SomeEnumStateUsed = 1,
SomeEnumStateHidden = 2
};
If somebody has explanation for this, please enlighten me.
Defining same variable under #implementation in more than one class also can cause this problem.
In my case, there were two file by same name in the location
Targets > Build Phases > Compile Sources and delete any duplicate files.
For me during the Xcode8 recommended project settings update "No Common Blocks" to YES which causes this issue.
My problem was that I had 5 duplicate symbols for architecture x86_64. After reading this post and their answers, I try with the common solution about change GCC_NO_COMMON_BLOCKS = YES to NO
But, instead of working for me, I went from 5 duplicates to 1 duplicate...
So, I paid attention to that last error, and I realized what was my problem, and it was an "incompatibility" with these packages (I had both in package.json):
rn-fetch-blob
react-native-blob-util
The message was clear about it, and I remove rn-fetch-blob because I have not idea why it was in my project, but, I only used with jest and delete it, it wasn't a problem.
So, after removing that package, and run yarn again, problem solved... And without changing the GCC_NO_COMMON_BLOCKS
Today , I got the same error . The error's key word is duplicate. I fix it by:
1. Remove the duplicate file at Build Phases-->Compile Sources
2. If you can not remove it at Build Phases, you need find the file at your project and remove the reference by DELETE :
3. Add the file to your project again
4. Add the file's .m to your Build Phases-->Compile Sources again
5. Build your project, the error will disappear
Another silly mistake that will cause this error is repeated files. I accidentally copied some files twice. First I went to Targets -> Build Phases -> Compile sources. There I noticed some files on that list twice and their locations.
Make sure you haven't imported a .m file by accident, you might want to delete your derived data in the Projects Window and then build and run again.
I got the same error when I added a pod repository
pod 'SWRevealViewController'
for an already added source code (SWRevealViewController) from gitHub. So, the error will be fixed by either removing the source code or pod repository.
Case # 2:
The 2nd time, this error appeared when I declare a constant in .h file.
NSString * const SomeConstant = #"SomeValue";
#interface AppDelegate : UIResponder <UIApplicationDelegate> {
...
...
None of above solutions works for me, I just fixed it myself.
I got duplicate symbol of my core data model which I make it myself, but
in my .xcdatamodeld inspector, I choose Class Definition of Codegen property, I guess that's what's wrong with. Then I choose Manual/None,it got fixed.
Hope this can be helpful for you!
For anyone else who is having this issue, I didn't see my resolution in any of these answers.
After having a .pbxproj merge conflict which was manually addressed (albeit poorly), there were duplicate references to individual class files in the .pbxproj. Deleting those from the Project > Build Phases > Compile Sources fixed everything for me.
Hope this helps someone down the line.
Similar to Juice007, I had declared and initialized a C type variable in two different .m files (that weren't imported!)
BOOL myVar = NO;
however, this method of declaring and initializing a variable, even in .m, even in #implementation grants it global scope. Your options are:
Declare it as static, to limit the scope to class:
static BOOL myVar = NO;
Remove the initialization (which will make the two classes share the global var):
BOOL myVar;
-(void) init{
myVar = NO;
}
Declare it as a property:
#property BOOL myVar;
Declare it as a proper iVar in the #interface
#interface myClass(){
BOOL myVar;
}
#end
In my case I had two main() methods defined in my project and removing one solved the issue.
The answers above didn't work for me. Here's how I got around it:
1) in finder, delete the entire Pods folder and Podfile.lock file
2) close the xcode project
3) run pod install in the terminal
4) open the xcode project, run the clean build command
Worked for me after that.
Because I haven't seen this answer:
Uninstall and reinstall your podfiles! Remove or uninstall library previously added : cocoapods
I've run into this issue over 3 times building my app and every time this is what fixes it. :)
I've just had this error as well. Found that the problem was variables declared with global scope, with the same names, were being repeated throughout the files being compiled into the program. Once changing the global variables to local scope to the pseudo-main function the error was resolved.

Xcode 5 error: "Malformed or corrupted AST file: mismatched umbrella header in submodule"

After adding StoreKit to my Xcode 5 project, I now see...
"Malformed or corrupted AST file: mismatched umbrella header in submodule"
...whenever I've imported any header from StoreKit. I haven't changed those system headers, and clearing derived data and the usual Clean Build Folder fix doesn't work either, nor does restarting Xcode change anything.
I see in the Clang sources where the error is being reported, but I can't tell why. Here's the relevant Clang code from http://clang.llvm.org/doxygen/ASTReader_8cpp_source.html:
case SUBMODULE_UMBRELLA_HEADER: {
03728 if (First) {
03729 Error("missing submodule metadata record at beginning of block");
03730 return true;
03731 }
03732
03733 if (!CurrentModule)
03734 break;
03735
03736 if (const FileEntry *Umbrella = PP.getFileManager().getFile(Blob)) {
03737 if (!CurrentModule->getUmbrellaHeader())
03738 ModMap.setUmbrellaHeader(CurrentModule, Umbrella);
03739 else if (CurrentModule->getUmbrellaHeader() != Umbrella) {
03740 Error("mismatched umbrella headers in submodule");
03741 return true;
03742 }
03743 }
03744 break;
03745 }
It evidently compares my imported umbrella header
#import <StoreKit/StoreKit.h>
to something else, but I can't determine what that something else is.
Has anyone else encountered this, and hopefully found a way to resolve it?
I was able to encounter this problem, following the direction mentioned by John above doesn't work for me. I was able to solve this problem by doing the following:
close all open XCode projects.
Delete all the folders inside Derived Data folder.
How to go to Derived Data folder? just right click on your Product build and show finder, browse through the hierarchy of folders and look for Derived Data.
Hope this helps. This seems to be a bug in Xcode? but not sure.
This solved it for me:
go to project build settings
scroll down to LLVM 5.1 Language Modules
set Enable Modules (C and Obj C) to NO
In Xcode go to Window->Organizer->Projects select your project and press delete button next to Derived data. Just did it (and it worked) with information the following question:
fatal error: malformed or corrupted AST file - Xcode
In your Project folder there would be couple of folders named Derived Data and build. Just remove those folders and the problem would be resolved. These folders get created automatically once you open your XCode.

Resources