Swift - Building a custom framework

Swift - Building a custom framework

A quick tutorial for building and importing a custom SDK to your project.

save it for a rainy day...

Ceating a Framework:

  1. Create a framework in Xcode :? File -> New… -> Framework
  2. Uncheck “include tests”?
  3. Add code to your framework (a public class \ struct)
  4. Build (otherwise the new code won’t compile and be part of the framework!)

Create a workspace in your project:

  1. Open a new\existing project you want to import the framework to.
  2. Import the Framework to your project by drag-dropping the framework’s .xcodeproj file. This will pop-up a question: “do you want to save this project in a new workspace”?? →?
  3. Create a .xcworkspace file by Selecting “Save”.
  4. save it in the root folder next to the project’s .xcodeproj file.
  5. You’ll see that the workspace is colored in red - that’s because you need to open the xcworkspace file.
  6. Open the .xcworkspace file

No alt text provided for this image

Add Framework to the Project

  1. Go to the general settings of the app’s target
  2. Under “Frameworks, Libraries, and Embedded Content” section, hit the + button and Add your framework.
  3. If you don’t see the framework in the tree-list, add it with Add Files… drop down menu choose the .xcodeproj file. This will add a group named Frameworks in your file inspector, and Do again the previous instruction (#2)

No alt text provided for this image

Quick Reminder - Access modifiers

private - declarations are accessible only within the defined class or struct

fileprivate - declarations are accessible only within the current swift file

Internal - declarations are accessible only within the defined module (default)

public - declarations are accessible by other parts of code but cannot be subclassed

open - declarations marked as open can be subclassed and overridden respectively out of their defining module.

Netanel Stern

CEO and security engineer

3 个月

???? ??? ?? ?? ??????! ??? ????? ???? ?????? ???: ?????? ????? ??? ??????? ?????? ??????, ?????? ?????? ??????,?????? ????? ????????. https://chat.whatsapp.com/IyTWnwphyc8AZAcawRTUhR

回复

要查看或添加评论,请登录

Aviram Netanel的更多文章

  • UIKit vs. SwiftUI - TableView \ List

    UIKit vs. SwiftUI - TableView \ List

    I wrote 2 projects that shows a tableview \ list with expandable cells. The idea is simple: you have a table \ list…

    4 条评论
  • Swift - didSet{...} Property Observer

    Swift - didSet{...} Property Observer

    if you're not familiar with the 'didSet' property observer - this is for you: with this simple trick you can execute a…

    1 条评论
  • Swift - the 'required' keyword

    Swift - the 'required' keyword

    Did you ever get this error? 'required' initializer 'init(coder:)' must be provided by subclass of..

    1 条评论
  • Swift - Array map, flatMap & compatMap

    Swift - Array map, flatMap & compatMap

    map, flatMap & compactMap are Array methods for manipulation. here are few simple examples to help you understand, and…

  • SwiftUI Pagination

    SwiftUI Pagination

    Pagination in SwiftUI & MVVM. In this example I'll show how to handle pagination: 1) Let's start with our ContentView:…

    2 条评论
  • The keyword 'some' - Swift \ SwiftUI

    The keyword 'some' - Swift \ SwiftUI

    If you ever started a SwiftUI project, you've probably noticed this 'some' keyword. so what's that? The keyword 'some'…

    7 条评论
  • Static - when do we use it?

    Static - when do we use it?

    First, if you don’t know the difference between Type & Instance: Type is the definition of a class \ struct . Instance…

    9 条评论
  • UIViewController - Lifecycle

    UIViewController - Lifecycle

    This is one of the most common questions in interviews, so you better know this one. In General Every view controller…

    9 条评论
  • @escaping closures in Swift

    @escaping closures in Swift

    In short: We will use @escaping when the closure needs to outlive the life of its function More: when we pass a closure…

    5 条评论
  • Arguments and Parameters

    Arguments and Parameters

    Arguments and Parameters What's the difference? Parameter is the variable in the declaration of the function. Argument…

    4 条评论

社区洞察

其他会员也浏览了