I use Xcode 15.3.
Short story:
Calling 'Call_MBLog' from within a framework doesn't work (see below).
Calling 'Call_MBLog' from the main-app works. E.g.:
//
// ContentView.swift
//
import Check_iOSDebugFrameWork2407Pkg
import SwiftUI
struct ContentView: View {
var body: some View {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
let InputNumer: Int32 = 42
let ResultNumber = Call_MBLog (InputNumer)
Text ("ResultNumber: \(ResultNumber)")
}
.padding()
}
}
//
// SwiftFiles/CheckGlobalFunctions.swift
//
import Foundation
public func MBLog(_ aString: String) {
print("MBLog (CheckGlobalFunctions.swift): aString: [\(aString)]")
let InputNumer: Int32 = 42
// var ResultNumber = Call_MBLog (InputNumer) // Cannot find 'Call_MBLog' in scope
}
My Framework-Structure is like this:
|_Check_iOSDebugFrameWork2407Pkg.h
#--------------------------------------------------
//
// Check_iOSDebugFrameWork2407Pkg.h
//
#import <Foundation/Foundation.h>
//! Project version number for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT double Check_iOSDebugFrameWork2407PkgVersionNumber;
//! Project version string for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT const unsigned char Check_iOSDebugFrameWork2407PkgVersionString[];
// Import all the public headers of your framework
#import <Check_iOSDebugFrameWork2407Pkg/RunTimeInfoFw.h>
// Swift module will be automatically imported
#--------------------------------------------------
|_Package.swift
#--------------------------------------------------
// swift-tools-version:5.3
import PackageDescription
let package = Package(
name: "Check_iOSDebugFrameWork2407Pkg",
platforms: [.iOS(.v12)],
products: [
.library(
name: "Check_iOSDebugFrameWork2407Pkg",
targets: ["Check_iOSDebugFrameWork2407Pkg"]),
],
dependencies: [],
targets: [
.target(
name: "Check_iOSDebugFrameWork2407Pkg",
dependencies: [
"Check_iOSDebugFrameWork2407ObjC",
"Check_iOSDebugFrameWork2407Swift"
],
path: "Sources/Check_iOSDebugFrameWork2407Pkg",
sources: ["Dummy.swift"] // We'll create this file
),
.target(
name: "Check_iOSDebugFrameWork2407ObjC",
path: "Sources/ObjCFiles"
),
.target(
name: "Check_iOSDebugFrameWork2407Swift",
path: "Sources/SwiftFiles"
),
// .testTarget(
// name: "Check_iOSDebugFrameWork2407PkgTests",
// dependencies: ["Check_iOSDebugFrameWork2407Pkg"]),
],
swiftLanguageVersions: [.v4_2]
)
#--------------------------------------------------
|_Sources
|||_Check_iOSDebugFrameWork2407Pkg
|||||_Check_iOSDebugFrameWork2407Pkg.h
#--------------------------------------------------
//
// Check_iOSDebugFrameWork2407Pkg.h
//
#import <Foundation/Foundation.h>
//! Project version number for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT double Check_iOSDebugFrameWork2407PkgVersionNumber;
//! Project version string for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT const unsigned char Check_iOSDebugFrameWork2407PkgVersionString[];
// Import all the public headers of your framework
#import <Check_iOSDebugFrameWork2407Pkg/RunTimeInfoFw.h>
// Swift module will be automatically imported
#--------------------------------------------------
|||||_Dummy.swift
#--------------------------------------------------
//
// Check_iOSDebugFrameWork2407Pkg/Dummy.swift
//
// This file is needed to satisfy SPM requirements
@_exported import Check_iOSDebugFrameWork2407ObjC
@_exported import Check_iOSDebugFrameWork2407Swift
#--------------------------------------------------
|||_ObjCFiles
|||||_CheckMBLog.m
#--------------------------------------------------
//
// ObjCFiles/CheckMBLog.m
//
#import <Foundation/Foundation.h>
#import "CheckMBLog.h"
int Call_MBLog (int Number) {
return Number * 2;
}
#--------------------------------------------------
|||||_include
|||||||_CheckMBLog.h
#--------------------------------------------------
//
// Sources/ObjCFiles/include/CheckMBLog.h
//
#ifndef CheckMBLog_h
#define CheckMBLog_h
// Fix "Unknown type name 'bool'"
#import <Foundation/Foundation.h>
int Call_MBLog (int Number);
//NS_ASSUME_NONNULL_BEGIN
//
//FOUNDATION_EXPORT int32_t Call_MBLog(int32_t inputNumber);
//
//NS_ASSUME_NONNULL_END
#endif /* CheckMBLog_h */
#--------------------------------------------------
|||||||_Check_iOSDebugFrameWork2407Pkg.h
#--------------------------------------------------
//
// Sources/ObjCFiles/include/Check_iOSDebugFrameWork2407Pkg.h
//
#import <Foundation/Foundation.h>
//! Project version number for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT double Check_iOSDebugFrameWork2407PkgVersionNumber;
//! Project version string for Check_iOSDebugFrameWork2407Pkg.
FOUNDATION_EXPORT const unsigned char Check_iOSDebugFrameWork2407PkgVersionString[];
// Import all public Objective-C headers
#import "CheckMBLog.h"
//#import <Check_iOSDebugFrameWork2407Pkg/CheckMBLog.h>
#--------------------------------------------------
|||_SwiftFiles
|||||_CheckGlobalFunctions.swift
#--------------------------------------------------
//
// SwiftFiles/CheckGlobalFunctions.swift
//
import Foundation
public func MBLog(_ aString: String) {
print("MBLog (CheckGlobalFunctions.swift): aString: [\(aString)]")
let InputNumer: Int32 = 42
// var ResultNumber = Call_MBLog (InputNumer) // Cannot find 'Call_MBLog' in scope
}
public func getCheckResult() -> String {
return "Any Result 1"
}
#--------------------------------------------------
|||||_Check_iOSDebugFrameWork2407Pkg-Bridging-Header.h
#--------------------------------------------------
//
// SwiftFiles/Check_iOSDebugFrameWork2407Pkg-Bridging-Header.h
//
#import "CheckMBLog.h"
#--------------------------------------------------
Thanks for any hint.
Markus