Calling an external class in iOS - ios

I have this class for button which was added to my project workspace. I had
linker error ( Apple Mach-o Linker Error)
Then again i opened a new project and added this class.
In my ViewController.h
#import <UIKit/UIKit.h>
#import <UIView+Glow.h>
#interface ViewController:UIViewController
#property(non atomic,strong) IBOutlet UIView *testView;
end
And in my ViewController.m
Added is the screenshot
#importViewController.h
-(void) viewDidLoad{
[super viewDidLoad];
[testView startGlowing]
}
I had
*unrecognized selector sent to instance error
This is the class
I suggest you use the Glow Category of UIView made by secret lab.
Any suggestion on how to call this class?
attached are the screenshots of the issue

If you have copied UIView+Glow.h into your project, you should use this to import it:
#import "UIView+Glow.h"
You should not use the angle brackets (<UIView+Glow.h>) to import headers that are part of your project.
If you have not copied UIView+Glow.m into your project, you need to do so.
If you have copied UIView+Glow.m into your project, you need to make sure it is included in the “Compile Sources” build phase of your target.
The easiest way to check is to open UIView+Glow.m in the primary editor. Then choose the View > Utilities > Show File Inspector menu item. Look at the File Inspector (on the right side of the Xcode window). Make sure it's showing information for UIView+Game.m. Then look at the “Target Membership” section. Make sure the checkbox next to your target is checked.
Update
The three linker errors in your final screenshot happened because you haven't added the QuartzCore framework to your project. This is the framework that contains the Core Animation classes.
If you don't know how to add a framework to your project, look at How to "add existing frameworks" in Xcode 4?.

Make sure that you use the following line at the top of the implementation file where you want to use the glow methods:
#import "UIView+Glow.h"

Related

Static library, bundle and IB Designable

I'm trying to use the IB Designable and IB Inspectable in my UIButton but seems there are some errors.
In the Issue Navigator, the bundle file:
Storyboard :
IB Designables : Failed to update auto layout status: Failed to load designabled from path (null)
So I wonder if there are any configurations to do to use it in a static lib or something like that ?
This is
#import <UIKit/UIKit.h>
IB_DESIGNABLE
#interface CustomUIButton : UIButton
#property (nonatomic) IBInspectable int cornerRadius;
#end
My custom button I want to live render is inside a view controller
Unfortunately it isn't possible to use IBDesignables with static libraries (or static frameworks).
This isn't a great answer but I want to give some context on why.
It seems that the way Interface Builder loads classes to be shown as designables is by actually dynamically loading the dynamic framework that you create (and not your app's binary), and using the classes directly (after changing them using the Objective-C runtime quite a bit).
You can see that Interface Builder isn't loading your app, and just the individual frameworks with these steps:
Create a new Xcode project
Create a new framework target in the project
Add a class that is IBDesignable
In the storyboard from your app create a view and set its class to your framework's IBDesignable class
Click "Refresh All Views" in the "Editor" menu
In your DerivedData folder for the project, in the IBDesignables directory, you can see that only your framework target has been built.
Interface builder actually loads your framework using dlopen manually. You can also see that to facilitate this when building your framework, Interface Builder actually adds 2 RPATHs to your binary, so the dependencies can be found in the custom paths (you can view this with otool -L frameworkbinary). This method of loading your binary isn't possible with static libraries.
For what it's worth I think the best workaround for this is to build dynamic frameworks, instead of static libraries, but only for IBDesignable builds. You'll have to do some configuration work to do this, and it isn't easy to work around Xcode to have this work, but if you try it, you can use either the build path, or the environment, to differentiate IBDesignable builds vs "normal" builds.
EDIT: IB Designable and IB Inspectable do not seem to work with static libraries, so if you're using a static library, either consider using a dynamic framework (iOS 8 only) or move your component outside the static library, if possible.
For issues related with Cocoapods, use the following solution:
This is related to this question.
Here's the solution:
1) Install Cocoapods (0.36.0.beta.1) or newer;
2) Add use_frameworks! to your Podfile
See more here.

Why does my Xcode 5 doesn't autocomplete nothing?

I'm starting a project but I have another one very similar as base.
I create my new project with storyboard and CoreData, create a new file of NSObject class, and when I start writing in the .h file:
#property (nonanatomic, retain) ns...
nsstring or any type of variable doesn't appear... for example, I start writing ns and it appears:
NS_DURING
NS_ENDHANDLER
NS_HANDLER
NS_VALUERETURN
NS_VOIDRETURN
and the most of code is in black letter, i mean, nothing is coloured as it shoud be normal like purple, blue, etc... the colour that xcode sets... here you can see it:
http://oi61.tinypic.com/359iws6.jpg
P.S: I'm using Xcode 5 Preview 3 and OsX Mavericks. I've never had this problem I think.
Possibly your dot-m (the implementation) file is not a member of the target.
When adding a new file to the project on the bottom of the save dialog there is a Target Membership window . Did you check that box?
To view the target membership and/or to add an existing file to your target open the implementation file. Then open the File Inspector using ⌥+⌘ 1 or View, Utilities, Show File Inspector.
In the File Inspector window halfway down there is the Target Membership. Check the box next to your target.
Syntax highlighting will begin after a short moment, wait for Xcode to finish its indexing.
Try out this: In XCode open Preferences, click on the Text Editing Tab and make sure "Use Escape key to show completion suggestions" is checked.

Adding a subclassed UIViewController doesn't allow any imports in .h or .m

I have added a new class that subclasses UIViewController. For some reason, I cannot import any other frameworks or custom classes into the .h file. And oddly enough, in
#interface TestViewController : UIViewController
The UIViewController is not colored to signify it's a class (I've changed my color scheme, not sure what the default color is supposed to be), it's acting like it's just some text I typed in.
In the default viewcontroller, I can import anything I need, but not in my class:
Can you try these things -
Can you do a dry build and see if there are any build errors. Just press ⌘ b. If there are build errors xcode auto-complete does not work. Fix the errors and try again.
Sometimes I have noticed xcode autocomplete just gives up for no comprehensible reason. All you can do is EXIT Xcode and restart.
Clean Build your project and try running your code. This would empty all caches, clean your build folder etc. I have found this to be helpful sometimes. i.e. ⌘ shift k followed by ⌘ b or ⌘ r
Again sometimes xcode codesense just gives up. Open Organizer then Project Tab. Clear the "Derived Data". Xcode should re-index your project then and codesense should work if there are no build errors.
Cant think of any other reason for this to not work.

How can you tell if iOS project is using ARC without opening it in Xcode?

I dont have access to Xcode and want to make sure a project is using ARC. What file contains the setting that shows ARC is enabled?
There are quite a bit of lines that look like this in my AppDelegate.h file.
#property (nonatomic, strong) Test * test;
Search for the MyProject.xcodeproj/project.pbxproj file, and open it with a text editor to see if it contains values for CLANG_ENABLE_OBJC_ARC. If you see = YES then ARC is enabled for one or more targets in the project.
Open the content of your .xcodeproj file: right mouse click -> show content (or something similar).
Open project.pbxproj with TextEdit or any other text editor and search for
CLANG_ENABLE_OBJC_ARC = YES;
or
CLANG_ENABLE_OBJC_ARC = NO;

Xcode 4: Creating a UIView xib, not properly connecting

I'm trying to create a nib that contains a view that will be embedded in a TableViewCell. I've created the interface and implementation files, ResultCell.h and ResultCell.m. They're stock, out-of-the-box, no code changes.
I then create an empty XIB file, and drag a UIView onto it. Then I click File's Owner, and set the type to ResultCell. I click the view, and set its class to also be ResultCell.
Here are the problems I have:
When using the Assistant Editor view (which I live in), the ResultCell.h file doesn't appear when I'm viewing the ResultCell.xib file. I have to force it to load by clicking on Automatic and selecting the file.
When I drop a label in the view, and then Ctrl+Click and drag to the .h to create an outlet, I get this error message: "Could not insert new outlet connection: Could not find any information about the class named ResultCell."
I've tried creating and re-creating the view, and it's just not working, and I've started to lose my patience. Any help would be very, very appreciated!
I got into a similar state just today. It was very odd: I could attach any XIB (new or existing) to any already-existing ViewController class in the project, but I could not create a new ViewController and have it attach properly to any XIB. The "assistant" functionality didn't work, nor did the IB-to-headerfile-connection functionality.
Closing the project and re-opening did not fix it.
Quitting XCode and restarting did not fix it.
Creating a new project and testing the functionality worked fine, which led me to believe there was something corrupt in some cache somewhere.
My solution
Close your project.
Go to the ~/Library/Developer/XCode/DerivedData folder and REMOVE all subfolders there referencing the project you are working on.
Open your project in XCode. The problem should be fixed now.
Incidentally, just running a full clean did not seem to clear things up. I had to trash the derived data. I'm certain I got into this position because of git games I was playing, but I had no idea how to get out, because even switching back to earlier git revisions didn't help. (That was a big clue also that it was something untracked by the project itself.)
This might not work for your specific issue, but occasionally I get that error when working with newly created nibs. Deleting and recreating the nibs and View Controllers with the same names as before didn't resolve the issue, but relaunching Xcode did.
I just had this problem and restarting Xcode did not fix it. I removed the class files from the project then added them back in and it started working.
I had the very same issue. And I tried :
Restarting Xcode
Deleting Derived Data
And many more
None of that worked. What worked for me was simply to :
Remove 'suspect' class files from Project (just remove References, huh?)
Re-add them to the project
And done!
If restarting Xcode doesn't work of you, I have found that Toggling the new .m file out and back into the target membership works.
This helped me out:
from the project file Panel (left side) select the xib file that is broken.
Click on the Files Owner icon from the editor view.
from the properties Panel (right side) select the third tab (at the top)
specify the "Custom Class"
If you do not see a "panel", please have a look at the top-right corner of the window and enable the proper "view" buttons. If you don't see the "view" buttons then click on the top-right most capsule button.
I noticed that .m file was moved inside en.lproj folder.
Just delete (reference only) the .m file from the Xcode and moved .m out of the en.lproj. Add it again.It will fix the issue.
Don't worry, you will get all your connections back.
I encountered the same problem today. Restarting XCode did not fix the problem for me. I was able to get things back to normal by using "Delete" option of "Derived Data" of the project that can be found under Organizer. Organizer says that, "Derived Data includes index, build output and logs". I guess that either index or build output was causing this issue.
in XCode go to organizer, click project, click delete derived data... than clean the project
In my case it helped to make a "fake change" (just a space) to the according header file.
ResultCell should be a subclass of UITableViewCell
You should not drag a UIView onto the empty canvas, you should drag a UITableViewCell
You should select the cell and change it to be your subclass
The owner is most often a controller with an outlet to the cell
Everytime you want to load a new cell, call:
[[NSBundle mainBundle] loadNibNamed:nibName
owner:controllerWithOutletToCell
options:nil]
after loading, use the cell, and set the ivar/outlet to nil, ready for the next load
there are other ways, but this is common
Perhaps what worked for me is this.. (Xcode v4.5)
This did not work
I was trying to control drag into the interface definition of my .h
#interface SearchViewController : UIViewController
#end
This worked (may be that is how it was supposed to work, I did not know it before)
See the open and close brackets. Control drag and drop after the closed bracket.
#interface SearchViewController : UIViewController
{
}
#end
I had a similar problem with a project written in Swift.
What worked for me was setting up the IBOutlet in code like this
#IBOutlet var foo: UIView?
and afterwards connect it to Interface Builder by dragging to the little circle that appeared right next to the code line.
None of the above workarounds resolved the connector issue for me so I shelved my pet project until I came across the following stackoverflow thread:
https://stackoverflow.com/a/15873770/2846800
I had been working on a large project in a previous version of XCode and had turned off indexing. By re-enabling indexing my issue is now fixed:
defaults delete com.apple.dt.XCode IDEIndexDisable
I can now use the D&D features of Interface Builder. I hope this can help others...
This problem seems to be an Xcode bug which creeps up mostly when you replace a file with a new file of the same name. Xcode seems to keep a reference of the older file of the same name.
Anyhow, the way to fix this seems to be:
Clean the project
Click (Your Project) in Project Navigator view. Go to Compile Sources under Build Phases of the target for which you are building. Remove and add back the .m file which is giving you trouble.
Alternatively, in the File Inspector (Utilities view) of the NIB file, under Target Membership, uncheck and check back the target name.
Restart Xcode for good measure.
Of course, deleting and adding back the .m file alone should fix it too.
(Steps 1 and 2 alone fixed it for me.)
If you copied files from other project just make sure you check the 'Add to targets' box
Renaming the class files may unlink them from the XIB. This answer helped me discover this:
Ctrl-Drag from button to method not working. Xcode/Interface Builder
Check that your custom class is set correctly in the Identity Inspector.
Similar symptom, but different cause.
Apparently I hit backspace when the focus was on the assistant view, because one of the standard file template comment lines went from // to / which results in the file not compiling.
Fixing the comment allowed the SDK to parse the file, recognize it as a UIViewController, and add in the outlet.
SO -- if you have this problem, do a build or analyze to see if there are errors that need fixing in your view controller .h file. THEN try the other solutions.
This might be an old topic but just in case anyone has the same issue in future, try deleting the associated .xib,.h and .m files and create new ones. For me, the UIViewController in my .h file wasn't purple and even backspacing and typing it didn't help.
Just put a line between the #implementation and the #synthesize. Most of the answers here have that in common. It worked for me
#implementation
#synthesize
I just tried everything here and nothing worked (using a Developer Preview for Xcode 5).
The only thing that worked for me was to put this incomplete line in my interface file:
#property (nonatomic, weak)
For whatever reason, adding outlets and actions by drag and drop from a .xib worked fine after that.
For me wether cleaning nor deleting the DerivedData solved the problem.
I tried to delete and recreate my UIViewController class several times and got the problem again and again.
Then I recreated the UIViewController class and gave it a different name. This solved the problem for me.
I have had this problem and found a solution not listed above.
In my case, I could see there was something wrong in the class .h file because my custom view controller did not recognise the class : UIViewController (it was in black not purple). All the other custom view controllers had the : UIViewController in purple.
in my case, and possibly yours, I needed to add the class to targets/build phases/compile Sources drop down. The .m needs to be added. All of the other .m's were there but not this one.
Once I added it, the :UIViewController appeared in purple and everything worked fine.
For my case, I have multiple project with some other dependencies. I tried to solve it by deleting derived data or restarting XCode but it couldn't work. In the end, I tried the following method and it works:
Go to target > Build Target Architectures Only > and set both Debug and Release to NO.
Set this for all projects in the workspace and recompile to make sure there is no other errors. Maybe not making sense but somehow did it. During my compilation, I had other issues such as linker errors and symbols not found.
For *.m file of this class view open "Show File Inspector" and unchecking "Target membership" for this project, then do Clean (menu Product->Clean) and checking again "Target membership" for this project
Using Swift, I had a similar problem. I found out that the comments were part of the problem for me.
I leveraged the default view controller, did some work in it, then created a second view controller by copying the entire first one, stripping it down to only viewDidLoad() and renaming the class to TestViewController. Builds worked, code executed. All was good.
When I went to drag a UITextField in to create an outlet, it would not let me. I noticed that my comments still said "ViewController.swift", so I changed the comment text to "TestViewController.swift" and rebuilt. I was able to connect my outlet!
I wonder if what occurred is that the Indexer was reading the comments as well as the class names, and somehow got confused.
Hope this helps someone out there.
I just had to delete the derived data folder. You need to click Window -> Organizer -> Projects -> Delete Derived Data
AND RESTART XCODE.
You should be good to go!
The new class not being part of the "TARGET" is likely the root cause of this, as alluded to by some of these answers.
When creating a new cocoa class, by default the option to add new class to target is by default checked, but should, for any reason, this not be checked when you hit save, you will have this issue.
Any of these workarounds that add the new class to the apps target will work to resolve the problem, and is something that all these 'fixes' have in common.
I think XCode likely has some bugs that causes a new file to, by default, NOT be added to the apps main target. The fix boils down to adding your 'broken' class to the main TARGET
In XCode 7.1, adding the connector at a different point in my source file worked. The error I was getting referred to one of my variables as if it were a class (didn't make any sense). The error stopped occurring when I added the connector below that variable instead of above it.
There is also a diferent reason for the issue ... if you have created new cocoa class file with template other than ios ... i can happen...
The solution would be to delete it and re create it with right template

Resources