Xcode does not compile category - objective-c

I have added a category to my Xcode project using File > New > Category. I noticed that in Xcode the code completion does not work and even if I add garbage to the class the compiler does not complain.
This is my class:
#import "MyClass+Category.h"
#implementation MyClass (Category)
a
sdf
ads
f#asdlkfjhaslfäasdlföjölfasdf
#end
The .m file has the correct target membership and is in the Compile Sources build phase. What is going wrong. I also tried to restart Xcode to no avail.

Well, that's embarassing. I did not have the proper target set so it was my framework that was being compiled instead of the code I was writing.

Related

Detect Xcode project development language

We can create a new Xcode project using Objective-C or Swift.
I want to detect, which language was selected when a project was created?
Projects can be a mix of Objective-C and Swift, but I am concerned about the language, selected during project creation.
May be it can be through pbxproj file or other better way.
Thanks.
ObjC project always contains the entry point that is main function.
Usually it is inside main.m file but it is not necessary. Developer can replace it to any name.
I tried 2 simple projects. One is in ObjC and second one is in Swift.
When I was tried to add new file the Xcode offered Swift language for Swift project and Obj-C for Obj-C project file.
Next I removed in Swift project AppDelegate.swift file and added AppDelegate.h and AppDelegate.m and (sic!) main.m files. of course I had to create bridging file for obj-c.
Which contains
#import "AppDelegate.h"
I was able to compile this project but when I tried to add new file Xcode offered me to add Objective-C file. But initially the project was created as Swift project.
I did similar manipulation for Obj-C project.
I removed AppDelegate.h and .m file as well as main.m and added AppDelegate.swift
I was asked to create bridge file and did empty file.
Next I went to «Build Settings» and switched Define Module parameter to YES value. (Without this I got linker error).
After it I was able to build and run this initially obj-c project which has AppDelegate in Swift now.
When I tried to add a new file the Xcode offered me to add new Obj-C file too.
So. It looks like you cannot detect initial language based on a parameter in Xcode because project can be always corrected. I think that rarely the developer will try to replace AppDelegate in a project and add\remove main entry point.
Hope this helps you.

#import "Project-Swift.h" File does not refresh

I have a project with Swift and Objective-C code. In my current project I have the problem that the #import "Project-Swift.h" file does not refresh if I add new Swift modules.
#import "Project-Swift.h" // does not refresh if I add .swift files
So in the Objective-C universe, the swift code is not available. the files exists, but does only contains default #defines etc. No project related stuff.
Clear Cache, rebuild, delete Derived Data does not help.
Solved it. Forgot #objc(<class>). It is mandatory.
Details here (Migrating)
Migrating Objective-C Code to Swift
And here (Swift Type Compatibility)
Interacting with Objective-C APIs
In my case it worked by building for the other target I had on my project:
Check you have prefixed your class with #objc
Choose the other scheme (target)
Build || Run
The bridging file updates
Change the scheme back to the target I was working on
Just use #objc before Swift Class that you want to use in Object-C code then Build the project.
For example:
#objc class Person : NSObject
{
// Swfit code goes here.
}
Now #import "Project-Swift.h" will be available in you project to use.

This class requires automatic reference counting

I am trying to add iRate from https://github.com/nicklockwood/iRate to my app.
After adding file i get this error before even running the project.
#import "iRate.h"
#import <Availability.h>
#if !__has_feature(objc_arc)
#error This class requires automatic reference counting
#endif
http://i.stack.imgur.com/amxPM.png
The solution in this issue in this link https://github.com/nicklockwood/iRate. It is for ARC Compatibility.
As of version 1.7, iRate requires ARC. If you wish to use iRate in a non-ARC project, just add the -fobjc-arc compiler flag to the iRate.m class. To do this, go to the Build Phases tab in your target settings, open the Compile Sources group, double-click iRate.m in the list and type -fobjc-arc into the popover.
If you wish to convert your whole project to ARC, comment out the
#error line in iRate.m, then run the Edit > Refactor > Convert to Objective-C ARC... tool in Xcode and make sure all files that you wish to use ARC for (including iRate.m) are checked.

Where is the reference to the .m file?

I created a new Xcode project (iOS application, Tabbed Application).
Now I'm seeing one sample code that Xcode generated for me (that I did not touch at all) and of course, it works on the iPhone simulator.
I am going through the code and though I'm seeing references to the .h files, I do not see any reference in any of the created files to .m files. (as in
#import "MRTAppDelegate.h"
#import "MRTFirstViewController.h"
#import "MRTSecondViewController.h"
Does the compiler just process whatever .m files you add to the project? Is there a list where they are all accounted for?
p.s. As it is obvious I also have little Objective C background, whatever I could carry from my university C classes.
if you go to build phrases -> compiled sources all the .m as specified there.
You're right on the basic assumption that Xcode will link the header and implementation for you. Just make sure you're added the .m file to your build sources and Xcode will do the rest.
You're also always going to #import the header file, and not the implementation file, in other classes.

Xcode and ZXingWidget: Importing Obj-C header files within .mm files

I use XCode 4.0 for developing an iOS project.
In my current project, I added the ZXingWidget library correctly but I had to change the .m extension in .mm in the class which implements MyViewController in order to import "QRCodeReader.h" and "ZXingWidgetController.h", the two headers I need to use the ZXing library.
Now, if in the same MyViewController.mm I want to also import my AppDelegate (which is obviously an Objective-C class), I receive a compile error which Xcode signals into other header files that are recursively added by my AppDelegate. These errors are of these kinds:
GCC 4.2 Error - Instance variable '<unnamed'> has unknown size
Expected ';' before 'public'
Expected unqualified-id before 'public'
I believe this is because I don't manage correctly the Objective-C and C++ mixing, and as I comment the line #import "MyAppDelegate.h" the error disappears.
Is there something I can do to fix this problem? Also a workaround could do!
Thanks!
Edit 1: The error does occur only if I import the App Delegate header in that .mm file. In every other .m file of my project I can successfully import the same App Delegate without errors. I feel there's something wrong with the .mm extension and GCC.
SOLVED: I had another external library interface which used this code
#interface Name : NSObject {
#private
#public
id var1;
int var2; // ecc...
}
And the error was pointing to the keyword #public. I commented the #private keyword and everything went just fine! I would be happy if someone could explain me the reason of this.