category in separate file is giving me "linker command failed with exit code 1 (use -v to see invocation)" - ios

I am trying to build a category for a project (my first time). If I implement the category in the model (LTUser), it works fine but, if I put it into a different file called LTUser+Additions(.h / .m), it gives me "linker command failed with exit code 1 (use -v to see invocation)" error with "6 duplicate symobols for architecture i386". I'm not even sure where I would add -v on invocation. I have included a screenshot of the error. What am I doing wrong with my category?
LTUser+Additions.h
#import "LTUser.h"
#interface LTUser (Additions)
-(void)saySomethingMore;
+(void)tellMe;
#end
LTUser+Additions.m
#import "LTUser+Additions.h"
#implementation LTUser (Additions)
-(void)saySomethingMore{
NSLog(#"I want to say something more to you from within category");
}
+(void)tellMe
{
NSLog(#"I want you to tell me from the category");
}
#end
edit #1
so just adding an empty category via: File -> New -> File -> 'select Objective C Category' -next-> Set name to Add and Category on LTUser
It makes the .h / .m files but if I compile this, it gives me the same error. This is making me think that adding / deleting category files has mucked up the project but still not sure.

That strongly looks as if you #import a .m-file instead of the .h-file somewhere.
The same error would also occur if you put the implementation into the .h file
(which you should never do), and import the .h file from more than one place.

So this app was originally to just mock something up and I did a shortcut that I've done several times before but not had an issue. Rather than a .h / .m file, I put both the header and the implementation in the .h file. This worked ok when just rendering a simple object but when I added a category, it cause the above blow-up. It should probably be mentioned in the docs that, when adding a category, it MUST exist with the .h / .m file structure.

Related

Header file issue with xcode 7

I have a subclass of NSObject, but I have a problem with header file, when I run the project, it shows me this:
and it allows me to add this, but directly this logical error is returned: "#end must appear in Objective-C context"
I precise that with Xcode6 I didn't have that issue with this Does anyone knows how to fix this frustrating issue ?
EDIT:
that's a constants file, do not pay attention to the file's name, here is .m file:
#import "CUSBoxes.h"
const int defaultCount = 10;
const long int repeat = 25000;
const NSString *defaultDescription = #"If any layout issue is related, change default values of each box you want to display";
#implementation CUSBoxes
#end
Usually this error causes you missed #end or invalid character in one of the .h file you used in your project. I have came across with this error, this error not exist in same files it throws check for other header files to fix this issue.
1) You might missing #end in any of the Header file.Check one by one all .h file which has #interface section,should be ended with "#end".
2) If everything looks good then Try cleaning project or Restart Xcode.(In my case,It worked).

error in ACAccount.h in Simulator-iOS 7.1

I'm trying to build and test an app with the xcode simulator, but during the building I get errors in ACAccount.h, ACAccountType.h, etc.
The "strange thing" (at least for me as i'm completely new in using xcode) is that if I click on the .h files with errors they do not appear under the project code but under
Simulator - iOS 7.1-> Frameworks -> Accounts -> ACAccount.h
which is unmodifiable.
Examples of the errors are:
line:
#class ACAccountType,ACAccount Credential; --> Illegal interface qualifier
ACCOUNTS_CLASS_AVAILABLE(NA, 5_0)
#interface ACAccount : NSObject -->Objective-C declarations may only appear in global scope
If the .h are predefined files.. How can I solve these errors?
Many thanks in advance!
Generally when you encounter items like the 'illegal interface qualifier' in system provided headers it indicates that you've placed the #import statement within an #interface block, like:
#interface foo ()
#import <Accounts/ACAccount.h>
#end
This generates errors about the content in the file being imported (e.g. your illegal interface qualifier error), while the actual issue is that putting #import statements within an #interface block is invalid.
You should put #import statements together at the top of the file, outside of any #interface or #implementation blocks.
If you put it into the #implementation section, the error becomes:
error: Objective-C declarations may only appear in global scope

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.

Multiple ViewController inheritance causes Apple Mach-O Linker Error

I'm setting up a base view controller called "BHAccountBaseViewController" and two other views that inherit from some basic functionality from the base controller.
"BHAccountBaseViewController" Inherits from "UIViewController"
"BHAccountViewController" (implements UITextFieldDelegate) and Inherits from "BHAccountBaseViewController"
Lastly I have one recently created class that I called "BHCreateProfileViewController" every time that I just simply include #import directive to "BHAccountBaseViewController" to inherit from this class Xcode fails to compile due to APPLE MACH-O LINKER ERROR!
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Thoughts? these are my three header files
BHAccountBaseViewController
#import <UIKit/UIKit.h>
#import "BHFileManager.h"
#interface BHAccountBaseViewController : UIViewController
#end
BHAccountViewController
#import "BHAccountBaseViewController.h"
#interface BHAccountViewController : BHAccountBaseViewController<UITextFieldDelegate>
#end
BHCreateProfileViewController
#import "BHAccountBaseViewController.m"
#interface BHCreateProfileViewController : UIViewController <UITextFieldDelegate>
#property (strong, nonatomic) id user;
#end
if I comment out the import on the last file the linker error goes a way! but I want to be able to inherit from my base clase ... thoughts?
Help would be much appreciated!
In implementation of BHCreateProfileViewController given above, I found the code looks like getting wrong at first line. What about fixing it as following:
#import "BHAccountBaseViewController.m"
to
#import "BHAccountBaseViewController.h"
and I wonder why BHCreateProfileViewController comes to inherit from UIViewController not BHAccountBaseViewController. Could you explain that?
This might be due to the retain cycle deadlock problem. You have to use forward class declaration for this i.e you can try #Class instead of #import. Please refer to these limks :
Objective-C: Forward Class Declaration
#class vs. #import
These might help.
In the compilation time your compiler would actually look for your interface files instead of implementation file.Compiler does not bother even if .m file is not available. So while importing you are supposed to import .h instead .m.

Unknown type name when trying to include a library

I'm trying to use Novocaine in an iPhone application I'm building. I can't figure out how to get around this error I'm getting:
Unknown type name 'RingBuffer'
Here's my file structure:
...with those files under Novocaine being the ones pulled from the Github repo for Novocaine. Here's my header file for DDViewController.
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import "UICoordButton.h"
#import "Novocaine.h"
#import "RingBuffer.h"
#import "AudioFileReader.h"
#import "AudioFileWriter.h"
#interface DDViewController : UIViewController
{
RingBuffer *ringBuffer;
Novocaine *audioManager;
AudioFileReader *fileReader;
AudioFileWriter *fileWriter;
}
- (IBAction)changeColor:(id)sender;
- (IBAction)changeColor2:(id)sender;
#end
I've tried a solution that I found on another question, which suggests that this should work:
#class RingBuffer;
#interface DDViewController : UIViewController
{
...
But that just gives me Redefinition of 'RingBuffer' as a different kind of symbol.
How can I fix this problem and use RingBuffer?
RingBuffer is a C++ class. I recommend you change the extension of your Objective-C files from .m to .mm which will make them Objective-C++
Found the answer (or I guess a combination of answers):
Follow coryalder's advice for setting the compiler default to Objective-C++ as described here.
Also, change all .m files to .mm files, and finally add -fno-objc-arc compiler flags to all the .mm files -- which is described in detail here.

Resources