Skip to content

mikemoser/swift-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Swift Framework: Basic Project Setup Example

This is a very basic step by step example on how to setup a Swift Framework for reusable controls and code and wireup using a project reference in an Application project.

Create Framework Project

  1. Create new Cocoa Touch Framework w/ Swift
  2. Add New UIViewController - MyViewController Add test code to implementation of MYViewController
override func viewDidLoad() {
        super.viewDidLoad()

        // Create the label
        var label = UILabel(frame: CGRect(x: 10, y: 10, width: 200, height: 40))
        label.text = "I am an SDK ViewController"
        
        // Add them to the main view
        self.view.addSubview(label)
    }
  1. Close Project

Create App Project

  1. Create new Single Page App (Swift) - MyApp
  2. Drag and drop framework's “xcode project file” from finder into MyApp
  3. In MyApp -> Setting -> Build Phases -> Link Binary With Libraries - add MySwiftFramework.framework
  4. In the MyApp main.storyboard, select the view controller and change the custom class to SDKViewController

Note: For Swift, classes must be public and their initializers to enable use in external applications.

Open Questions

  1. Seems like you need to build after making changes in Framework before using in App. Would like this to auto-build.

About

Basic Project Setup for Swift Framework

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published