When creating a new project in Xcode 6, the generated project is missing the Prefix.pch file. Is this intended? Should we continue making our own, or is there a new method we should be using instead?
I don't use it too much, but having a few key system frameworks like Foundation and UIKit available in every file is useful, along with a couple oft-used 3rd party frameworks. Is the preferred solution to just create our own prefix file manually and configure it in the build settings, or something else?
You can easily add the Prefix.pch file manually like this:
1) Add new .pch file to your project -> New file -> Other -> PCH file
2) Goto your project's build setting.
3) Search "prefix header". You should find that under Apple LLVM.
4) Paste this in the field $(SRCROOT)/yourPrefixHeaderFileName.pch
5) Clean and build the project
If you use Objective-C just like before xCode 6 you will also have to import UIKit and Foundation frameworks in the .pch file. Otherwise you will have to import these frameworks manually in each header file. You can add the following code anyway as it tests for the language used:
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Related
I saw in a github(https://github.com/sandym/swiftpp) project on using "cxx-Bridging-Header.h" header file for .cpp(C++) and .mm (objective-C++) file and learnt that it was build by "Run Script" but didn't got any clear idea about how to create the header. Please help on how to create such a header?
Go to, File -> new File -> iOS source -> header file .h -> click on project to bring up build settings, look for Objective-C Bridging Header double click in blank field to bring up blank view -> drag and drop your newly created .h file into blank view till the file path is there (it might disappear on you a couple of times) -> go to .h file and #import "cxx-Bridging-Header.h" build and you should be good to go.
Good luck!
When I create a new OS X "Game" project with Sprite Kit, and set a breakpoint anywhere I can see the variable values just fine:
Then I change the code to import my own framework (TilemapKit) which is a pure Objective-C framework:
import SpriteKit
import TilemapKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
print("dang!")
}
}
No other changes made. I'm not even using any of the TilemapKit code (yet). When the breakpoint triggers, I see this:
The entire project stops being debuggable as far as observing variable values goes. This behavior is perfectly consistent. Without the framework import I can debug again.
Since I'm on Xcode 7 beta (7A121l) and OS X 10.11 developer preview I know this could simply be a (temporary) bug.
Command line Tiles are set to use the Xcode 7.0 version btw. I tried enabling modules in the framework target, made sure the deployment target is the same (10.11), disabled symbol stripping. I added a Bridging Header and #imported the TilemapKit framework in it (removing the Swift import in that case would still give me the non-debuggable app, so it doesn't seem to matter how or where I import the framework).
Does anyone have a suggestion on what could cause this behavior and how I might go about fixing it - or at least how I could try to narrow down the issue?
Is the culprit more likely to be connected to the project's vs the framework's build settings? Do I need to enable something in the app project to make it compatible with ObjC frameworks? (I already got -ObjC in the Other Linker flags)
UPDATE:
I ran po self in the debug console and found this notice:
<built-in>:3:6: error: module 'TilemapKit' was built in directory '/TilemapKit.framework' but now resides in directory './TilemapKit.framework'
#define __clang_major__ 7
^
missing required module 'TilemapKit'
Debug info from this module will be unavailable in the debugger.
How come the framework build directory changed? And why would that matter and how to fix this?
PS: the same framework in a new ObjC app can be debugged just fine.
I got a message from an Apple developer stating that they've observed this problem, and that it could be fixed by moving the .framework to a subfolder of the project.
Apparently the module .. was built in directory error appears only if the .framework is in the same folder as the .xcodeproj aka $(PROJECT_DIR).
However moving the framework to a subfolder didn't fix the issue in my case, but it's still worth a try until this gets fixed in a newer Xcode 7 beta (still occurs in beta 3).
In my case this was happening because of redundant import statements in my project.
My project mixes swift and objc files, so I have import statements in the bridging_header.h file.
In my bridging_header.h I had #import blah.h
In one of the swift files, I was importing a redundant header from a framework
#import blah // From blah.framework
I removed the redundant import from the swift file, that seems to have fixed it.
I can confirm this is happening in Xcode Version 7.0 beta 4 (7A165t). I had to remove my ObjC framework to get Debugging values to return. If removing your framework isn't an option, the print method is old-school debugging, but still works.
I had this issue a while ago. In my case the Prefix.pch was beeing included inside the Bridging-Header.h. This is not a issue per so, but inside my Prefix.pch there was many C includes that make the lldb fail to import the Bridging-Header.
So I removed the "#import Prefix.pch" from the Bridging-Header and copied just the "#includes" to the obj-c files that I need to use in swift.
The Optimization level is not set to None for the Debug configuration.
Be sure to set it to None for Objective-C apps as shown in Figure 1 and for Swift apps as shown in Figure 2.
The Build Configuration pop-up menu is set to Release in the scheme editor's Run action settings pane.
In Xcode, open the scheme editor by choosing Product > Scheme > Edit Scheme…, select the Run action for your app in the scheme actions pane, then set Build Configuration to Debug as seen in Figure 3.
Go to Edit Scheme on left top corner.
And change the configurations to Debug, if it is release
I am looking for a simple procedure for combining an Objective-C code from a shared library project with Swift code from an application project but have had no success so far with this sequence:
start Xcode 6.1.1
create workspace Test
create iOS Cocoa Touch Static Library project TestLibrary and add it to workspace
create iOS Single View Application project Test (language: Swift) and add it to workspace
add import TestLibrary to ViewController.swift
If I now build Test, I receive this error in ViewController.swift: No such module: ‘TestLibrary’.
Presumably two hurdles must be overcome:
Tell TestLibrary that is should "export" TestLibrary.h. What is the right syntax and procedure for adding the (presumably) required bridging header file?
Tell Test where TestLibrary is located. Since both the application and static library projects belong to the same workspace (and sit in the file system next to each other) I assume no explicit steps are required, or are there?
So in summary, my question is this: how can I overcome the build error even if I subsequently add let test = TestLibrary() to ViewController.swift, i.e. how can Test (Swift code base) make use of TestLibrary (Objective-C code base)?
This procedure seems to work (for single app target):
Do not add import TestLibrary, since both the Swift and Objective-C code will reside in the same app target
Create Test-Bridging-Header.h to Test and add #import "TestLibrary/TestLibrary.h"
Set build setting Objective-C Bridging Header: Test/Test-Bridging-Header.h for Test
Drag libTestLibrary.a from TestLibrary (under Products) into Test's Link Library With Binaries (under Build Phases)
Add let test = TestLibrary() e.g. inside viewDidLoadin ViewController.swift
Voila ...
In my case, I have to add all the .h file's of the Framework in the Bridging file, that fixed the issue. Also remove the import TestLibrary from the swift files
I want to work with some frameworks like glew and cg so i manually added
the needed frameworks to my project by right clicking the project -> Add files to ...
and choosing the correct framework. The problem is, when i try to include the header files,
Xcode cant find any of them. I hope this picture will help to understand:
And:
The error given is for the glew framework, but it also happens on Cg.
As you can see on the left, The needed frameworks were added.
Any idea on how i can include these headers?
After trying to add the header files manually i got an architecture error:
I dont know if this is how it should look like.
Thanks!
Before starting, remove the framework and all files you have added while trying to make it work.
Then, you have to add the frameworks in the Build Phases of your target. Then go into Link Binary With Libraries and select your framework from there.
This should do it. Your headers should be available as auto-completion after each #import directive.
If it does not work (it sometimes happens), there are additional steps I can provide to you.
Additional steps:
Go to your project settings, in the build settings:
Complete the Framework Search Paths with the path of your framework
Do the same with User Header Search Path
Then, it should work. If it does not, you will need to add the full path of your header in the #import directive. Example:
#import "/path/to/my/header.h"
Apple's documentation available here states:
In the project navigator, select
your project
Select your target
Select the 'Build Phases' tab
Open 'Link Binaries With Libraries'
expander
Click the '+' button
Select your framework
(optional) Drag and drop the added
framework to the 'Frameworks' group
In my case I have added Framework Search Paths for Target, but it should be added to Project
Also Always Search Users Path should be yes
For those whose autocomplete fails after adding framework.
I used to add frameworks, by going to Build Phases and taking the Link Binary with Libraries option. Now in XCode 6.1, though project was building fine, autocomplete in XCode was not working.
So what needs to be done is:
Remove the already added framework from Project Navigator and also from Link Binary with Libraries.
Add framework to project by simply File -> Add Files to option in XCode.
And auto complete will start working.
In my case, the external framework had been downloaded with Windows and added to the project. Then it was transferred to OSX, where the Xcode project was built and the external framework didn't load properly. I guess it is because Windows changes the framework folder to be a regular folder, which OSX then has trouble with.
Solution for me was to simply download the framework with OSX and drag it into the framework folder in the XCode project.
In my case I had to update a framework version, so I just replaced the .framework in the filesystem and then I got the error you've mentioned in the question.
Removing the framework and adding it back again, playing with the search paths and all the other suggestions didn't help.
Eventually, cleaning the build folder did the trick:
Select "Product" from the xcode menu, hold the option key and click on: "Clean Build Folder".
After that I built and ran the project successfully.
I'm having trouble adding a static library from another Xcode project (CloudApp API) to my Xcode project. My project has two targets -- a prefpane bundle, and a console application. I want to add the static library to the console application. Here's what I've done so far:
Created a new workspace
Added the CloudApp project to my workspace
Added the libcloud.a file to my "Link Project Binaries" list for the target binary
Added -ObjC to the "Other Linker Flags" setting for the target binary
Added $(BUILD_PRODUCTS_DIR) to the "User Header Search Paths" setting for the target binary
Copied all the relevant headers from the CloudApp project into my project (without adding them to the target) so that I don't get errors from any #import statements
Edited the scheme for the target binary to require compiling CloudApp first
Added relevant frameworks to the target (Cocoa, Foundation, CoreFoundation)
Doing all this worked fine when I just had a single Cocoa target (not a console application). But now I'm getting errors in the CloudApp header files I included. Basically things like this:
In CLWebItem.h:
Unknown type name 'NSImage'
Any ideas?
Create a prefix-header.pch and #import <Cocoa/Cocoa.h> inside. Make sure to compile the prefix header in your settings.