Even if I don't use obj-c, do I have to make a header file to modularize the app? - swift

I'm studying a clean architecture project.(https://github.com/sergdort/CleanArchitectureRxSwift) In this project, each directory creates a header file and references the class through a header file in a different directory file. I think they made it like this for modularity. I searched for it, and it seems that the header file is only used to insert the obj-c code into the Swift code. Is it common to make header files just for modularity without using obj-c?
Application.swift
Domain.h

Related

How to retrieve bridging headers that has been lost

I was trying to put a facebook login in my app. I'm also checking some of the tutorials that'll help me to do this. Then i have created a header file that i also delete since that i wasn't able to accomplished the tutorial that i'm watching. Then all of a sudden, i'm having an error that stating...
Briding Header 'Users/mac/Desktop/App
Files/myApp/myApp-Bridging-Header.h' does not exist
I don't know why is that happening. I try to delete my .swift file and replace it with the same name then it still having an error. I even try to make a .swift file with a different name but still having an error as well.
In build settings.. in “Swift Compiler -Code Generation”—> Objective-C Bridging Header — “reset the Path of Bridging header file”
How to create a Swift Bridging Header Manually
Add a new file to Xcode (File > New > File), then select “Source” and
click “Header File“.
Name your file “YourProjectName-Bridging-Header.h”. Example: In my
app Station, the file is named “Station-Bridging-Header”.
Create the file.
Navigate to your project build settings and find the “Swift Compiler
– Code Generation” section. You may find it faster to type in “Swift
Compiler” into the search box to narrow down the results. Note: If
you don’t have a “Swift Compiler – Code Generation” section, this
means you probably don’t have any Swift classes added to your project
yet. Add a Swift file, then try again.
Next to “Objective-C Bridging Header” you will need to add the
name/path of your header file. If your file resides in your project’s
root folder simply put the name of the header file there. Examples:
“ProjectName/ProjectName-Bridging-Header.h” or simply
“ProjectName-Bridging-Header.h”.
Open up your newly created bridging header and import your
Objective-C classes using #import statements. Any class listed in
this file will be able to be accessed from your swift classes.

including a header from a project into a static library

I have a subproject (static library) inside my project.
As this static library may be used by a bunch of app, I have this config.h file on my project that contains the app configuration. The static library must read it.
The problem is that adding
#import "config.h"
on the static library fails, because the file cannot be found.
I could add an absolute path to my project root on the search headers, but I want to make this not hard coded because this static library will be used by other projects. Another problem is that I cannot use relative links like ../.., for example, because the static library is on another volume.
Including $(SRCROOT) on the search paths of the static library will give me the root for that library not for the project using it, that is what I want.
How do I solve that?
Just pay attention to my question. I am inside a static library that is used by a project. Config.h is out there in the project. I want to import that config.h on my static library.
If there is an easy way to do that, please tell me.
I have uploaded a sample project to here and here, so you can see my pain.
thanks
One way, somewhat of a hack, is to add a Run Script to each App's Build Phase, as the first item, and have it copy Config.h to some known place - /tmp/Config.h, and your included library will look for it there. Since the file is copied on every build, it will always be proper.
EDIT1: So not pretty, but you can add a Run Build Script to just under the Dependencies in the library. Just add one and leave the checkbox set to show environmental variables. You can see this one set:
FILE_LIST=/Volumes/Data/Users/dhoerl/Library/Developer/Xcode/DerivedData/MyProject-fdzaatzqtmrnzubseakedvxmsgul/Build/Intermediates/MyStaticLibrary.build/Debug-iphoneos/MyStaticLibrary.build/Objects/LinkFileList
What you can see is that several of these have as the prefix the current project folder:
/Volumes/Data/Users/dhoerl/Library/Developer/Xcode/DerivedData/MyProject-
You can write some script there to get the prefix, then append the local Config.h file path, and now you have a fully qualified path to the Config.h header, which you can then copy to a known location in the library. I'm going to post on the xcode forum as there may be a better solution - there use to be in Xcode 3. I'll update this if I get anything substantive back.
EDIT2: Try This:
1) Click on the library, click on Build Phases, add a Run Script Build phase by tapping bottom right '+' button
2) Drag it so its the second item in the list (below Target Dependencies)
3) Change the Shell to "/bin/ksh"
4) Paste this in, after editing it to have the proper files/paths:
# Get the Project Name (assumes upper/lower/numbers only in name)
PROJ=$(echo $BUILD_DIR | sed -En -e 's/(\/.*\/)([A-Za-z0-9]+)-([a-z]+\/Build\/Products)/\2/p')
# Use this variable to construct a full path
FULL_PATH="/Volumes/Data/Users/dhoerl/Downloads/nightmare/"$PROJ"/"$PROJ"/HelloWorldLayer.h"
echo FULL_PATH equals $FULL_PATH
# Make Sure MyStaticLibrary is correct
echo PROJ_DIR equals "$PROJECT_DIR/MyStaticLibrary"
cp -f "$FULL_PATH" "$PROJECT_DIR/MyStaticLibrary"
5) This assumes that you put the library anywhere you want, but each App project has to havethe same parent folder (not much of a restriction - what I did in the past).
PS: When I do this kind of thing, I usually don't include an actual file of the app, but create a header for a class that is not instantiated in the library. Lets call this Foo. So in your library, you have Foo.h, and it has lots of methods that return info - the number of widgets, the location of some special folder, plists, arrays, dictionaries, whatever. The idea is the library knows how to get whatever it needs through this interface (class singleton, or just a class with class methods. YMMV.
PSS: anyone else reading this, it pays to create demo projects.
I'd go a different route. Make this config.h file part of the static library using compiler symbols in it to switch features. Then in your projects define those symbols depending on what features you need.

xcode create constant/variable as a build setting?

I have a URL used multiple times in my code and would like to centralize it into something like a build setting constant/variable. How would I go about accessing a build setting from my code? And is this the right thing to do?
Thank you.
Constants.h
static NSString * const myStackURL = #"http://stackoverflow.com/users";
or
#define myStackURL #"http://stackoverflow.com/users"
What you want to do, essentially, is import a header that defines a constant into every one of your other files. The easiest way to do this is to stick it in (application name)-Prefix.pch in the Supporting Files group in the project navigator. Anything defined in this precompiled header can be used by any other file. From Programming iOS 5 by Matt Neuburg:
The precompiled header is a device for making compilation go faster.
It’s a header file; it is compiled once (or at least, very
infrequently) and the results are cached (off in /var/folders/) and
are implicitly imported by all your code files. So the precompiled
header should consist primarily of #import directives for headers that
never change (such as the built-in Cocoa headers); it is also a
reasonable place to put #defines that will never change and that are
to be shared by all your code.

Gsoap undefined references

I'm trying to use and web service with gsoap. I've already generated all *.h and *.cpp using wsdl2h and soapcpp2, included all libraries, at least I think so, but when I build the project it gives me the message of undefined references to a lot of methods. The thing is all methods are declared in soapH.h (the prototype) and in soapC.cpp (the implementation).
Any help will be appreciated.
It seems that you included some generated header files in your build, which should not. (e.g. the .h file generated from wsdl) There are descriptions in the comment section in each generated files, and you'd better read them to get familiar how to use them.
Also, if you use openssl, the library should also be included during linking process(-lssl)
Solved, All I need was the original header file, I was getting one from the wsdl.
In case anyone encounteres this problem: you do not have to include all the .cpp files in your makefile - some of them are included by the other. What you need also depends on whether you are building a client or a server.
Consult the documentation here to see which files are needed and for what.

How to invoked methods of external .h files in iphone

to all
In my iphone game I want to add external .h and .a files. I am adding them by using add project option given in Xcode. It get added but I want to invoked the methods given in the header files. As per instruction given to us we have to call one method which is declared in external header file. We have to call that method inside AppDelegate's applicationDidFinishLaunching method . But at the time of compilation it gives one error that is referenced from: and symbol not found. I don't understand how to invoked this method and how to get referenced for the method.
I am sending one link please see that. The same problem with my application is coming.
http://forums.macrumors.com/showthread.php?t=443437
In that three screen shots are given by some toddburch on Jan 24, 2009, 07:37 AM
The same error for my methods are also coming but my code is in Cocoa with objective-c not in ruby.
If anyone know the solution please reply me As soon as possible.
The .h is not enough. You also need the implementation, either source code or compiled framework.
Do you have access to the source code itself? Try dragging the .h and .m/.c files from the framework directory directly into your project. It's a little messy, but I think it will solve your problem based on the error messages you are getting. You can put them all in a group so your project doesn't look so crowded after you drag them over if you like.
You currently have two files
A *.h header file which describes the classes and functions available in your third party library
A *.a static library file which holds the pre-compiled code for the functions described by the *.h file.
Assuming you've got to the stage where you can #include or #import "xyz.h" and compile your application, the bit which is missing is linking your executable with the *.a file.
The symbol not found error message is the linker telling you it knows some of your code is calling a particular function, but it can't currently find another code module that provides an implementation of that function.
One thing to check is that your *.a file is correctly configured within your project to be passed to the linker. One way to do this is to expand the "Targets" section of the main XCode window. If you drill down into the section representing your application you should see a subnode labeled "Link Binaries with Libraries". Your *.a file should be listed, if it isn't one way to add it is to simple drag and drop the file into this section.