I’m trying out Swift playgrounds and I cannot find a way to change value of a struct. Below I want to change properties of Shadow from default values.
I’ve tried the initialiser and dot syntax but I get ‘field is inaccessible due to internal protection level.
let circle = Circle()
circle.draggable = true
//var shadow = Shadow(color: #colorLiteral(red: 0.9529411764705882, green: 0.6862745098039216, blue: 0.13333333333333333, alpha: 1.0), offset: Point(3,-3), blurRadius: 5, opacity: 1)
var shadow = Shadow()
shadow.color = .red
circle.dropShadow = shadow
You’re apparently using the “Shapes” playground.
So, view the source by clicking on “...” » “Advanced” » “View Auxiliary Source Files” » “Contents” » “Modules” » “Book.playgroundmodule” » “Sources” » “PlaygroundAPI”.
If you look at the
Shadowstruct, none of those properties are declared aspublic. That means that you don’t have access to them outside of that module.In contrast, if you look at the
Circledeclaration in contrast,radiusis public. And if you look atAbstractDrawable,dropShadowispublic, too.In the absence of an explicit access qualifier (e.g.,
public), a property gets theinternalaccess qualifier, only accessible within that module. (See The Swift Programming Language: Access Control.) And your code in that playground is not within the same module as whereShadowwas defined. Thus you don’t have access to it.So, bottom line, your warning is just telling you that you cannot access this internal property of the
Shadowstruct.This begs the question as to why they declared
Shadowsuch that you can’t customize the nature of the shadow. I suspect it is just an oversight on their part. For example, I opened up this playground workbook in Xcode and replaced theinitmethod forShadowwith the following:Then I could reopen this playground on my iPad and do things like:
And that yielded: