Xcode 8 :unknown type name 'CABasicAnimation';did you mean 'CAAnimation' - ios10

Xcode8:I'm trying to CMD+B Project in generic ios Device.
But show Error:
unknown type name 'CABasicAnimation';did you mean 'CAAnimation';
else simulators OK.

Seems like you are missing a #import <QuartzCore/QuartzCore.h> at the top of your file or QuartzCore isn't linked at all (Check at Project -> Build Phases -> Link Binary With Libraries).
And it's always a good idea to delete Derived Data contents and rebuild the project from scratch in those cases.

Related

Adding Unit Tests to an already existing project?

When you create an XCode 4 project, it asks you if you want to include unit testing. But how do you add it to a project that's been created without them?
I started a project with Unit Tests to try to figure it out, and it looks like the only difference between it and my existing project are the Test.h and Test.m files in the new project.
But when I move them into my old project and try to build, it says no such file or directory: SenTestingKit/SenTestingKit.h. That looks like a framework to me, but if I go to build phases and try to add the framework, there isn't one available called SenTestingKit :( And the new project only links the usual suspects: UIKit, CoreGraphics, and Foundation, but no SenTestingKit.
Answer updated for Xcode 10.2.
Glad you asked this question — it's never too late to add tests to a project!
Open your targets panel by selecting your project in the navigator,
Click the + button that's at the bottom of the target list,
Select iOS Unit Testing Bundle under Test section in iOS tab,
Provide the required information and click Done.
It's that simple. Xcode will generate a target, some boilerplate files such as Info.plist and an initial test case file for you. Happy testing!
Also, if you want to be able to do cmd-U to run your tests then delete the scheme that was created for the test bundle and instead edit your main application scheme and add the test bundle in the Test configuration. See this screenshot:
Xcode 7 update
Method one
File > New > Target...
Choose iOS Unit Testing Bundle. (If you want to add UI Testing then choose the UI Testing Bundle.)
Method two
Click your project name in the Project Navigator. You will see TARGETS listed. At the bottom of the screen press the plus (+) button and add the iOS Unit Testing Bundle.
The test targets in this image have already been added, but you can see where the add button is.
Related
How to do a Unit Test in Xcode
Xcode UI Test example
One more variant using Test navigator
Xcode version 10.2.1
Open Test navigator(⌘ Command + 6)
+ at the bottom
New Unit Test Target...
Choose options
Do not forget add next import to test internal[About] elements
#import "myClass.h" for Objective-C
#testable import module_name for Swift
This is pretty descriptive how-to guide:
Adding Unit Tests to an existing iOS project with Xcode 4
Some more tips to the correct answer:
In XCode 6 it is much easier now since you don't need to fix any build settings.
Change the bundle id on a test target to the correct one, if needed, by clicking the target -> Info -> Bundle Identifier.
Press CMD + U and your tests will run.
If you use CocoaPods (which is likely), you should also add Pods to the Configurations of your Project.
[Updated for Xcode 10.2]:
Open your Xcode project
Open targets
Click "Add Target" button
Go to "Test" section
Select "iOS Unit Testing Bundle"

Why should your constant implementation file be added to your frameworks target?

I was reading an old post on here: Constants in Objective-C which talks about how to set up a file for your constants when doing iPhone dev in objective C. One of the responses (which got a lot of helpful votes) says that "Constants.m should be added to your application/framework's target so that it is linked in to the final product."
My question is, how do you do this, and what is accomplished by this? Does this make it so you don't have to import the constants file in the files you need to use it for?
Also, does the same method talked about in the response apply to integer constants, etc?
Thanks.
It makes it so that the constant values are available in the linked binary. Your header file will be included by reference (since you #import it) but the compiler needs to know that you want that .m file to be part of the final binary.
In XCode 4, choose your project from the top of the Project Navigator (the file tree view tab on the left). Select your target from the list of targets that appears in a new column to the right of the Project Navigator. Select the Build Phases tab on the right. Open up the Compile Sources item. Here are all of the files that are being compiled to build your binary. Make sure your constants file is in here. If it is not, find it in the Project Navigator and drag it into the Compile Sources pane.
In Xcode 4, beside the method Seamus mentioned, you can also select that .h file, open right view (at the top-right conner, there're three), in the first tab there's target membership, select the target you want to add it to and you're set.
You have to make sure you #import and also the file has to be in build target. #import make sure your complier know where to look for, include the file in target make sure when complier go and look, there's that file (The file won't be include in your build if it's not part your building target even it's in your project).

Can't include FMOD on iOS

I don't think I'm including the FMOD library correctly. I'm getting the following XCode error:
expected specifier-qualifier-list before FMOD
I'm using XCode 4 and the latest version of the FMOD library. I went into the "Link Binaries With Libraries" section in XCode and added libfmodex_iphonesimulator.a.
Any ideas on what I could be doing wrong?
Thanks!
Here is a step-by-step process for getting FMOD running in an iOS application:
File -> New Project
iOS -> Application -> Window based application
Choose name and location (I used 'test' and the FMOD examples directory as the location)
Assuming you named the app 'test', rename 'testAppDelegate.m' to have the extension '.mm' to allow C++ code.
Edit 'testAppDelegate.mm' to have #import "fmod.hpp" at the top.
Project -> Edit project settings (ensure Configuration at the top is set to All configurations)
Go to "Other linker flags" and type in -lfmodex_$PLATFORM_NAME
Go to "Header search paths" and type in ../../api/inc
Go to "Library search paths" and type in ../../api/lib (now close settings).
Right click on the "Frameworks" group on the left, choose Add -> Existing Frameworks, then choose 'CoreAudio.framework'
Repeat step 10 but choose 'AudioToolbox.framework'
Add FMOD code to 'testAppDelegate.mm' as needed, see playSound example for reference code.
After you link the appropriate library make sure you drag the 'inc' folder with all of the .h files into your project somewhere, that was my issue. Also, make sure you include AudioToolbox and CoreAudio if you did not already, and make sure to include fmod.hpp and fmod_errors.h in your view controllers header.

Correct path for #import of iPhone Frameworks (ALAssetsLibrary.h)

This may be the easiest points out there but it is stumping for some reason. I am trying to include the AssetsLibrary Framework and having issues with getting the compiler to see the actual include file for ALAssetsLibrary when using relative paths.
I am currently using:
#import </Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.2.sdk/System/Library/Frameworks/AssetsLibrary.framework/Headers/ALAssetsLibrary.h>
And this works but is oh so bad in that it calls out the device and specific OS build. I have added the framework and everything links and runs. I just really do not like using the above absolute path and cannot get any relative paths to work. I have tried many combinations of using quotes ("") and braces (<>). Various relative paths to just System, Library, System/Library...
XCode specifics:
XCode 3.2.5
Component versions
Xcode IDE: 1760.0
Xcode Core: 1763.0
ToolSupport: 1758.0
Found it. Don't know why I did not think of this earlier...
#import <AssetsLibrary/AssetsLibrary.h>
Simple.
In Swift:
Please first of all add the AssetsLibrary framework to your Xcode project: click on the name of your project in the project navigator < Then click on the name of your project under TARGETS < Then click on Build Phases < Then click on Link Binary With Libraries < Then click on the "+ button" and add the AssetsLibrary.framework
Finally add this import below at the top of your swift class:
import AssetsLibrary

Rename a class in Xcode: Refactor... is grayed out (disabled). Why?

Why is Refactor... grayed out (disabled) in Xcode?
I'd like to rename a class.
Select the class's symbol in its header file - i.e. the bit just after #interface. Then the refactoring stuff should be enabled.
If you are using Objective-C++ (i.e. mix Objective-C with C++ code) then refactoring is disabled in xcode since it does not support refactoring of C++ code.
Refactor might also be disabled if affected files (most likely the file with your class in it) are not saved.
I've been using Xcode for 5 years now, and refactoring has never worked correctly (even xcode 4.6 has major bugs where it WILL corrupt your source code!).
The workaround has always been (still works 100%, even in cases where Apple's code fails)
use shift-command-f to find all uses of the file
select "replace" in the search settings
"replace-all"
do the following for the .h file, and REPEAT IT FOR THE .m FILE (if you have one):
right click the original file, and select "show in finder"
delete the file from xcode (select "delete references only" when asked)
rename the .h (and .m if you have one) in Finder
in Xcode, select "Product -> (hold down Alt) -> Clean Build Folder"
quit xcode (you can usually get away with not doing this - but NOTE: there are some other MAJOR bugs in Xcode where it crashes itself if you don't do this)
re-open xcode
drag/drop the .h and .m back into Xcode
wait a few seconds (some of Xcode's core methods are asynchronous - allowing it to corrupt your project)
finally, when it seems to be doing nothing (and your hard disk isn't making any noise any more): cmd-b to re-build
I have a 100% success rate with this method. I just tried refactoring with Apple's "Refactor -> Rename" in latest xcode and it failed - again!
(this time with the incorrect error: "Unable to determine the language of", one of those error messages where Apple put the wrong text in place)
I'm going to my project at finder, then change files name by get info.
After that, at xcode -> Project Navigator I delete the files.
At end, I click right on the class and Add files to ..., and add these files again.
It worked for me.
For me I realized Refactor was disabled because the Xcode project I had opened was referencing a Base SDK that was missing. Edit Project Settings and in the Build tab set the Base SDK to one that you have (like for me this was iOS 4.2). This enabled Refactor for me.
Also, it could happen that you renamed the filename for the class, either outside xcode or by ctrl-clicking the filename and then renaming it.
xcode refuses to refactor if filename does not match with the class name.
Go to your class' header file and find the line that looks similar to this:
#interface YourClassName
Right click on the class symbol (e.g. YourClassName) and you should be able to select Refactor -> Rename...
I just tried this and it works in Xcode 5.
This may be a bit late, but I stumbled across this post because I was unable to refactor my "ViewController.swift" file to "WhateverViewController.swift". I tried selecting the file in the Project Navigator and then selecting "Editor -> Refactor" from the top menu, but 'rename' is always greyed out.
Instead, what worked was selecting the ViewController name from the editor. So if you have:
class ViewController: UIViewController {
// Code here...
}
Highlight the "ViewController" word and then select Refactor from the menu or right-click and select Refactor -> rename.
Hopefully that helps...
Had this problem as well. I ran through trying to find missing SDKs, saving files, and looking for Objective-C++ code as mentioned above, and all it took to fix my machine was rebooting XCode.
Seems a little buggy still.
BTW, this was for XCode 4.0.1
Refactoring works If you first change the file name in the project navigator.