Passing a class instance into a PreviewProvider in SwiftUI? - view

so in my ContentView, I'm creating a view with:
ViewName(variable: ObservedObjectInstance)
where variable is the name of an initialization parameter required for the view; it takes in something of the same type as the ObservedObjectInstance. The ObservedObjectInstance is an #ObservedObject variable that was declared as a struct-level variable. In the ViewName class, I'd like to be able to access ObservedObjectInstance but I'm not sure how. I tried just declaring the following as a struct-level variable:
var variable: ObservedObjectClassType
and then in the PreviewProvider, I tried doing the following:
ViewName(variable: variable)
but it didn't work. I'm pretty sure the declaration of 'variable' in the ViewName class and the PreviewProvider is what's wrong, but I'm not sure how to fix it. Any help would be greatly appreciated.

In PreviewProvider use the following
ViewName(variable: ObservedObjectClassType())

Related

Send T type to method with an object Instance

I'm sorry if I can't explain my question but it's hard for me.
I'm trying to send an T class to my method, but I don't have direct access to my object, so, I thought use the name for create an instance with reflections, but I don't know how to send the class T to my method.
This is th definition of my method
void RedirectToActivity<T>(bool closePrevious);
And I have this code for call it
var activity = Activator.CreateInstance("myassembly", "MainActivity");
RedirectToActivity<????>(true);
With the first line I create an Instance of my class MainActivity.
In second line I need to send MainActivity class, and receive it like a T object in RedirectToActivity, but I don't know how to achieve this.
I need some like that...
RedirectToActivity<MainActivity>(true);
But I don't have direct access to MainActivity class.
I've tried this
RedirectToActivity<activity.GetType()>(true);
RedirectToActivity<typeof(activity)>(true);
But not works.
Can you just add a generic parameter argument to your RedirectToActivity method?
void RedirectToActivity<T>(T activity, bool closePrevious)
{
// Do Stuff here
}
And then pass your activity instance in:
var activity = Activator.CreateInstance<MainActivity>();
RedirectToActivity(activity, true);

presentViewController does not exist

I am building a plugin in NativeScript.
When I try to access "presentViewController" method on rootViewController, I get the error "property presentViewContrller does not exist".
const rvc = UIApplication.sharedApplication.keyWindow.rootViewContrller;
rvc.presentViewContrller(myViewController, true, completion() {});
It suggests to use presentViewContrllerAnimatedCompletion which does not accept my view controller.
Could you please assist what part of my code (or maybe setup!) is wrong?
The right method name is presentViewControllerAnimatedCompletion only.
You should combine the parameter names with method name while marshalling Objective C to JS/TS.
presentViewController:animated:completion

How to Use Internalization i18n in a Controller in SAPUI5?

Could anyone please explain how it's possible to use a i18n text in a setValueStateText method in a controller?
oTP.setValueStateText("{i18n>co_Maximal_60_h}");
The error msg in the dialog shows only "{i18n>co_Maximal_60_h}" and not the real text.
the resource bundle is in the following way accessible in a controller:
...
var oResourceBundle = this.getView().getModel("i18n").getResourceBundle();
oTP.setValueStateText(oResourceBundle.getText("co_Maximal_60_h"));
...
You cannot set the binding string via setter method.
Here you have 2 options:
set the binding right in the view (use the same string but in XML)
utilize the ResourceBundle:
var oResourceBundle = this.getOwnerComponent().getModel("i18n").getResourceBundle();
var sTxt = oResourceBundle.getText("co_Maximal_60_h");
oTP.setValueStateText(sTxt);
I'd recommend to add a reusable method to your BaseController with a name "i18n", so whenever you need it, call 'this.i18n("i18n_key")'.

Yii2 virtual attribute getter had to change to function call

I'm new to OOP and Yii2. I have a function in Model:
public function getDatRev() {
if ($this->rev) {
return $this->rev;
} else {
return $this->datum;
}
}
in the View until now I have used it like this:
$model->datRev;
and it would return the correct value. Now I don't know what has changed, maybe I was also updated the framework, but the old construct doesn't work anymore, and in order to make it work I have to change it to:
$model->getDatRev();
Can you please explain to me why that is?
When you try get property the Yii2 calls magic method __get (). Return value is depend from implementation of this method in parent class. Yii2 can check if this property exist in some container, or if exist getter of this property.
In your case seems like you don't call parent's method __get(). This may have happened because you override __get() method or initialized this property.
Your class needs to extend yii\base\Object (directly or not) in order to use short property syntax ($model->abc instead of $model->getAbc()). Magic method __get() #Timur mentioned is defined there and further extended in yii\base\Component class.

MVC3 URL Parameters

I have some parameters in URL, which I would like to be present in the URL for all pages in my MVC3 app. For example:
mycompany.com/home?param=1
mycompany.com/cart?param=1
mycompany.com/logout?param=1
Whether the user is navigating to a new page or submitting a form, how can I have my parameter
be present in all my pages? Right now the only way I can think off is somehow reconstruct the URL for every new view I need to render. Is there built in functionality in MVC to do this?
Thanks
That sounds like something you should store in Session instead of updating all of your links to add the same parameter.
You could use a Session variable as the other poster suggested, or you could use a base view model which holds this static param value.
So your base view would be something like this:
public class BaseViewModel
{
public static int ParamValue = 1;
}
then in each view model you use for each view, you'd have something like this:
public class PageViewModel : BaseViewModel
{
// properties
}
This way, in each view, you can just reference #Model.ParamValue whenever you need to access it:
#Model Namespace.PageViewModel
My param value is <b>#Model.ParamValue</b>

Resources