Manually invoke RaisePropertyChanged - mvvm

Is it MVVM correct to manually invoke RaisePropertyChanged on some property, for example that has no setter?

Most definitely.
Here is an example: Assume a Person class has 3 properties: firstName, lastName and fullName. fullName is a read only property (only a getter). Then the setter of firstName will raise property changed for both the "firstName" property as well as the "fullName" property.

Then the value of the property is never changed? Why no setter?
Anyway you can do that yes.

Related

How do we create custom getters and setters, and what’s the advantage of doing so in Flutter?

What is the reason of using custom getters and setters in an application.
That's fairly very simple
First let me show you a sample of how getters and setters in Dart look like, which is essentially the language behind Flutter
class Foo {
// Creating a field/instance variable
String _fooName; //Keeping it private always
// Using the getter
String get foo_name {
//We can do something else here, like saving the variable somewhere and then returning it to the caller function
return _fooName;// private variable return for use in outside class
}
// Using the setter method
set foo_name (String name) {
// We can do something else, like update another variable based on fooName
this._fooName = name;//private variable being assigned new value
}
}
From the name, setters are involved in setting the values to an instance variable in an object oriented programming paradigm whereas getters are involved in getting the value of an instance variable
Now you would ask why not return the instance variable directly and why having such a roundabout approach to setting and getting the value
Well the answer is while getting as well as setting, we might want to do some other operation too other than just setting or getting the value and it's always better not to give admin access to the variables and that's why they are private so as to promote consistency within the objects accessing the field
It's a matter of preference, but you really shouldn't needlessly create one for a single field
https://dart.dev/guides/language/effective-dart/usage#dont-wrap-a-field-in-a-getter-and-setter-unnecessarily
One use case for creating a setter would be to perform some type of validation
For a getter, it'd be useful for a calculated field based on other properties, rather than a single property alone

Mdriven Designer class attribute Allow Null=False not working

I have a class named "Project" with attribute "Name" having type of String. I have changed it from Allow Null=True to False and then I have saved the model and restarted the WECPOF prototyper in xml mode. But it still allows me to create and save instances of Project without adding a name. What might I be doing wrong?
Try to keep your attributes "nullable", i.e. Allow null = True. Why? Because you usually end up wanting to see the difference between "nothing" and "empty".
As Hans suggested, add a contraint on the class with a expression like this "not self.Name.isNullOrEmpty".
I guess the string is not null but empty "". Strings are tricky that way - the only type that is presented the same as null and as its simplest possible value.
To signal to user that you do not allow a null or empty you can do a constraint on the class or add a validation expression in the ViewModel.

self.property or property in Swift

In a Swift method you can access a property using self.property or simply property.
Is there any difference? Is one of these preferred? Is there any style guide published by Apple which requires one or the other?
In practice, you don’t need to write self in your code very often. If
you don’t explicitly write self, Swift assumes that you are referring
to a property or method of the current instance whenever you use a
known property or method name within a method.
The main exception to this rule occurs when a parameter name for an
instance method has the same name as a property of that instance. In
this situation, the parameter name takes precedence, and it becomes
necessary to refer to the property in a more qualified way. You use
the self property to distinguish between the parameter name and the
property name.
Reference: The Swift Programming Guide from Apple.

How does Swift implement ARC in property attributes?

How does Swift implement ARC in property attributes? For example, how do I make my String variable use copy instead of strong in Swift?
You can use the #NSCopying attribute when you want the copy behaviour from Objective-C.
From the Swift Book:
Apply this attribute to a stored variable property of a class. This
attribute causes the property’s setter to be synthesized with a copy
of the property’s value—returned by the copyWithZone method—instead of
the value of the property itself. The type of the property must
conform to the NSCopying protocol.
The NSCopying attribute behaves in a way similar to the Objective-C
copy property attribute.
However, in the specific case of String properties, it's not necessary to do so.
Strings are a value type in Swift. As such, when an existing String is assigned to a new variable, the variable actually stores a copy of the String, rather than a reference to the existing one.
Swift’s String type is a value type. If you create a new String value,
that String value is copied when it is passed to a function or method,
or when it is assigned to a constant or variable. In each case, a new
copy of the existing String value is created, and the new copy is
passed or assigned, not the original version.
So, the #NSCopying attribute is to be used when you have properties of a reference type that you want to set using the copy behaviour.

What exactly is a no-parameter method name?

From the Core Data docs:
A property name cannot be the same as
any no-parameter method name of
NSObject or NSManagedObject—for
example, you cannot give a property
the name “description”
Ok, so -description is blocked for property names. I guess it's because of KVC. But what exactly does "no-parameter" mean? Is that any method which does not take a parameter?
So in other words:
Any property of NSObject or NSManagedObject
ANY method name of NSObject or NSManagedObject, which does not take a parameter
Did I get that right?
Any unary message is a no parameter method name. I.e., -copy, -retain, -release, are all unary messages when sent, and no parameter methods when you define them. An example of a keyword message (or a method with parameters) is: +stringWithString:, etc.