[swift-users] noob question about modules

blaster_in_black blaster_in_black at protonmail.com
Mon Sep 18 05:40:17 CDT 2017


For the record, I will paste here the answer I have received on StackOverflow. It adds some useful tips to the info provided by Alex. In short,

Swift modules are somehow equivalent to Java packages, and Swift frameworks to Java .jars (if we don't get too formal);
Swift (sub)modules can be visible to clients and the latter can import them much as Java sub-packages are imported;
Swift (sub)modules are not implicitely defined by the source code folders layout, but by meta-files and tooling that are external to the source code (contrarily to Java).

https://stackoverflow.com/questions/46228517/swift-submodules-what-are-they-exactly

Cheers,

David

Sent with [ProtonMail](https://protonmail.com) Secure Email.

> -------- Original Message --------
> Subject: Re: [swift-users] noob question about modules
> Local Time: 14 September 2017 12:26 PM
> UTC Time: 14 September 2017 10:26
> From: swift-users at swift.org
> To: alblue at apple.com
> swift-users at swift.org
>
> Thanks much, Alex.
>
> But how do you physically partition the namespace within a module, if not by sub-folders?
>
> I am not sure whether the following example is, by definition, of a submodule that one could import by writing "import Cacao.StyleKit":
>
> Https://github.com/PureSwift/Cacao/tree/master/Sources/Cacao/StyleKit
>
> Sent from ProtonMail mobile
>
> -------- Original Message --------
> On 13.09.2017, 10:23, Alex Blewitt < alblue at apple.com> wrote:
>
>> No, submodules in Swift bear little relation to sub packages in Java. It's really just a way of partitioning the namespace within a single module. Nor is there any relation between the path and the name of the module either.
>>
>> Alex
>>
>>> On 12 Sep 2017, at 22:41, blaster_in_black via swift-users < swift-users at swift.org> wrote:
>>>
>>> Hi,
>>>
>>> I am beginning with Swift 4 (coming from the Java world) but I do not have yet a Swift development environment to experiment with. Therefore my question(s) might sound a bit silly. Unfortunately, I haven't been able to answer them by reading the online Language Guide.
>>>
>>> 1) What makes a submodule? I can see online examples about how to import them, but not how to create one or any other further details about them. Are they like Java packages inside a jar? Do their hierarchical name ( prefix1.prefix2. ... .submodulename) reflect a path tree on the filesystem (/ prefix1/prefix2. ... /submodulename), just as it happens with Java packages?
>>> 2) Can two different submodules within a single module export two different classes under a single class name? Like  module.submodule1.MyType and module.submodule2.myType.
>>>
>>> Thanks in advance.
>>>
>>> David
>>>
>>> _______________________________________________
>>> swift-users mailing list
>>> swift-users at swift.org
>>> https://lists.swift.org/mailman/listinfo/swift-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170918/430e706f/attachment.html>


More information about the swift-users mailing list