getting module not found after importing packages in swift - swift

I've done a bit of swift, but I've never tried to use a third party package before. I created a brand new swift app, with Mac/iOS version and tests from the wizard. I went to xcode, right clicked on the sidebar, and chose add packages, and put in a package by url:
https://github.com/witekbobrowski/EPUBKit.git
It goes away for a little bit - and three package dependencies appear on my screen:
and when I look at my project settings, I can see them there:
(I actually added the zip package separately after the first one didn't work, just to test it, wondering whether something was wrong with the package)
Anyway - I can now see the packages, browse into them, see code or whatever - and the package found its own dependencies, so everything looks like it's working fine. But if I go into my swift app main, and add
import EPUBKit
or
import Zip
it just says "No such module ...".
I've obviously missed a step - what am I doing wrong - how do I fix it? I don't even know how to investigate it, because everything I look at just looks completely fine and I don't get any errors. I tried cleaning builds, restarting Xcode, using the real version of Xcode 13.2.1, using Xcode 13.3 beta - and nothing works.
NEW LEARNINGS
so - I tried changing how I'm running it to produce an IOS app - and it's working fine - but when I produce a Mac app, it's like the package isn't even there? Why would that be, and how do I make it work for Mac as well as IOS?

Author of EPUBKit here, thanks for taking interest in my library!
The issue is reproducible in a new project which kinda makes sense but don't at the same time. I am glad Xcode is not adding a package to every single target in my project but at the same time why does it assume that I want it in the iOS target? Anyway, I know that this question was already answered in the comment and the problem is solved but I might as well just drop more detailed instructions. Maybe it will help someone.
1. Select Project from Project Navigator
Select te target that is not working for you, in this case it's the macOS target. In the General tab you will see the Frameworks, Libraries, and Embedded Content section. If the package is missing from the list, tap the plus button at the bottom.
2. Add Missing Library
Look for the one you are missing, in this case its of course EPUBKit and tap the Add button.
3. Success
Now the library is successfully added to your target. Go ahead and build the project to run and enjoy your app :)

Related

How to manually add SSZipArchive to my project

First off, I'm a Mac OSX newbie, both using and programming, but it's been thrust upon me. My project is moving along nicely, but I need to unzip a file, and it looks like SSZipArchive seems like the way to go. I want to manually add it to my project, so that it stays all together in my source code control system. Others, esp. the release engineer, shouldn't need to do anything, and we need to have all the source code local.
I've tried a million ways and back, only to keep getting the dreaded "No Such module" error. I've researched for a couple days now, and still no closer. So I'm starting from scratch in a new project to say what I'm doing and to plead for some help here. All this is being done on an El Capitan laptop, using Xcode 7.3.1, with Swift 2.2.
Create a Cocoa Application project, calling it 'ziptest', using Swift, nothing else checked. Build it just for fun.
Drag 'n' Drop the SSZipArchive folder found in the master.zip downloaded from the SSZipArchive GitHub site into my project. I'm not sure where it should go, or if it matters - top level, between ziptest project icon and the ziptest group or inside the ziptest group. But I'll put it inside the ziptest group. Now I'm faced with a new question - for the "Added folders", do I want to "Create groups" or "Create folder references". I do copy the items, because, as I said, I want to add them to SCCS later. I saw somewhere here on Stackexchange to make sure it is Group, so that's what I'll do. Build again and it still works.
I know I need a "bridging header" file, so I'll create it. I thought at some point, Xcode asked if I wanted to create it, but the above step doesn't do that. After much experimention, I found that if I d'n'd the SSZipArchive.m/.h files directly, it asks me. It doesn't put anything into it, but at least it creates it and updates the Build Settings. But I do this now manually by right clicking on the ziptest group folder, select New File... and create an empty Header File called "ziptest-Bridging-Header.h", following the pattern from the Xcode created one, being sure to check off the ziptest Target.
I add:
#import "SSZipArchive.h"
to that file. And building still works.
I added ziptest-Bridging-Header.h as the Objective-C Bridging Header in the Build Settings. And building still works.
Now comes the moment of truth. I add:
#import SSZipArchive
to AppDelegate.swift and I get the dreaded No such module 'SSZipArchive'
What am I doing wrong?
Edited to add: Oh, I also added libz.dylib to the Build Phases -> Link Binary With Libraries part. Doesn't help, of course, because we haven't even gotten to the link phase yet.

Xcode 7.3 autocomplete is so frustrating

There is a new autocomplete in Xcode. Probably might be useful because it checks not only beginning of names etc. But I found that very often it doesn't find a class name or a const name at all etc. I need to type in entire name by myself. Over all I found it makes my life harder and coding more time consuming. Is there a way to switch to the old way it used to work?
Xcode 7.3.1
In Xcode > Preferences > Text Editing
uncheck Enable type-over completions
restart Xcode
It seems that clearing the checkbox "Enable type-over completions" in XCode -> Preferences -> Text Editing does the trick. At least in my case autocompletion fell back to a sort of old way, so it could autocomplete the class name that I had to type in manually before that.
This is by no means an adequate solution, BUT it has allowed me to (barely) maintain my sanity the past few days:
After every build, you need to trash your Derived Data folder. You can find this folder in Xcode > Preferences > Locations > Derived Data. Just trash the whole thing and it'll kick off a re-indexing step that should restore proper autocomplete functionality.
Unfortunately, I've found that once I build, the autocomplete behavior reverts to its broken state.
just open Xcode derived data folder and delete the folder
/Users/yourUserName/Library/Developer/Xcode/DerivedData
then restart Xcode, now autocompletion works like a charm
I have the impression that some 'parts' of autocompletion simply fail after a while. I use to restart the Mac to get it back working. But sometimes it fails quite soon again.
Maybe the answer of #Alex Bykov combined with a restart will do the trick.
Anyway: auto-completion of Xcode always was crap. AppCode used to get it much better. Unfortunately not yet with swift.
Closed Xcode, opened Xcode, let it index, it worked.
it doesn't find a class name
As a work-around, you can try to press
Command + Shift + K and Command + B
Several times,it works temporarily.
Xcode 7.3.1
I will share another posible reason, that after couple of days we found out. We have multiple schemes, and in one of them, the bridging header was importing a file that didn't exist anymore. So, it didn't break while compiling and running (the header belongs to another scheme) but it caused the autocompletion to break (couldn't find any objective-c class).
Hope it would help someone!
After having tried different methods:
Delete Derived Data
Switching Module Enabled off in Build Settings
Full Clean
Relaunch
Only this worked:
Find any commented out (/* abc */) code after #end in your files and delete.
Credit to Max_B:
https://forums.developer.apple.com/thread/7439
In my case, other projects were auto-completing correctly. If all your projects fail to correctly predict code, then it might be a different issue, and the other answers might work.
I ran into this issue while trying to make an OS X app and I was able to fix this issue by making sure that the Xcode 7.3 documentation and the OS X 10.11.4 documentation was actually downloaded. Doing this fully restored my autocomplete functionality. My full instructions are below as well as in my answer to a similar question: https://stackoverflow.com/a/39420664/3444925
I had this problem myself and after looking through all the other similar questions & answers about this, I couldn't find a solution. However, I finally found what worked for me.
Go to Xcode -> Preferences -> Components. There you will probably find a screen that looks like the following:
This shows that the documentation has not has not been downloaded and therefore, any attempts to re-index or re-build the application without downloading the documentation would prevent you from being able to use the autocompletion functionality.
Once I downloaded the Xcode 7.3 Documentation and the OSX 10.11.4 Documentation, this was enough for me to get the autocomplete functionality back (I was trying to build an OS X app, so feel free to download as much documentation as is relevant for you).
I didn't run into this until I created a couple of new class files. Other classes worked fine, but autocomplete would NOT work for anything in the new files...
FIX (for me) - I had to add those files to ALL of my targets, including the unit test targets even though I wasn't using them yet.

Xcode won't build to device

This problem has been KILLING me. I've been working on this app for 8 Months, and I am so close to finishing, I just can't seem to build for device. Building for the simulator works fine, but device always gives me the SAME 2 errors.
The 1st Error:
"Instruction requires a CPU feature not currently enabled"
From googling, I've found this probably means I'm not linking a binary I should be, but I'm not sure.
The 2nd Error:
If you can't read it, it says: Generating JWFNS.app.dSYM ... error: unable to open executable '/Users/ajr1188/Library/Developer/Xcode/DerivedData/JWFNS-azshgysfabycfagnebotitpcyaww/Build/Products/Debug-iphoneos/JWFNS.app/JWFNS'
This is the big one. I cannot seem to build the .app.dSYM file properly. I went in and deleted the build folder, I looked at EVERY stackoverflow question I could find and tried changing any random thing mentioned in another question, but all of it is to no avail. I'm so suck right now. AHH. PLEASE. Any help would be so appreciated!
Maybe your project has become hopelessly corrupted. One thing to try is to start a brand new project and copy/import all your sources/assets into the new project to see if that fixes the problem.
Another less nuclear (but perhaps more time consuming) approach is to binary search the build. Exclude absolutely everything except main.m and see if that fixes the problem. If it does, include half your sources, and buid again....repeat, trying to narrow in on the problem spot. Maybe a file or group of files has received special build settings that don't belong there.
I've had very similar problems, I cant remember the exact error message but it was very similar. Are you able to make a new project that will run on your device?
if so (and I know this sounds bad but it's worth a try) Create a new project and simply copy all the code and resources across and see if it still works. If it doesn't then there is something wrong with you code and you can continue trying to isolate the problem from there.
Hope this is helpful.
check the frameworks you link to. there's a chance that you linked a framework (say quartz) of osx, instead of ios.
Answering in detail is probably going to take looking at your target settings. But it looks like you may be building for the wrong architecture. (It doesn't link, so there is no .dSYM symbol file.) For example, if you have only recently built for device, you probably created your project under an older Xcode, and it may not have the arm6/arm7 settings right.
To check, show the Build Settings for your target (not the project), and filter on Architecture.
Make sure that in build settings the architectures are armv6 and armv7. Also make sure that in .plist file, the "Application requires iPhone environment" is TRUE. Delete "Required device capabilities" in the .plist if present.

Xcode falsely claims CFBundleExecutable to be (null)

I'm trying to create an ad-hoc build of an iPhone app for beta testing.
On their end, they're seeing an error like the following:
"The info.plist for application at xxx specifies a CFBundleExecutable of (null), which does not exist"
Here is an excerpt from the actual info.plist:
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
And it clearly is not null.
What am I doing wrong here?
The WORKING SOLUTION is this (and only this):
In Xcode, choose “Executables” from the project hierarchy. Click your project executable then press Command-I. Choose the General tab and set the working directory to “Build Products directory”.
Found via BrainwashInc, who credits MacHackShack. I thought this valuable information was way too important to leave floating around on random blog.
It seems like sometimes XCode may flip this setting, as I suddenly started having this issue, and the fix above repaired it. Changing it back to "project directory" reproduces the issue for me, every time.
I also had to restart XCode to get the debugger to work once this fix installed the app, that may be unrelated.
I don't think there is ONE working solution to this. I found several solutions that doesn't work for me. At the end, I did find one solution.
By deleting whatever I had in the "Producs" folder in xCode I managed to get it working. I am using xCode 3.2.1.
Note: I did the change regarding "Build Products directory” above as well, perhaps both solutions needs to be implemented, up to you to try it out.
This is, to say the least, quite anoying. As a beginner, things are complicated enough without bugs in the SDK...
Hope this will help someone out there!
Cheers
It sounds like you're looking at the info.plist in the project not the built product.
The '${EXECUTABLE_NAME}' in the project info.plist is just a place holder for a variable in the build script. You need to look at the info.plist in your built product to see what is listed there. It sounds like for some reason, the build script is not populating the field as it should.
You might actually check that the contents of the application package actually has an executable. Sounds weird I know but a few years ago I mucked about with my build setting son a project and ended up with a product without an executable. Everything else, the package, resources, string files etc was there just no actual program.
This is a know issue of SDK:
Changing an iPhone Executable's working directory from “Build Products directory” may cause the application not to install properly with the error message “The Info.plist for application at (null) specifies a CFBundleExecutable of (null), which does not exist.”
as you can see here:
http://developer.apple.com/iphone/library/releasenotes/General/RN-iPhoneSDK-3/index.html
For me, it worked to change the working directory.
I created the problem deleting by hand the build directory.

When my colleague changes code and commits it to the repository I can see the code, but xCode compiles as if his contributions weren't there

Have any other iPhone developers experienced this phenomenon? I can see his contributions in xCode - I see for example my colleague has wrapped a navigation controller around one of my view controllers and added it to my tab bar. Great! That view really did call for a navigation controller and this is a welcome addition to the project.
So, I up my code and compile - no navigation controller. I do build -> clean all targets, thinking maybe some pre-compiled code is mucking me up and compile again. Same result. I was eventually able to get his changes to compile by deleting the whole directory and checking it out from the repository, but I really don't want to do that every time my colleague checks in code.
Is there some kind of box I need to check or something? What could be causing this behavior?
Thanks in advance.
Here are a number of possible fixes:
1) Delete the current version of your app off the simulator and/or device. This especially becomes necessary when using Default.png or app icons. There are a lot of shortcuts that the compiler takes for apps that are already "installed".
2) Make sure that there are NEVER any build folders or user specific files (pbuser.USERNAME I think). These files wrecked havoc on a few projects and we basically had to delete and start over.
3) Make sure that all files are svn added to the project before each commit (although this wouldn't matter for your current problem.
4) Find the changed code and set breakpoints for the debugger to catch. I believe that breakpoints that turn YELLOW while running signify that there is a difference between run and code.
I would tend to believe that it would be a problem with the .proj file also, but it sounds like that's not it.
Some things to check (but maybe you already did it):
is the new code added to the correct target? You will still see it in the project tree, but it won't be compiled
if you are using a SVN (or CVS) client that is not XCode, you have to remember to commit (and update) the .xcodeproject file too.
Your question isn't entirely clear to me, so forgive these follow-up questions:
Where in Xcode did you see the changes? In the repository browser, or in the file browser part of Xcode?
What do you mean by "up your code"? (I'm assuming you mean that you chose the "Update source from repository" option or whatever it is called - I'm away from my mac right now - but I thought I'd check.)