So just curious about one thing. When creating a custom shape and conforming to Shape I am required to implement
func path(in rect: CGRect) -> Path
Cool.
Now when I look up Path I see this:
And that it conforms to:
Now when I look up the first requirement: Animatable, I see that it has some required implementation:
Then why am I not required to add this data to every custom shape I create?
I have used animatableData before, but only optionally. If I understand the docs right then this isn't optional but required.
Any clarification is appreciated!
Edit: Edited title to better reflect subject matter
Related
I have a page that inserts some predefined components in the placeholders, when user creat it (like gallery and header for example).
I also want web masters to give a freedom to insert other possible components to the placeholders around the predefined components, but I want to prohibit somehow to edit/delete the predefined components (gallery and header) from the page.
However, a content editor can add another gallery component (technically possible) to the same page, and delete it if he wants to. But predefined components should just not be touched (at least be removed from the placeholders. In other words - I don't want to have a delete button in the Experience editor next to the predefined components).
There is a way to fully prohibit editing the component rendering, but I still want web masters to insert components by themselves if they want. I just want them to do not modify the components that come when page is created.
As I understand this can be done somethere on the RenderingReference level, but I cannot figure it out how. Could you give a tip please?
Okay, I have found a way to do this.
Just in case if somebody will need it.
First, we need to create a Processor to catche page renderings in the Experience Editor.
public class CheckLockedComponentsHandler : GetClientActionsChromeData
{
public new void Process(GetChromeDataArgs args)
{
if (args.ChromeType == "rendering")
{
if (args.CustomData["renderingReference"] is RenderingReference rf && !string.IsNullOrEmpty(rf.Settings.Parameters))
{
var rmParams = WebUtil.ParseUrlParameters(rf.Settings.Parameters);
args.ChromeData.Custom["editable"] = string.IsNullOrEmpty(rmParams["editable"]) ? "true" : rmParams["editable"];
}
}
}
}
When, we add a property editable = false when creating a locked component.
And finally we need to register our processor in the configuration
<pipelines>
<getChromeData>
<processor type="CheckLockedComponentsHandler,MyLib" patch:after="*[last()]"/>
</processor>
<getChromeData>
</pipelines>
How can I create and import a move filter on construction heuristics?
Solution
optaplanner at configuration may show some errors when you try to add and on configuration. It is possible to need one more tag or something else, but for something was missing or was doing it totaly wrong.. I finaly managed to add my filter by creating customfilter class whis implements SelectionFilter and add to the annotation of the entity class. Find in the documentation the SelectionFilter class.##
<constructionHeuristic>
<constructionHeuristicType>FIRST_FIT_DECREASING</constructionHeuristicType>
<changeMoveSelector>
<filterClass>...</filterClass>
</changeMoveSelector>
</constructionHeuristic>
Following part 3 of Apple's tutorial on SwiftUI, Handling User Input, I get this error:
Unable to infer complex closure return type; add explicit type to disambiguate
I'm using the same code as the tutorial (even coping from the 'Complete' sample code doesn't resolve the error).
Does anyone have a cue what is going wrong here?
struct LandmarkRow: View {
var landmark: Landmark
var body: some View {
HStack {
landmark.image(forSize: 50)
Text(verbatim: landmark.name)
Spacer()
if landmark.isFavorite {
Image(systemName: "star.fill")
.imageScale(.medium)
}
}
}
}
Regardless of the cause of the issue, how could you indeed add an explicit type to disambiguate here? What would the return type in such a case be?
--
Update
Apparently you should not continue with your result of the 2nd tutorial with the 3rd. Some things changed in between of the tutorials that is not documented in the tutorial. I've added the project files to Github so you can check out the diff.
It's better to start the 3rd tutorial fresh with a fresh download of the Project files of the 3rd tutorial.
The issue is not with the closure, but with the isFavorite property on landmark.
It is not declared on the Landmark type, and the compiler instead of showing the undeclared property error, unable to resolve the stacks build closure return type, so it shows and error there.
Great job Apple tutorial writers and even better one Xcode11 compiler.
To fix:
Declare isFavorite variable on the Landmark type.
Make sure you update the landmarkData.json for every landmark record with the isFavorite = false entry, otherwise the app will crash at runtime.
Some background to this problem
Like #dirtydanee already answered there is a difference between those two tutorials. But the problem behind the problem is that while it looks like you're doing a configuration it's actually just functions nested in functions using generics and protocols to "magically" parse everything into a compiling function.
However conformance to these generics and protocols need to be pretty precise because if not the whole tree of functions cannot compile anymore. But it's hard to determine for the compiler what conformance actually failed. This is why you see an error at the top rather than at the point where it actually happens.
It's strongly advised to make sure your views are decomposed into natural and simple blocks so you're not pouring over hundreds of lines of View code to find that one bug.
Dave DeLong had a really great talk about how to compose Views from ViewControllers that still holds true until today: basically you never use View as a subview inside another View but you need to decompose your View of many, simple Views. Otherwise these errors'll drive you nuts.
For people getting this error on SwiftUI and looking for a way to debug their view stack
This error happens mainly when there is a compilation issue on one child View.
1 - Make sure your parent view can support multiple subviews (VStack, ZStack) and you have less than 10 subviews. Sometime you may want to add a Group wrapper.
2 - If this is not the problem, there is probably an issue with one subview. Try to isolate the one you suspect to have the issue. Usually I copy the subview into a property and a different error appears
var debug: some View {
MyViewWithError(property: self.property)
}
Most of the time you'll encounter this because you pass the property (self.property) instead of a binding (self.$property)
Hope this can help some people
I have run into this error when made a typo. Also this error appears when a code has syntax issues. Just check if your changes are correct
I encountered the problem in a subview where a #Binding prop was of a different type of the #Binding source.
In Swift 3, a lot of the methods got renamed. According to one of the sessions at WWDC, the prepositions in method names are moved to the parameter name:
UIView.animateWithDuration(1)
-> UIView.animate(withDuration: 1)
UIStoryboard.instantiateViewControllerWithIdentifier("some stuff")
-> UIStoryboard.instantiateViewController(withIdentifier: "some stuff")
So I thought viewWithTag(1) will be renamed to view(withTag: 1), but it isn't!
There is even mentioned in the API guidelines:
Especially when a parameter type is NSObject, Any, AnyObject, or a fundamental type such Int or String, type information and context at the point of use may not fully convey intent. In this example, the declaration may be clear, but the use site is vague.
func add(_ observer: NSObject, for keyPath: String)
grid.add(self, for: graphics) // vague
To restore clarity, precede each weakly typed parameter with a noun describing its role:
func addObserver(_ observer: NSObject, forKeyPath path: String)
grid.addObserver(self, forKeyPath: graphics) // clear
I also found that SKNode.addChild is not renamed as well!
Question:
Why are these methods not renamed? They forgot about them? Or are there exception cases to the API guidelines? If yes, what are them?
I am looking into the algorithm described in Swift Evolution 0005.
viewWithTag
The first step of name pruning is:
Prune the result type from the head of type-preserving transforms.
Specifically, when
the receiver type is the same as the result type
and the type name is matched at the head of the first selector piece
and the match is followed by a preposition
the view part is actually the first to be removed.
The forTag is removed too in step 3, therefore the result is an empty selector.
That collides with
Pruning Restrictions
...
Never make a selector piece entirely empty.
Therefore no pruning is performed.
addChild
addChild, addSubview, addGestureRecognizer follow all the same pattern, there is actually an example in the spec:
Never prune a suffix from the base name of a method that matches a property of the enclosing class:
This heuristic has the effect of preventing us from producing too-generic names for methods that conceptually modify a property of the class.
... If we were to drop GestureRecognizer, leaving just add, we end up with a method that conceptually modifies the gestureRecognizers property but uses an overly generic name to do so:
In general, they cannot forget about some methods because the renaming (importing) is automatical.
I'm trying to make my own full adder and some other devices as a sub-circuit in "Proteus" and use them several times in a bigger circuit.
The problem is when you copy a sub-circuit you need to rename all of its inner parts, otherwise, the parts with a same name in two sub-circuits would be considered as one, therefore you'd get some errors.
So I'd like to know if there is a way to define a full adder of my own and use it like "74LS183" which is a primitive device, and by primitive I mean it has been defined in the library.
From answer posted here
It's in the Proteus Help file:
SCHEMATIC CAPTURE HELP (F1) -> MULTI-SHEET DESIGNS -> Hierarchical Designs
See the section "Module Components":
Any ordinary component can be made into a module by setting the Attach Hierarchy Module checkbox on the Edit Component dialogue form.
The component's value is taken to be the name for the associated circuit,
and the component's reference serves as the instance name.
after this you can use your new implementation of that component with your new name. for making it available at library see "External Modules" section of proteus help.
The problem with copying is solved in "Proteus 8".not completely but sort of.
I mean you can copy a subcircuit without a need to change it's inner parts, but you must change the subcircuit name and I mean the bigger name above the subcircuit not the little one below it.
so there is no need to define a primitive.