Xcode / Objective C - Dynamically import files (via folder, regex, etc.) - ios

I am creating an iOS framework (like an acyclic MVC) and want a Controller to be able to import all View files. The view files are all in a folder and have a *View.h naming.
Is it possible to import all views in one line by doing something like #import "/Views" or #import "*View.h"? What's the simplest way to dynamically import?
Currently I am importing a header file which contains the other header files. This works, but I would like a way to dynamically import so I can add a View and not have to update imports before using it.

I don't think you can do that because import is done during compile time. But you can archive the result by a script in which it generates the umbrella header contains all the #import "*View.h". Add it into Build Phases before compile sources

Related

How to add Obj-C Libs(with .h files) to swift in Flutter

I would like to ask how to add files / Libraries of Obj-C(for example: xxxx.a + xxx.h) to swift in flutter? I'm confuse where to put the import and how to import it, try to used linked libraries I tried to put 1 folder inside the linked libraries,
this is my libs folder which I want to put inside project
this is from my build phases --> Link Binary with Phases
this is sample picture from runner
but when I tried to import it in Runner-Bridging-Header.h:
#import "GeneratedPluginRegistrant.h"
#import "LibHealthCombineSDK.h"
it's give me error 'LibHealthCombineSDK.h' file not found
is my ways to put this libs is correct? if yes, how to used it inside swift?

How do I build an iOS Framework with the FIT C++ library

I am trying to create a Swift wrapper for the FIT C++ libFitSdkCppiOS.a library but don't really know how to set things up with the mix of C++, Objective-C and Swift code.
Here is what I have done so far:
1. Created a new target for the FITFramework
2. Copied the libFitSdkCppiOS.a library and the associated cpp header files into the targets folder in Xcode
3. Because you can't use a Bridging-Header file in Frameworks I am trying to figure out how what to do next.
I have seen a few posts about something called an umbrella header but have no idea what that is or what needs to be in it to get this to work. Can someone please explain step by step what I need to do to create this Swift Wrapper and package it up as a framework that can be used by other projects.
Is the umbrella header the main framework header file, in this case the one called FITFramework.h ?
If not how do I create an umbrella header file and where does it need to be?
What should be in the umbrella header file?
FITFramework.h
//
// FITFramework.h
// FITFramework
//
// Created by xxxx xxxxxxx on 7/6/18.
//
#import <UIKit/UIKit.h>
//! Project version number for FITFramework.
FOUNDATION_EXPORT double FITFrameworkVersionNumber;
//! Project version string for FITFramework.
FOUNDATION_EXPORT const unsigned char FITFrameworkVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <FITFramework/PublicHeader.h>
EDIT:
1. How do I expose the Objective-C classes to Swift without using a Bridging-Header file ?
There are a few articles that mention the use of a module.map file but this seems to be to expose the C headers rather than the Objective-C headers to the Swift wrapper function
OK I figured it out - and it was hard to find any good or accurate guides. I will write it up in more detail elsewhere and add a link at some point.
In the meantime - assuming your framework is call XXXFramework - you need to:
create a XXXFrameworkPrivate subdirectory in the XXXFramework folder with a module.modulemap file in it
add the private headers to the module.modulemap file like so
module FitFrameworkPrivate {
header "../XXX.h"
header "../YYY.h"
header "../ZZZ.h"
export *
}
create a XXX.xcconfig file with the following line
SWIFT_INCLUDE_PATHS = $(SRCROOT)/XXXFramework/XXXFrameworkPrivate
set the project configuration to use this config file for both debug and release
add this line to your Swift classes
import XXXFrameworkPrivate
Basically this allows Swift classes to import the headers from the module.modulemap file instead of using a Bridging-Header file which can't be used in a Framework.
Watch out though - I have callbacks between the C++ classes, the Objective-C classes and the Swift classes and this creates a problem if your public class uses a protocol to communicate with one of the private Obj-C classes. To avoid that add another public Swift class that talks to the Swift wrapper and only have that one public.
If anyone has a better way of doing it please let me know.
Thanks a lot! This answer was very useful to me as I had similar issue (to integrate the c fit sdk instead of the c++ fit sdk into a swift framework for macOS and iOS apps)
I'll just add the follow step I had to do, in case it helps someone:
When using the framework in a app that used Pods, I wasn't able to include the "Private" framework (necessary because it contains the c constant converted to swift constant like FIT_MESG_XXX) and the xcconfig are set by the Pods framework. Editing the Pods xcconfig worked, but clearly bad.
Eventually, I figured out you can just create a new xconfig with a #include and use that in the external app where you want to use like so (this is separate from the xcconfig you need to build the framework)
#include "../Pods/Target Support Files/Pods-iOSorMac/Pods-iOSorMacOSApp.debug.xcconfig"
SWIFT_INCLUDE_PATHS="$(SRCROOT)/fit-sdk-swift/RZFitFile/sdk" "$(SRCROOT)/fit-sdk-swift/RZFitFile/src"

using module.modulemap to integrate frameworks' objC header in Swift class

I have a framework that contains Objective-C header files. I want to use these header files in the Swift project, in which I am importing this framework.
There are two ways to do it
1) create bridging header file - but, then user will be dependent to create this file, while integrating the framework
2) create module.modulemap file - that I can ship with my framework and user can add it to (which build setting).... <- I need help here
I've tried Import Paths in Swift Compiler - Search Paths and Module Map File in Packaging
In both the cases, I am not able to import the header RandomHeader.
My module.modulemap looks like below
module ToBeShippedFramework
{
header "RandomPublicHeader.h"
export *
}
Is there something different that I need to do?
PS: Please put in comments if you need some more info to understand this question more clearly.

imported xcode generated swift header not found in .pch file

I have recently added a Swift file to my Objective-C only project. Xcode created the necessary header files, including the Objective-C Generated Interface Header. Everything works fine if I #import this header file "myProject-Swift.h" to the .m file where I am accessing the Swift class I have added.
However I will want to eventually use this Swift class throughout my project, and to avoid importing it every single time, I wanted to add this myProject-Swift.h import file to my .pch prefix file.
However when I try to build my app after having added this, I get a 'myProject-Swift.h' file not found error and the build fails.
Does this mean it is not possible to import this myProject-Swift.h in a .pch file?
Is it really only possible to do it in each .m file individually?

How to import Objc Files into my Swift files within my custom cocoapods framework?

Simple explanation. I have created my own pod with name BSSelectableView, but within I need to use two files written in Objective-C. What do I need to achieve?
I need to make it visible within my Swift files, and also for people who will install my pod.
Your Target needs a Bridging Header.
This is an Objective-C-Header-File with the name [TargetName]-Bridging-Header.h
Within this file, you have to #import all Objective-C-Headers you want to use in your Swift-Files.
You don't have to import anything in your Swift files.
More information about Swift and Objective-C mixed projects
You need to create a [TargetName]-Bridging-Header file in your project.
import all the header files in bridging header file
Now you can use all objective c file in swift.

Resources