I'm using Xcode 9 and Swift. I've got one workspace and one iOS project. Later I added a MacOS target (Cocoa App). When I try to reference a class from the MacOS target to the iOS target, the compiler says:
Use of unresolved identifier.
How do I get Xcode to allow me to share Swift classes from target to another?
This type of Xcode workspace organization is mentioned in Apple's documentation but doesn't describe how to allow the usage of implicit dependencies within Xcode.
Use Project Navigator to find the classes you wish to share with another target. Highlight the classes. Open the inspectors (icon in the top right corner of Xcode). On the right side a panel will appear. Change the "Target Membership" to include the other (in this case, MacOS) target.
After a rebuild it should work fine.
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 have accidentally deleted my main storyboard. Now I am trying to use the main storyboard from this path:
Users//Library/Developer/Xcode/DerivedData//Build/Products/Debug-iphonesimulator/.
I found here a file named Main.storyboardc which I suppose is my main storyboard but when I am trying to compile it (with this new Main.storyboardc) I am having an error saying Interface Builder cannot open compiled nibs.
I know this question is discussed before but I didn't find anything helpful
Furthermore I am using Xcode 6.3.1 and this discussion was not very healpfull Xcode 6 Interface Builder "cannot open compiled nibs" error, FiksuSDK
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'm facing a few problems with Xcode. I have searched around and nothing helps... to make things worst i'm learning everything from scratch. swift, xcode, build mac apps... coming from ruby/rails this is extremely painful!
A while ago all projects started throwing errors like the use of undeclared type 'NSObject' and so on.
I am using Xcode Version 6.1 (6A1052d).
The project still runs if I clean/build it and run. But as soon as I select another file and come back the AppDelegate the errors appear again. Also cmd+clicking just displays "Symbol not found" and autocompletion doesn't work.
I created a new blank project (multiple times) and this still happens. I didn't even touch the code! I have attached two images to show my problems.
The first line error I managed to fix it following Subclass UIApplication with Swift:
Basically I removed #NSApplicationMain from AppDelegate and created a main.swift file with these lines.
import Foundation
import AppKit
NSApplicationMain(C_ARGC, C_ARGV)
this seems to fix the 'NSApplicationMain' class must conform to the 'NSApplicationDelegate' protocol error.
But I can't see how to fix the other errors. Any help please? :) Thanks in advance.