Swift submodules - what are they exactly
- Swift module equivalent to Java package, Swift framework is like Java jar. Submodule is just module inside of other module.
- Yes you can, but it if you want to import just a class you have to use
import class
(import struct
for struct,import enum
forenum
). Simpleimport
can be used only with modules. - No, they're not bound to the folder trees. They're defined using
Clang module
system, Xcode and SPM perform most of the boilerplate for you.
Submodules in Swift
While you can do something like
import struct MyModule.MyStruct
import func Darwin.glob
I'm not sure if you can get much deeper than that. Here's a relevant quote from the (free) Swift book
“Providing more detail limits which symbols are imported—you can specify a specific submodule or a specific declaration within a module or submodule. When this detailed form is used, only the imported symbol (and not the module that declares it) is made available in the current scope.”
It goes on to explain that you can import any of typealias
, struct
, class
, enum
, protocol
, var
, or func
It looks as though Swift has some type of support for submodules (they're mentioned offhand a few places), but I'm not sure we have the ability to actually compile those just yet.
Swift package with submodules like in CocoaPods
This is not something which is supported yet by the Swift package manager (customizing the behavior of a target based on how it is used by other targets).
If you have a package which you want to do this, for now you have to do it via some kind of runtime registration where the CoreData
module would register the fact with the Main
module that it needed this other bit of behavior.
Error not a git repository when adding git submodule? Swift 5.0 Xcode
There should be additional error lines after
git submodule add git@github.com:Shopify/mobile-buy-sdk-ios.git
Make sure first that you do have access to the remote repository with:
git ls-remote git@github.com:Shopify/mobile-buy-sdk-ios.git
Try also, for testing, the HTTPS URL:
git submodule add https://github.com/Shopify/mobile-buy-sdk-ios.git
That should avoid the SSH error:
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
If you do want to use an SSH URL, make sure your public SSH key ~/.ssh/id_rsa.pub
content is registered to your account first.
The exact error message was:
fatal: not a git repository (or any of the parent directories): .git .
That simply means the current folder (in which you are trying to add a submodule, any submodule) is not itself a Git repository!
You should create one first:
cd desktop/testmeAPP
git add .
git commit -m "First commit for testmeAPP"
See also "Using Git with an existing Xcode project"
Then try your git submodule add
command again.
Related Topics
Swift-Setting a Physics Body Velocity by Angle
Adding Index List and Section Headers to Translated Tableview
Convert Optional String to Int in Swift
Swift Array to Array of Tuples
Set Custom Uiview Frame in Uiviewrepresentable Swiftui
Classes in Swift Files Inside Folder References Not Seen by Xcode 10's Compiler
Is It Safe to Force Unwrap an Optional After Checking It Is Not Nil
How to Decode the Body of an Error in Alamofire 5
Menu Items Disabled in MACos Menubar App
How to Make a Segue to Second Item of Tab Bar
Adding Animation to Tabviews in Swiftui When Switching Between Tabs
File Couldn't Be Opened Because You Don't Have Permission to View It Error
Swift, Error Exc_Breakpoint (Code=1, Subcode=0X100695474)
Catch Any Error, Specially Unexpectedly Found Nil in Swift
How to Cast [Int8] to [Uint8] in Swift