Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create and use an iOS Framework for sharing code with Extensions

How does the minimal setup and usage of a custom iOS framework look like? I starting to look into this in order to share code with a Today Extension.

Here's what I did so far

  1. Added a new Target choosing the Cocoa Touch Framework template and called it TesterKit
  2. Inside the framework I created a new class TestClass.swift
  3. Inside TestClass.swift I created a simple class method class fund tester() printing a string for testing

Looking at my app I can see that TesterKit has been added as Embedded Binaries and Linked Frameworks and Libraries, however it is red

  1. In order to use this new Framework in the app, I added import TesterKit to the top of my AppDelegate
  2. Then I tried to call the class method from the Framework using TestClass.tester(). But instead of showing the log message I get a …

    "Use of unresolved identifier"

→ What am I doing wrong? Any wrong assumptions here?

Note: I already watched the WWDC sessions 416 "Building Modern Frameworks" and found the Framework Programmign Guide. If there are any example projects showing how to use such new custom iOS Frameworks, ideally using Swift + integrating this with Today Extensions, that might be helpful, too.

like image 396
Bernd Avatar asked Oct 21 '22 01:10

Bernd


1 Answers

It seems like your import is not failing which means the framework is actually set up correctly...try making the function public.

public func tester() { print("tester()" }
like image 195
Pavel Dusatko Avatar answered Oct 22 '22 17:10

Pavel Dusatko