I have following issue: I have an iPhone application which can be compiled using various color styles. So the goal is to have several build configurations with defined style, for instance COLOR_STYLE_BLACK. Style definition files should be placed under some subfolder in source tree, like, for example Classes/styles/black. Then, in App_Prefix.pch I'd like to #import files from respective subfolder, like following:
#ifdef `COLOR_STYLE_BLACK`
#import "styles/black/DefaultStyle.h"
#endif
But the issue is that I cannot make XCode to import files from subfolders. It seems XCode does not allows folder structures in project, or at least I cannot figure out how to do it.
When I add folders as folder references to the project, XCode copies them to the Rersources folder, but does not add them to Compile sources build phase and reports errors on missing files.
Thanks for any tip or advice on this.
Matthes
The bigger issue here is that you're hardcoding your theme in sourcecode.
Its only ever the most extreme customisation that should be done this way. Its sound advice that your theme should be in artwork and you should select it at runtime by varying the path you load the artwork from and such.
Related
We have a project with nearly 1K Swift files. It just works well if everything is inside groups, but when trying to add some folder references to directories that contain Swift files, the compiler just can't see any thing defined inside these files (classes, for example). It works well for bundle and data files, but not for source code.
I also tried changing existing groups to folders using different methods (dragging, using the menu and manually browsing, etc.) and XCode stops seeing the entities declared inside these Swift folders' files. When I switch the same folder back to a group (delete -> remove reference -> add files to project...), it works again.
Please note that I opened the File Inspector, and already ensured that the target for the reference folder was checked. Also tried to uncheck it and checked again, just in case there is just-another-XCode-bug when adding files. Nothing worked.
Another experiment that I've done was consisted of moving a folder to the root directory, so the folder was not inside a group. Didn't work either.
After each try, I always cleaned the project's build folder, just in case.
Please note that the following questions did not provide anything useful tip for fixing this:
Xcode added folder in blue and related there files are not compiling
Moving Files into a Real Folder in Xcode
And of course, this another one does not make sense to me since I want folders, not groups, because I find them much easier to use and specially, to maintain, given the large amount of Swift files of this particular project: Adding Folder to Xcode Project is not Properly added
It works well for bundle and data files, but not for source code.
Yup, well, that's because those are completely different kinds of thing, and need to be treated in completely different ways.
You can't put code inside a folder reference (blue). That would simply mean "copy this code file into the body of the app", which would be silly. That's the kind of thing you would do with bundle and data files.
If the problem is to organize your code file references within the project window, you can use:
a group (yellow with a red mark in the lower corner)
or, a folder-linked group (yellow plain and simple)
In the latter case, the code file itself will also be placed in the corresponding folder on disk inside the project window, so this is also a mode of organization on disk.
NOTE But note that you must always let Xcode itself organize the contents of the project folder! You must work entirely within the Project inspector in the project window. Stay out of the Finder. Otherwise, you'll break your 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.
I am fairly new to ios development - trying to use sdwebimage in my iphone project. I believe I completed all basic setups as required. But when I build, I get this error: No such file file or directory near this line:
#import "UIImageView+WebCache.h"
Yes I have added Target Dependencies
I have added libSDWebImage.a in Link Binary With Libraries
I have -all_load -ObjC in Other Linker Flags
I also tried the -force_load ${BUILT_PRODUCTS_DIR}/libSDWebImage.a (64bit mac)
My Use Header Search Paths is : $(BUILT_PRODUCTS_DIR)
I cleaned the project and rebuilt - but no use.
Build keeps failing. Again, XCode4 code completion "resolves" when I type #import "UI & hit "ctrl+space" which means the lib is visible to xcode. Any pointers will be super helpful. Thanks.
To add the needed header files to the build path do the following.
Select your project file
Select your target
Select Build settings
In the search box enter 'header search paths'
For the Release add "$(SOURCE_ROOT)/SDWebImage" (thats with quotes).
This will work when importing like this #import <SDWebImage/UIImageView+WebCache.h>
I also use SDWebImage.
In my experience I didn't do anything with the linker flags etc.
You only have to add the classes in your project and simply import the "UIImageView+WebCache.h" in your class' header like this:
#import "UIImageView+WebCache.h"
and if you want to use it on an UIImageView object, just use the method
setImageWithURL:placeholderImage:
you can refer to their github for more info
I just ran into this problem and have solved it.
The issue is that when you "drag" the SDWebImage xcode project to your project, Xcode only create a reference to point to those files needed. When you are in debug mode it's fine, it knows where to find those file. However, when you want to archive it (packing everything to be self-contained), it couldn't find it from your search path.
Although you have added $(BUILT_PRODUCTS_DIR) to your search path, but if the actual files that you downloaded are not physically located in your $(BUILT_PRODUCTS_DIR), then Xcode won't find them. This was the problem for me since my SDWebImage files were still sitting in my download folder.
What you want to do is:
1.Move the SDWebImage folders to a place where you won't accidentally delete it. Notice once you've done that, the SDWebImage project file will become red since it's physical location is moved. And it's wired that I could not delete that reference in Xcode, what I ended up doing is add that file again (choosing from the location where I just move it too). You will end up with a red SDWebImage.xcodeproj in your project navigator which you can not delete. It's very annoying but it won't affect anything.
2. If the location you move the SDWebImage stuff to is not in your $(BUILT_PRODUCTS_DIR), then you either move that inside $(BUILT_PRODUCTS_DIR) or as I do, add the path to Target -> Build Settings -> Search Paths -> User Header Search Paths.
Archive and it should work now.
I faced this same problem and was about to go crazy. Like Ravi, I followed the static installation instructions as closely as possible.
I saw the auto suggest for UIImageView+WebCache.h when I was typing #import, but it keeps throwing file not found.
In the end, it was this. In header search paths,
“$(BUILT_PRODUCTS_DIR)” - Wrong.
$(BUILT_PRODUCTS_DIR) - Right.
Embarrassed but now it's working right =)
I've been dealing with this problem for the past hour and noticed something that hasn't been mentioned: Make sure that when you up update header search paths that the "Recursive" option is selected! Otherwise the compiler will not check subfolders.
Worked for me...
I was dealing with the same problem, my two frameworks were not getting found. I tried all the suggested ways in order to resolve the error but it couldnt help. Atlast I deleted the frameworks from my project structure and reloaded them from the original project file and it worked!! Please try this if it helps, It worked for me...
I had a similar issue after pod update. If you are using CocoaPods version higher than 1.0.0 and more than one target in your project, you have to add all the targets into the Podfile.
UPDATE:
Here is more detailed compiler output:
So I am working on a simple app. I want to be able to do some encoding/decoding of strings, so I have added these three files from the Google Mac ToolBox to my project:
GTMDefines.h
GTMNSString+HTML.h
GTMNSString+HTML.m
Since my project uses ARC, I have added the files to the build phases and set the -fno-objc-arc flag so they don't compile with ARC. See the screenshot:
Now I go to my main view controller and add this line:
#import "GTMNSString+HTML.m"
And I try to compile my project. I get errors like these:
How can I solve this? I am new to iOS development so please explain well.
To get rid of the first two warnings (no rule to process file...) remove GTMDefines.h and GTMNSString+HTML.h from your "Compile sources". Only .m-files need to be there.
You never want to import .m files, even if it's technically possible! To get rid of your errors, change your import from
#import "GTMNSString+HTML.m"
to
#import "GTMNSString+HTML.h"
The instructions for installing the JSON Framework seem to be for older versions of Xcode. I'm relatively unfamiliar with Xcode and I can't figure out how to properly import the framework into my project. I selected all of the files in the "Classes" folder (JSON.h, NSObject+JSON.h, etc.) that comes in the download, dragged them into the main area of my project, and added #import <JSON/JSON.h> to my ViewController's .h and .m files, and I get a No such file or directory error for JSON/JSON.h
What am I doing incorrectly here?
If you’ve placed the files under the Classes group and haven’t taken any further action, they’re at the root of your project directory. As such, import it as
#import "JSON.h"
I think you're indicating that you're importing JSON.h from the JSON folder, and it sounds from your description you don't have those in a folder...