Import Specific Module in Swift

Pawan Manjani
Aug 14, 2022

--

We use to import modules in our Swift file like:

import UIKit

But what if I say we can import specific modules in our file instead of importing the entire module

https://giphy.com

Yes we can like below:

import UIKit.UIViewController

Let me give you more example

Suppose you have created the framework MyFramework and there you have enum, struct, class, etc but you want to use only enum from that Framework then you can import like:

import enum MyFramework.FlowType

Note: Make sure that enum should be public

If you try to use struct from same Framework then compiler will throw error like below:

If you want to use struct from Framework then you have to import like below:

import struct MyFramework.MyStruct

For more visit: https://ioslifee.blogspot.com

Thanks for reading, Happy Coding 💻

--

--

No responses yet