enable target membership issue on .m file - ios

when i enable keyboard target extension on .m file then this controller give errors like Use of undeclared identifier. i am creating custom keyboard extension on swift and i want add objective c class on keyboard target extension like
when i disable custom keyboard like this
then app work proper but i required to enable extension target so, how can i solve this issue.
i already check bridging file and build phase in compile resource on both extension and host app target.
Thanks

Related

How to create the new target in Xcode for app extension using CMake?

I want to use Notification Content Extension in my Xcode project.
I use CMake to generate my project.
Now the project has only one target.
I can add the extension as new target manually in Xcode using menu File - New - Target - Notification Content Extension.
Could you provide an example how to create new Xcode project with additional target for app extension by using CMake?
Since CMake 3.8, you could use XCODE_PRODUCT_TYPE target property to let CMake generate specific type of application.
Minimal example that should troubleshoot you:
# add app bundle
add_executable(MyApp MACOSX_BUNDLE ${APP_SOURCE_FILES})
# add app extension bundle
add_library(MyAppExtension MODULE ${APPEX_SOURCE_FILES})
set_target_properties(MyAppExtension PROPERTIES
BUNDLE YES
XCODE_PRODUCT_TYPE com.apple.product-type.app-extension)
# link extension bundle with UserNotifications frameworks
find_library(UN_LIB UserNotifications)
find_library(UNUI_LIB UserNotificationsUI)
target_link_libraries(MyAppExtension PRIVATE ${UN_LIB} ${UNUI_LIB})
I tested on cmake3.23 on mac, app extension is a executable not library. It should be like this:
add_executable(MyAppExtension MACOSX_BUNDLE ${APPEX_SOURCE_FILES})
set_target_properties(MyAppExtension PROPERTIES
XCODE_PRODUCT_TYPE com.apple.product-type.app-extension)
Then you can embed app extension to app :
set_target_properties(MyApp PROPERTIES
XCODE_EMBED_APP_EXTENSIONS MyAppExtension)

Accessing a class of iPhone app in Watch App

I want to use my already developed NSObject Class in watch app (Watch App target is added to same project).
My iPhone App is written in Objective-C and now I am using Swift for Watch Extension, so I created a Bridge-Header to use this class in Watch App and add the class to Watch Extension target. When I build the app, it gives me many errors from other classes with this reason:
Cannot find interface declaration for UIControllerView, SuperClass of xxxxClass
And all these error files seem that they have a target of WatchKit Extension, but I didn't include them. On these files, Target Membership Watch Extension is also unchecked (means not a target of extension). Here are the Classes which I didn't added to Watch Extension, but they are running as a Watch Extension class.
You will need to select that class and check Target membership for WatchKit extension From file inspector.
For Swift class :
For Objective-C class you make it for .m file
You have the check the targeting files are added or not.
For that:
1.select your project file -->Build Phase-->Compile Sources.
-Check the file present or not.
2.if not just remove and add the files that are all missing in compile source.
3.Clean and Build your source..

iOS Sharing .h file between main app and share extension

I have all constant key in .h file. After that, I share that one between my main app and my share extension. However, my share extension doesn't seem to read that file and I can't use constant key from there. How shall I do?
You need to make an embedded framework that is imported by both the app target and the share extension target. That is how to share code of any kind between targets.

Using the same file with different flags in WatchKit and host App

I'm trying to use the same code in both my watchkit extension and host App, but with some additional code in the host App and some additional code in the watchkit extension. To do this I've added WATCH and APP swift flags on the respective targets. Problem is, when I look at my code with my App scheme selected, it doesn't syntax highlight the APP code but does highlight the WATCH code, and other code that refers to the APP code then fails to compile.
The watchkit extension is a target dependency of the App so I'm guessing it's something like it is compiling the code for the watch and then using the same compiled code for the App, although in the compile results I can see it is compiling with the correct flag and can't see any overlap between watchkit and App build paths, any ideas?
SWIFT version
Use other swift flags in build settings of your WatchKit Extension target. For example, add a flag WATCH (must be prefixed with -D):
Then in your shared file add this code:
#if WATCH
NSLog("watch")
#else
NSLog("app")
#endif
Objective-C version
Use preprocessor macros in build settings of your WatchKit Extension target. For example, add a macro WATCH = 1:
Then in your shared file add this code:
#ifdef WATCH
NSLog(#"watch");
#else
NSLog(#"app");
#endif

iOS / WatchKit: Is there a way for the watch kit app(swift) to use the iOS code (Objective C)?

I thought about using a bridging header, but I keep getting fail to import bridging header. Is it possible for watch extension (written in swift) to use code from the iOS App (written in Objective C)? I need to make sure I am doing this correctly and professionally. If I can use bridging header, why am I getting the following error?
:0: error: failed to import bridging header
It might something as simple as a path problem. But what I normally do is create a dummy Objective-C file so that Xcode will create that bridging header for me, then I just copy and paste the path into the extension's build settings.
I've included a demo project which calls a method from an Objective-C file that is imported in the bridging header. I've also had to add the file in the extension's build phases for it to work. I hope this is what you're looking to solve.
https://dl.dropboxusercontent.com/u/5296996/WKTest.zip

Resources