In Xamarin, I have access to Foundation.NSUrl. This is fine, but I have a native (Swift) library that I am binding to, that exposes a property of struct type Foundation.URL?.
I can't see this type defined in Xamarin and an attempt to use NSUrl instead generates a build error. Does the URL type exist somewhere in Xamarin or is there an equivalent type I can use in a binding, or is there a definition I can use in StructsAndEnums.cs?
Related
In prism we can have ViewModelLocator resolve the VM when we navigate to a View by setting the attached property prism:ViewModelLocator.AutowireViewModel="True"
However, in the PRISM samples on Github, the container is initialized using the extension method (RegisterForNavigation) which seems to do the same thing.... ,
containerRegistry.RegisterForNavigation<MainPage, MainPageViewModel>();
I am wondering if the RegisterForNavigation has made the AutowireViewModel attached property approach obsolete?
I am wondering if the RegisterForNavigation has made the AutowireViewModel attached property approach obsolete?
No, this kind of registration just - additionally - defines the view model to be used for the registered view directly (instead of relying on the convention configured in the view model locator).
Setting ViewModelLocator.AutowireViewModel is still required to actually create the view model (whether it's type is defined manually or derived from the view's type by a convention).
I have a Xamarin Forms Project That targets iOS. I am trying to write Xamarin.UITests that depend on existence of certain files inside the /Documents folder on the device
In trying to read/write the files to the correct Folder here is what I found.
string documentBasePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
Results From actual app :
"/Users/markwardell/Library/Developer/CoreSimulator/Devices/147FD387-FCAD-4E93-BFC7-4BC1572FF7D4/data/Containers/Data/Application/13E0B91B-8C70-4139-B570-7431DDF5B5CA/Documents"
Results From Xamarin.UITest :
"/Users/markwardell/”
Clearly I need a way of getting same result as 1..
How can I get the folder results same as app in the UITest?
The UITest project does not have access to the Xamarin.iOS SDK which is the SDK that is giving you the path from the actual app when deployed to a device or simulator. IOW, the System namespace in Xamarin.iOS's version of .NET/Mono implements some things differently depending on the platform, as is necessary in this case since the documents path is different on iOS than it is on Android, than it is on Windows, etc. So this is why the paths are different.
That said, you can get around this by using a backdoor method. See:
https://learn.microsoft.com/en-us/appcenter/test-cloud/uitest/working-with-backdoors
This allows you to call a method implemented in the iOS project itself, thereby using Xamarin.iOS SDK in that method.
You implement the backdoor method in your AppDelegate class in your iOS app project like so:
[Export("getMyDocumentsPath:")] // notice the colon at the end of the method name
public NSString GetMyDocumentsPath(NSString value)
{
// In through the backdoor - do some work.
return new NSString(System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments));
}
Then call it from your UI Test project:
var path = app.Invoke("getMyDocumentsPath:", "").ToString();
Worth noting from the linked doc (in case it ever goes away):
On iOS, IApp.Invoke can call a C# method on the project's AppDelegate according to the following rules:
The method must be public.
The method must be adorned with the ExportAttribute and the name of the exposed C# method identified. The exposed name must append a : (colon) to the name. IApp.Invoke must use the iOS form of the method name.
The method must take a parameter of NSString.
The method must return NSString or void.
I just upgraded Xcode to 8.0 (8A218a) and am converting my project in Swift 2.3 to Swift 3.0. The only issue left now is this error:
"Exception while running ibtool: Cannot find value transformer with
name UTIToIconTransformer"
The UTIToIconTransformer is defined something like:
#objc(UTIToIconTransformer) class UTIToIconTransformer : ValueTransformer {
// ...
}
The code worked fine when it was in Swift 2.3. The binding using this value transformer is set like this:
If I remove this binding, the app runs, and the row titles are shown correctly.
I have tried calling NSValueTransformer.setValueTransformer() in the app delegate's +initialize(), in applicationDidFinishLaunching and in the value transformer's +initialize(), as suggested here, here at StackOverflow and here at NShipster (Though I don't think the statement of "Typically, the singleton instance would be registered in the +initialize method of the value transformer subclass, so it could be used without further setup." complies with the Apple's doc.), all without success.
In the Apple's doc, it says
Value transformers are typically registered by an application’s delegate
class, in response to receiving a initialize: class message. This allows
registration to occur early in the application startup process, providing
access to the value transformers as nib files load.
Availability in Interface Builder
Your NSValueTransformer subclasses are not automatically listed in the
Interface Builder bindings inspector. When inspecting a binding you can enter
the name that the value transformer is registered with, but the functionality
will not be present in Interface Builder’s test mode. When your application
is compiled and run the transformer will be used.
But registering in the AppDelegate's override class func initialize() didn't help. In Xcode 7 and Swift 2.3, it even worked without the registration.
Finally I solved the problem by removing the NSOutlineView from the storyboard and setting up a new one.
I have another project which also has an outlineview binded with an NSTreeController, and that project has no problem after the Xcode 8.0 upgrade. Then I tried creating a new ValueTransformer with a new name, with no luck.
I guess there may be something wrong with the storyboard, so I tried recreating the outline view. Then Xcode doesn't complain that it can't find the transformers!
I made an implementation change to one of the methods in the native framework. Would I need to recreate bindings, in this case ?
Short answer: likely not
Long answer: Depends, you would need to rebuild the binding only if this change you mention is in the public API signature of the method / property. This is because the bindings matches 1 : 1 (most of the time) what the native API surfaces so for example if your method used to return a NSString and now it returns another class or the selector name changes or the type of any of the parameters changes then yes.
You also would need to rebuild the binding if the binding dll bundles the native library you are using. If you are manually linking the native library (using the additional touch args in your app project) you should be fine.
I have been using bindings without having ever heard of exposeBinding.
Is it only intended to plug-ins ?
What does exposeBinding do ?
Expose bindings are nothing special, it is just normal binding what you see in the Xcode. But why its named is expose binding becuase when you do any binding in the interface builder. It causes second binding automatically in the interface builder which is called expose binding.
For your understanding i have attached the screen shot in which inside binding inspector i have just bind file owner to the hidden in Availablity section and then you can see below automatically it created hidden2 inside Availablity section below. This new binding hidden2 is called exposed binding. And also the used of these binding values are then used together in returning the final value of the binding. Please follow the attached screen shot:-
From the doc.
exposeBinding:
Exposes the specified binding, advertising its availability.