Can't seem to import a framework into my current project in Xcode 10.2.1 - swift

Here's what I've done so far:
Create a Single View App project called MyApp
Create a Cocoa Touch Framework project called MyFramework
Created a Swift file with a class as public class FrameworkClass
Dragged MyFramework.xcodeproj into MyApp's Project Navigator - This caused Xcode to create a workspace.
I added the framework to MyApp.General.EmbeddedBinaries
Now it looks like this so far but I can't seem to import my framework still:

Please follow the steps to resolve your problem:
Choose your project, rather than a specific target, and open the
Build Settings tab.
In the Other Linker Flags section, add -ObjC.
If these settings are not visible, change the filter in the Build Settings bar from Basic to All.

Right before alt-tabbing Xcode to submit this response, I built on reflex and it turns out that it won't detect the references until you build once. After that, it should start to be detected by the text editor.
I was going to delete this question however, I already typed it up anyway so might as well. Hope this helps someone!

Related

Couldn't instantiate class _TtC12STracker23InfoInterfaceController

I try to build my watch app and I keep getting an error
createViewController:className:properties:contextID:info:gestureDescriptions:
clientIdentifier:]:2916: Critical failure. Simulating crash: Condition failed:"NO".
Couldn't instantiate class _TtC12STracker23InfoInterfaceController
I had to rename my project at some point and according to my research it can be the cause of the problem. I recreated from scratch the Interface.storyboard and InfoInterfaceController but it did not help.
That is not a good way to solve such problems specially when someone has bigger WatchOS App Project and deleting all and recreating is absurd and time consuming.
first check if you did rename your project correctly by following steps in this answer by Luke West: https://stackoverflow.com/a/35500038/7345611
then do these steps:
go to interface.storyboard located at left navigator pane in Xcode
select the yellow circle on top of a interfaceController
go to it's identity inspector
in class section, reassign your class to that interfaceController by retyping the class name and hitting enter which Xcode will updates the module section under it automatically. (all your problem lie in Module Section where Module still has the old name assigned to it)
do the same process for all interfaceControllers and customClasses(if you have any) and everything that you assigned a class to it before.
now the app should run as expected.
This is due to Module Which will be pointing to Watch App Instead of Extension as these all files exist in the Extension Module, you can directly change the Module of Watch StoryBoard file InterfaceController, NotificationController and if any default created interfaces.
In the "Build Settings" of your WatchKit App target, make sure to update IBSC_MODULE (Default Module). Set it to the WatchKit Extension module name (in iOS apps IBSC_MODULE can be left empty and will automatically point to the target's module). The module name is the name of the target's product name (which is often also the target's name) with spaces replaced by underscores. In case your UI classes are in a framework, use the framework's module name instead of the WatchKit Extension module name.
For example, if your WatchKit Extension target is "My WatchKit Extension", in your "My WatchKit App" target go to "Build Settings" and change IBSC_MODULE to "My_WatchKit_Extension".
As mentioned by sandydhumale, select your Interface Controller in the Storyboard and in the Identity Inspector make sure to check the "Module" field under the "Class" field. An empty "Module" field means the class will be searched in the default module (set by IBSC_MODULE).
So I've solved the problem by deleting all watch targets and files and recreating them

Cannot add Alamofire to Swift Project

Trying to add alamofire to swift project using unstruction from here
Did all these steps, clean project a lot of timer and restarted XCode, nothing helps. Error does not dissappear
http://i.stack.imgur.com/kNU3R.png
"Cannot load underlying module for 'Alamofire'" and nothing to do
Changes I did:
1) added project file to my project
i.stack.imgur.com/eUe8E.png
2) added to build phases panel
i.stack.imgur.com/1wanl.png
3) added to general tab
i.stack.imgur.com/L3TTR.png
What`s wrong with that?
I had the same problem. I was able to fix it by doing the following.
Download the Alamofire "Source" folder.
https://github.com/Alamofire/Alamofire/tree/master/Source
Drag it into your xCode Project, and click "Copy Items if Needed". If you view the project in Finder, the Alamofire Source folder should be in the project itself. (Ex: I have 3 items. Example App, Example App.xcodeproj, Example App Tests. The folder should be in Example App.)
Finally, you should be done! However, now, you do not need to import Alamofire, since you are not actually loading a framework.
For example, instead of doing Alamofire.upload, you will now only do upload.

Can Swift playgrounds see other source files in the same project?

I created the most simple custom class in a separate Swift file in my project:
class Foo
{
init()
{
println("I made a foo.")
}
}
Then, in a playground within the same project, I tried
var x = Foo()
Xcode didn't seem to like this, and told me that 'Foo' is an unresolved identifier. I'm somewhat confused about how playgrounds fit into the rest of the project structure, since any other Swift file in my project can resolve 'Foo' without issue.
How can I make my playground able to use custom classes I define in other Swift files in my project? I have tried naming the product module for the build target and importing that into the playground, with no success: the playground doesn't recognize the name of the product module.
Thanks in advance for the assistance. I know it is something simple.
There's two ways to use your project's code in a Playground
Playground's Sources Folder
Yes, in Xcode 6.3 Beta 3 (and hopefully, into the future):
Playgrounds are now represented within Xcode as a bundle with a disclosure triangle that reveals Resources and Sources folders when clicked. These folders contain additional content that is easily accessible from your playground’s main Swift code. To see these folders, choose View > Navigators > Show Project Navigator (or just hit Command-1).
Open up a new playground and hit cmd + 1 to see the left pane, then drag files into the source folder to use within the playground.
Note:
The files in the source folder are compiled to a framework which means if you want classes, functions, etc. to be accessible in the playground, they must be explicitly marked as public.
public class VisibleClass {
}
class InvisibleClass {
}
Source: release blog
Compile Project Into Framework
Move project to workspace if it isn't already. (File -> Save as Workspace) will do the trick
Add framework target to your project
Build framework
Make sure files you want to access are added to your framework target
Add Playground to workspace (NOT the project)
Use #testable import YourFrameworkName
Access code in playground
I made a write up here that goes into a bit more detail if you want to check it out.
They cannot. Playgrounds are self-contained. This will hopefully change in the future.
Edit: As of Xcode 6.3, Playgrounds can now contain supporting code. They still cannot see other code in the same project, but code can be added to the support folder of a Playground that can be used from within the playground. See the Swift blog for more info.
Yes.
I started by just adding a class file in the Sources directory.
I made everything public:
class
init
members
After much trying, nothing worked. The XCode crashed and after reopening it all worked like a charm.
In Xcode 10's Project Navigator:
Add the source code file to the playground's Sources folder.
Drag the file from the playground's Sources folder to the desired location in the project (you should see the little "plus in a circle" icon appear.
End the drag and then in the Add File dialog uncheck "copy if needed"
The source file now "lives" in the playground package; the Project refers to it (you can verify that with the File Inspector).
I tried it the other way around: file lives in project folder with reference in playground's Sources folder but it didn't work; I ended up with two copies of the source code file.

How to add new iPhone target

I'm trying to add a new target to my Xcode project so that I can run the same app, but with subtle difference.
Please can someone guide me through the setup of a new target since it is my first time and I'm not sure how to go about doing it.
In particular, I'm interested how I make the new target run the code in the original app. When I tried creating a new target it just made a new app delegate, and viewController file.
Sorry if this is simple, I'm just quite confused.
EDIT:
Please note that I'm after after instructions based in Xcode 4.
In xcode 4, make sure you're in the folder view where you have the project. Select the blue project button, then next to that you can see Targets, Select the target you have there, right click & select duplicate target.
Now you have two build targets.
To apply subtle differences in your app, make a global C flag. in Build settings there is a paragraph named GCC 4.2 - Language, it has a property named Other C Flags. Add your flag here like so:
-DOTHER_VER
Now in your code you can check for this using:
#ifdef OTHER_VER
// some code.
#else
// the subtle difference.
#endif
After you create your new target from settings of your project, you can create an identifier class to check the target. If you use macros everywhere in your code, it'll not be readable and feasible. You can check this tutorial-blog to learn how to do it, besides you may see some best practices there.

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"