Property cannot be declared public because its type uses an internal type
You have to declare the access level of the Content
class public as well.
public class Content {
// some code
}
As stated in the documentation:
A public variable cannot be defined as having an internal or private
type, because the type might not be available everywhere that the
public variable is used.
Classes are declared as internal
by default, so you have to add the public
keyword to make them public.
A similar rule exists for functions as well.
A function cannot have a higher access level than its parameter types
and return type, because the function could be used in situations
where its constituent types are not available to the surrounding code.
Property cannot be declared open because its type uses an internal type (Typealias)
In this specific case (when used within a framework target), making the typealias
public will not solve the issue. You need to use the platform condition check also when declaring the image property, as follows:
#if os(iOS)
import UIKit
typealias Image = UIImage
#elseif os(macOS)
import Cocoa
typealias Image = NSImage
#endif
public final class MyClass {
#if os(iOS)
public var image: UIImage
#elseif os(macOS)
public var image: NSImage
#endif
init?(imageURL: URL) {
guard let image = Image(contentsOf: imageFileURL) else {
return nil
}
self.image = image
}
}
The same applies for any public methods that use this type, whether it is a parameter or the return type of a function.
Offtopic: Make sure to initialize this class on a background queue/thread to avoid blocking the main thread and freezing the UI while the image is being downloaded.
Related Topics
How to Write an 'If Case' Statement as an Expression
What's the Difference Between a Required Initializer and a Designated Initializer
What's the Swift Equivalent of Objective-C's "#Ifdef _Iphone_11_0"
Uitableviewcell Height Auto Layout Not Working on iOS 10
Need Self to Set All Constants of a Swift Class in Init
How to Fix ' *Pod* Does Not Support Provisioning Profiles' in Azure Devops Build Agent
Making Cocoa Application Scriptable Swift
What Is the Swift 3 Equivalent of Nsurl.Urlbyappendingpathcomponent()
Swift Arc4Random_Uniform(Max) in Linux
How to Simulate Traits/Mixins in Swift
Subclassing VS Extension in Swift
Swift 4.2+ Seeding a Random Number Generator
Swiftui: Dismiss View Within MACos Navigationview
Convincing Swift That a Function Will Never Return, Due to a Thrown Exception