Submodules in Swift

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 for enum). Simple import 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



Leave a reply



Submit