I want to split my codebase into a library which I want to upload to github and an GUI application. I hope that using recently introduced SwiftPM is a good idea.
But all examples I've been able to find show creating a console application with swift package init --type executable.
I want to know how to create a skeleton for macOS Cocoa Application with all the pregenerated stuff like assets, storyboard and so on?
It would be great to have access to such useful thing as:
swift package build
swift package test
swift package update
...
Any ideas?
Thank you!
This is my working solution for creating cocoa apps with SPM.
Create your executable version of application: swift package init --type executable
Include your packages in Package.swift
Update/fetch them: swift package updateor swift package fetch
Create your .xcodeproj: swift package generate-xcodeproj
Open your .xcodeproj with Xcode; you'll see it as a console app.
Build your solution (this build will create dependencies: .frameworks, under 'Products')
Click the project name to see the targets
Add a new target by pressing + button below the list, and create your cocoa/gui app
After adding the app, click the app name on the targets list
Under General tab locate Embedded Binaries section.
Press + to add binaries, and select your referenced libraries.
Work on your cocoa app.
When you build, .frameworks will be embedded into .app
If you update your packages.swift, you should repeat above, except creating the new target; you'll just need to add it to the project.
Related
I want make some changes in plugin. For android part everything is clear. But how can I open iOs part of plugin? There are no Xcode project just several .h and .m files.
How to open iOs plugin at Xcode?
https://github.com/flutter/plugins/tree/master/packages/video_player/video_player/ios
First, be sure to run the example app at least once.
$ cd example
$ flutter run
Then open the project in Xcode. The Xcode project is in example/ios. The swift (or obj-c) code that implements the iOS end of the method channel is found in (replace the italic strings with the actual plugin name):
Pods/Development
Pods/plugin_name/../../example/ios/.symlinks/plugins/plugin_name/ios/Classes
which you can find by opening the tree in the left pane.
go to root of package then.
cd example
flutter build ios --no-codesign
Launch Xcode.
Select File > Open, and select the hello/example/ios/Runner.xcworkspace file.
The iOS platform code for your plugin is located in Pods/Development Pods/hello/../../example/ios/.symlinks/plugins/hello/ios/Classes in the Project Navigator.
The quickest way to open Xcode is xed ios when you are in the root project directory.
The plugins are put in $project_dir/ios/Pods
The plugins are actually installed by running pod install. flutter run will call pod install for you while also building the app. If you want to save time, just run cd ios; pod install and don't build your app.
I am developing an Ionic Capacitor plugin which imports 2 iOs .framework files and a .bundle that refers to one of this .framework files. The thing is that no matter how I link/embed and point/copy this files on the plugin project, xcode claims, on the app project, that it cant find the module in the swift file.
I already tried to add the files to the project, used the "Embedded binaries" option, linked libraries, allow non-modular includes (on build options menu), add the files to the headers (on build phases), and so on....
The line that xcode point the error is:
import OneFramework
And xcode claims:
No such module 'OneFramework'
I was expecting that when I add the plugin to my app project via npm, and later running a "$ rm -rf ios && ionic capacitor run ios" to run the app, xcode find all the modules of the plugin that I am trying to do.
I found the solution. To achieve this the first thing to know is that when you do npx #capacitor/cli plugin:generate what the CLI do for you is the generation of a cocoa pod. The root of this pod is the generated folder itself.
With that in mind, the next thing to do is to learn how to make pods, but i'll sumarize the principal aspects that led me to the success.
-First of all you open the *.xcworkspace. Followed by that, click on the "Add Files to Pod..." option and add your files. Please ensure that the "Copy files if needed" option is marked. Please refer to the picture below.
-Now its nice to create a folder for your .framework and another for the .bundle (if there are any) files. Do this by right clicking the Pods project and select the option "New group". Select a name like that is different from the pattern of xcode, it is nice to know that this folders are created by you.
-If you done this right, the frameworks you recently added to the project will appear on the pods project like this:
-Now, for your swift implementation find your files, drag your .frameworks that are on the pods project for the "Frameworks, Libraries and Embedded content" of the plugin project. The result will be something like this:
-Ok, files included and linked. Now we should let our cocoa pod know about this and declare this files. The file "YourAwesomePlugin.podspec" (located at the root of the plugin project) is the main entrance of the pod. In this file you will declare which files (.frameworks, .bundle, etc) belong to your pod and consequently will belong to your plugin when you npm install it. To declare this you'll need three directives:
s.vendored_frameworks = 'ios/Pods/YourFrameworkFolder/**'
s.resource = 'ios/Pods/YourResourceFolder/YourBundle.bundle'
s.xcconfig = {'ENABLE_BITCODE' => 'NO'} #This is mandatory on my case, but you need to evaluate if this options applies to your plugin.
-Now we hit play on the plugin project. To test on your app if the plugin is ok, you need to add the path of the root of the plugin project on the podfile of the pods project of the APP project. Like this:
-To install it you can go on Yourproject/ios/App and run pod install.
Please note that:
To declare the existence of your recently created plugin you you need to do some declarations as well, but this part is easy and already documented on capacitor/plugin docs.
The installation method via pod install that I suggested is for testing. It would be nice if you pack your plugin using npm and npm install it like all other plugins.
I dont have much knowledge on cocoapods like I wish, but this works and I think that is a clean solution. If not, please let me know.
If this answer is useful for you, please thumbs it up, it is a week of research and trying that I am sharing, along the time to write it all down.
I want to know if there is a way to enable swift support for flutter project. I only enabled Kotlin support while creating the project. I need to enable Swift too. Is there a command I can execute or any setting in flutter plugin for Android studio where I can enable or is there is an option to enable in Xcode?
This is what I want to do but for existing Flutter project
Delete existing ios folder from root of flutter project.
Run this command flutter create -i swift .
This command will create only ios directory with swift support.
Well, I search the same thing now, also I enable the kotlin support...
so, how to enable swift or kotlin support for a existing proyect?
For swift support, you need to move your ios folder to outside of your project folder, for kotlin move outside the android folder, also check your package name in your manifest, or your PRODUCT_BUNDLE_IDENTIFIER
Run the below flutter command in your terminal on root folder of your proyect (I'm using com.custom_name.my_proyect for the package name of this example)
-i swift is for swift
-a kotlin is for kotlin.
--org is to set the first two words of your package, in this case com.custom_name
--project-name is to set the last word of your package in this case my_proyect
You can use only switf/kotlin or both, (Don't forget the period '.' at the end of the command)
flutter create -i swift -a kotlin --org com.custom_name --project-name my_proyect .
*Apply again your previous custom changes on the ios folder (E.g: info.plist, custom splash screen, etc.), now in Runner folder you don't have main.m and AppDelegate.h files, instead you have only the AppDelegate.swift file in swift language, so if you need to put API_KEYs there, the code is different.
*If you apply -a kotlin line, is the same logic that swift in your android folder, so your MainActivy.java file is now a MainActivity.kt file in kotlin language, and you need to apply again your previous custom changes in Android folder (E.g: build.gradle, res folder, android_manifest, etc.).
Little known secret -- you can run flutter create . in your Flutter app directory and it will repair the project, recreating any files that are missing. So if you already have a project created with Objective-C and Java, you can run:
flutter create -i swift -a kotlin .
to convert the host app to Kotlin and Swift.
(Ignore Kotlin you you want, but my experience is that just leave it there)
Bridging Header must be created.
Open the project with XCode. Then choose File -> New -> File -> Swift File.
A dialog will be displayed when creating the swift file(Since this file is deleted, any name can be used.). XCode will ask you if you wish to create Bridging Header, click yes.
Make sure you have use_frameworks! in the Runner block, in ios/Podfile。
Make sure you have SWIFT_VERSION 4.2 selected in you XCode -> Build Settings
Do flutter clean
Go to your ios folder, delete Podfile.lock and Pods folder and then execute pod install --repo-update
For the scenario where you already have an ios module partially written in Objective-C, and now just want to use Swift code alongside, than I suggest you to right click on ios in project window and choose Open iOS module in XCode this from context menu
Than you can just follow those instructions:
https://developer.apple.com/documentation/swift/imported_c_and_objective-c_apis/importing_swift_into_objective-c
If your plan is to rewrite module in swift than I'd create a new project with the same name as your original one and turned on Swift support. Than I'd just copy the whole ios module to your original project.
First delete AppDelegate.h, AppDelegate.m, main.m files
And also remove main.m from build phases -> compile sources
After that run this command
flutter create -i swift .
How do I add an external library to my xcode project?
Currently I'm trying to add this camera library , and I thought it was just about adding the pod and installing it but when I try to add the import LLSimpleCamera I get no such module "LLSimpleCamera".
Any help?
Could you be opening Animal-Spotting.xcodeproject file instead of Animal-Spotting.xcodeworkspace?
You could always try the classic "clean build & delete the derived data"
I'm new to jailbroken dev. I have a regular xcode application project. Now I need to convert it, or create a new application project using iOSOpenDev for jailbroken dev. I found the same question:
xcode project conversion to iOSOpenDev
But I have no idea what to do with the first step. Do I need to add some settings or change some values of existed settings? Pleas give some more details.
thanks!
About the first step, I did some tryings and it worked out. The following steps is just the same as kokoabim said:
1.change the install path to /Applications; add iOSOpenDev's include,lib,framework folder path to Framework Search Paths,delete iphonesimulator from Supported Platforms in Build Settings, Header Search Paths, Library Search Paths(I'm not sure if it's necessary);
Add a run script build phase (must be last in order) to existing target that executes /opt/iOSOpenDev/bin/iosod --xcbp.
3.Create the Debian package control file under the existing target's folder as (target's directory)/Package/DEBIAN/control.
4.Perform a Build For Profiling (Cmd-Shift-I).