I want to change a variable value from another Yocto recipe that is not soft assigned '?='
For example
meta-layerA has a given recipe that sets variable FOO="valueA"
And I want to change FOO either in meta-layerB (custom recipe) or in local.conf
If meta-layerA has FOO?="valueA" I'm able to change FOO from local.conf.
Is there a way to change FOO even if '=' is used as assignment?
If you have a distro configuration you could use overrides, something like:
FOO_<distro_override> = "valueB"
to reset the variable when your distro is configured. In a .bbappend, a second assignment parsed after the first would override the original value so:
FOO = "value2"
would work too as it would reset the original value due to be parsed later.
Create a bbappend in meta-layerB for the recipe which is in meta-layerA and just put FOO = "valueb" in it.
Related
Here is a little background:
I am trying to test some functions. I CANNOT change anything in the function or any class variables.
So I am calling this function in my unit test, the problem is that, there is a boolean flag, this method simply will just not execute if this flag is not set to true. But this flag has a private setter, so I can directly set it.
I asked around someone told me to use a extension IN the test file to set the variable, but I've tried I don't think I can set it if the extension is not in the same file as the function. Am I doing something wrong? Or is there any other way to test it?
What they were referring to is to place an extension in the file with the class-under-test. So if you have something like:
class ToBeTested {
private(set) var bool: Bool
}
You can add an internal setter:
extension ToBeTested {
func setBoolTrue() { bool = true }
}
But this has to be in the same file with ToBeTested. If you cannot modify that file, this is not a solvable problem. If it needs to be tested this way, then the class will need to be designed to permit that.
When a property is marked private(set), the compiler can assume that the value cannot be changed in any way outside this file. That allows it to apply optimizations that may not be valid if the property were changeable outside this file. The "setter method" may not even exist if the compiler determines that it doesn't need it. For example, it may completely inline that operation, or eliminate it entirely if it can prove the value is never changed.
I apologize for the rather basic question, there is a lot of documentation out there but this is not particularly clear to me.
Swift keeps giving me warnings that suggest changing variables to constants so my question is this: if I set a constant equal to a control property (a label text value for instance) and the value of that control property changes, will the value of the constant change? The definition of that "constant" will always be equal to the control property.
Example from my code:
let MELLandingPenalty: Int = Int(lblMELLandingDist.text!)!
Constants behave in two different ways:
If the assigned object is value type then the value is a copy of the right side and will never change.
If the assigned object is reference type then the reference will never change but its variable properties are mutable.
In your example value type MELLandingPenalty will never change – by the way variable names are supposed to start with a lowercase letter and don't annotate types the compiler can infer.
Trust the compiler and resolve the warnings by changing var to let.
I am assigning the value of a custom class to another variable. Updating the value of the new variable is affecting the value of the original variable. However, I need to stop the reference variable from updating the original variable.
Here's a basic representation of what's happening:
var originalVariable = CustomClass()
originalVariable.myProperty = originalValue
var referenceVariable = originalVariable
referenceVariable.myProperty = updatedValue
print("\(originalVariable.myProperty)") //this prints the ->updatedValue<- and not the ->originalValue<-
I've tried wrapping the referenceVariable in a struct to make it a value type but it hasn't solved the problem.
I've found information regarding value and reference types but I haven't been able to find a solution.
My question in a nutshell: How do I stop an update to a reference variable from updating the original variable that it got its value assigned from?
Thanks in advance.
The whole point of reference semantics (as used by classes) is that all variables point to the same (i.e., they reference the same) object in memory. If you don't want that behaviour, you should use value types (Struct, Enum, Array...) or create copies of your object.
If CustomClass implements the NSCopying protocol you can do:
var referenceVariable = originalVariable.copy()
If it doesn't, you'll have to find some other way to copy it or implement the protocol yourself.
Wrapping the class in a struct will just make two different structs each containing a different reference to the same object.
As I started developing with Swift and searching through different tutorials and documentations about the language, I'm not sure about one thing.
You can declare an object / value with a specific data type like this:
var aString:String = "Test"
var anObject:SKScene = ASceneClass()
Or you can just do it like this:
var aString = "Test"
var anObject = ASceneClass()
The result will be exactly the same (ASceneClass inherits from SKScene of course)
As everyone is doing it different I wonder if there's a logical reason behind it or you do it for readability ?
Declaring type right after variable name is called Type Annotation
When you don't do that, you have to provide initial value
var aString = "Test"
Often value is not known at that moment, or you are not even sure if it's going to be not nil value, then you can declare it as optional
var aString:String?
If you would like to declare variable without any initiaization but you are sure it's not going to evaluate to nil, you force unwrap it
var aString:String!
This is the definition. In practice, it's always better to use type annotations even when you initialize variable with value, because later in your program you will notice anytime you mess something with the type of the variable.
Also, When you declare an array or dictionary, usually nested ones, Xcode might expect them to have type annotations since it might have some issues with writing values when the type is not known in advance.
To recap
You will want to use type annotations whenever you can, which means whenever you are sure about the variable's type in advance
Recommended/Documented way to declare a variable in swift is as follow:
var <variable name>: <type> = <initial value/expression>
Note: Given form declares a stored variable or stored variable property. Its used when you are clear about type annotation of it.
Though its valid to declare variable without its Type.
var variableName = <initial value>
Note: When you don't know type annotation its mandatory to assign 'Initial value' to that variable.
Refer Swift Documentation on Declaration for more details.
I am having a problem with VBA Excel 2010. I've made a custom Class called 'Enclosure', created an instance of this and added it to a dictonary.
I can then loop through the keys to ensure it has been added.
I'm having trouble then extracting my enclosure class. Here's my code for the extraction sub:
Sub AddEnclosureItem(sItemToAdd As String, ByRef rdEnclosures As Scripting.Dictionary, dDebug As Boolean)
Dim TempEnclosure As Enclosure ' hold enclosure we pull
TempEnclosure = rdEnclosures(1)
End Sub
When I try to compile I get the 'Object Variable or With block variable not set'
Any idea's on how to proceed? I've read somewhere you can declare a dictionary stating the items are of a certain object but I can't get it to work in 2010. That's all I can guess at. OR a way to cast the enclosure item as it comes out.
When you assign an object to a variable, you have to use the Set keyword. The opposite of Set is Let, which is used to assign a value (not an object) to a variable. The Let keyword is optional and almost nobody uses it anymore.
The reason there's a Set and Let is because most objects have a default property - meaning that if you reference an option without a property, it will return the value stored in the default property. The Value property is a common default property. This
x = Range("A1")
is the same as this
x = Range("A1").Value
is the same as this
Let x = Range("A1").Value
Any is acceptable (although I prefer the second one). That's great if x is a Double or String, but if x is a Range object variable, you need use Set
Set x = Range("A1")
If you omit the Set keyword, VBA assumes you wanted Let and tries to assign the (default) Value property to x. That gives the 'Object variable or with block not set' error because it's trying to assign a Double or String to a Range object variable.
Your custom class module probably doesn't have a default value, so none of this should matter. But it does. Even if there is no default value, you have to use Set to reference the object.