How do you log the data flowing into a SwiftUI view? - swiftui

Say I'm writing a new View that accepts a couple of pieces of data as arguments with which it builds its contents, what's the best way of getting a log of what data is flowing into the View?
When developing in JS, I can just write console.log(arguments), is there an equivalent in SwiftUI, and if so, where do I place the log call in my View so it won't throw an error?

James's answer got me partway there - print() is indeed the equivalent of console.log(). The other bit of knowledge I needed was to right-click the play button in the preview window of XCode and turn on 'Debug Preview'.

Related

How do I make my SwiftUI app open from a string?

It's possible to use "openURL(...)" on a View so that the system opens my SwiftUI app with a URL passed in for processing. That happens when, for example, I drag a suitable object and drop it on my app icon or open app. I want to do the same thing with my object that's represented as a String (JSON in this case). What do I call to do this, i.e., is there something like "openString(...)"?
There are a number of view modifiers like "onCommand", "onPasteCommand", etc. that sort of look like they might work but I'm missing some an overview of what the right options are to make my app respond properly to events that communicate data. Also, I'm looking for the preferred way to do this for iOS 14.
What did work for me was to use ".onOpenURL" and read the data from the URL there. To export data, create a UIActivityItemProvider that writes the data to a file in the app's tmp directory and returns its URL. These two actions can be used with the UIActivityViewController to share.

What is the meaning of Single Source of Truth (SSOT) in the context of SwiftUI?

I found this term in the What's New section of Xcode 11. Exactly what is the meaning of this here in the context of SwiftUI?
SwiftUI includes:
Design tools read and write the same code you edit by hand for a single source of truth
With SwiftUI, you can either write the code programatically or use the design tool to edit the UI, which will also result in the SwiftUI code being modified. Essentially, you only have the source code, there's no separate design file (i.e. nib or Storyboard), which means that there is no way your UI design and the code handling the UI can ever get out of sync (which was the case previously with nib files or storyboards).
SwiftUI offers a declarative approach to user interface design. As you compose a hierarchy of views, you also indicate data dependencies for the views. When the data changes, either due to an external event or because of an action taken by the user, SwiftUI automatically updates the affected parts of the interface.

How do you display rapidly updating data to the user in a win32 GUI app?

So im building a basic win32 GUI app and I have a vector of data that gets constantly updated through an external source via a port. Im interested in displaying that list of data to the user but im not sure the best approach to go about it without causing update flickering.
I originally had an edit box in which I build a string with the information and update the window. But it has proved troublesome as the amount of data grows since I cant scroll down to look at additional data. Any ideas?
My idea is no point of updating the visual control as the same speed you receive the data. Because even-though you update at the same speed the users cannot see that change at the speed of data receiving. Human eye does not see a change happening in speed as 1/8th of a second. So better to update the visual control in a controlled manner. Maybe using a timer.
Appending to the text of an edit control for each subsequent data point will lead to flickering as the whole control re-renders as the text has changed.
I'd advise one of the following options:
1) use a ListBox or ListView control; when you add another row item, it only re-draws the new/changed/scrolled item. https://learn.microsoft.com/en-us/windows/desktop/controls/create-a-simple-list-box and https://learn.microsoft.com/en-us/windows/desktop/controls/list-view-controls-overview
2) If you only want an always-scrolling list of data, consider just having a command-line application that writes to the standard output and saves you a lot of trouble - cout or printf your data.
You can also use EM_SETSEL and EM_SCROLLCARET to automatically scroll, but also check the position of the scroll bar before doing that. If not at the bottom, it means that the user wanted to pause, so you can scroll.
Also, you can have the scroll lock key checked in order whether to scroll or not, after all that is what it's name is supposed to do.

How to call print function if I changed the original view class?

I'm an MFC user.
In my code, there are two Views with split bar which are filled with buttons on the left and signals on the right side.
And, I tried to call the print functions which include print preview, OnPreparePrinting(),OnPaint() what so ever, through a button which is made by me and called PrintScreen on the menu, but it didn't work.
How can I connect from the menu button with the print functions?
And how can I project the both images from the two views on one page?
P.S. I've googled a lot, but I couldn't find completely the same as my situation. If someone knows this solution or information, please link or leave any solutions.
The MFC only supports printing for one view only, as long as you don't write your own print routines.
When you have two views divided by a splitter, one should be the active one. (Usually the view with the focus). In this case all standard commands like printing route to the one view that is active.
When you want that both views including the splitter to be printed, you have to write your own code. A simple solution would be calling the print functions for both views one after another.

Webview Swipe issue - Appcelerator Titanium

Right now I am using one webview to show data from my aplicationDatadirectory, here everything is working fine, I get content when user click next back respectively. Now what I am doing is in onload of webview I register "touchevent" and "touchmove" in webview's html like this :-
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
on the basis of this I find swipe event. I get correct html in webview(I can see images). But I am unable to get touchstart and move call. I dont know what is the problem here. I set data in webview using url here.
Now when I set data in webview using html(I used data of my html file(given below) in one var) now I am unable to see images it just shows me one black border(empty) but here my touchstart and touchmove events are firing also my swipe is also working as expected. I am checking this functionality in iPhone.
Can any one find the issue what is going wrong here? Thanks.
I think that this depends on the time when you apply
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchstart", function mytouch(){Ti.App.fireEvent("touch", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
$.webview.evalJS('document.getElementsByTagName("body")[0].addEventListener("touchmove", function mymove(){Ti.App.fireEvent("move", {X:event.touches[0].pageX,Y:event.touches[0].pageY,length:event.touches.length});}, false);');
If you use the html property data is loaded immediately and you can use the code exactly after setting html content. If you use the url (even if it is located locally, which might be difficult for android) then you need to wait a short time until the page is loaded. There is also an event listener for that (web view-event load) but i can't say if that works for local resources but i don't think so.
In this case you should apply your javascript snippet into your html resources (if they are locally) instead of manually adding it using evalJS.
Please note that there is an issue on android that you can't use local images (resources folder) in your webview when you provide the content via html property.
I made it swipe working in iOS(in android it was working).
I did not expect this thing to be a reason but I do not know logic behind it. I was accessing .xhtml files from application data directory and it was working without any issue in android but in iOS it was not.
I just change(rename in my code) .xhtml file to .html and now it is working. :)
Hope this can help someone who is looking for the same.(or just for his interest)
Thanks.