i have this code here. Normally it is just a Text(question), but then the contents of my variable question will not be translated. There must be a better way...but i don't know how.
Of course "question" will have diffent contents...
if question == "text to be translated" {
Text("text to be translated") // works
} else {
Text(question) // does not work
}
Here is possible variant (old good NSLocalizedString) that still works (tested with Xcode 11.3 / iOS 13.3)
Text(NSLocalizedString(question, comment: ""))
other possible variant (tested in same environment) is
Text(LocalizedStringKey(question))
Related
We have a pure Win32/C++ app from which we want to be able to detect Tablet Mode on Windows 10.
I have the following code which came from somewhere which uses WRL to access the Windows.UI.ViewManagement.UIViewSettings.UserInteractionMode property:
WRL::ComPtr<IUIViewSettingsInterop> interop;
if (SUCCEEDED(Windows::Foundation::GetActivationFactory(WRL::Wrappers::HStringReference(
RuntimeClass_Windows_UI_ViewManagement_UIViewSettings).Get(),
&interop)) && interop)
{
WRL::ComPtr<vm::IUIViewSettings> pViewSettings;
if (SUCCEEDED(interop->GetForWindow(hWnd, IID_PPV_ARGS(&pViewSettings))) && pViewSettings)
{
vm::UserInteractionMode currentMode;
if (SUCCEEDED(pViewSettings->get_UserInteractionMode(¤tMode)))
return currentMode == vm::UserInteractionMode::UserInteractionMode_Touch;
}
}
This works fine, however we also have another function using WinRT and I gather WinRT is the current technology we should be using for this, so I was trying to work out how to convert the WRL code.
I came up with this code, which compiles fine, but throws an exception in GetForCurrentView():
auto uiSettings = winrt::Windows::UI::ViewManagement::UIViewSettings::GetForCurrentView();
return uiSettings.UserInteractionMode() == winrt::Windows::UI::ViewManagement::UserInteractionMode::Touch;
The error is HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND). I'm assuming there's something I'm meant to be doing to initialise the "current view", similar to how the WRL code provides a window handle to GetForWindow, but I haven't been able to work out how or what that is.
Thanks to #RaymondChen the C++/WinRT equivalent of the WRL code in my question is:
auto uiSettings = winrt::capture<winrt::Windows::UI::ViewManagement::UIViewSettings>
(winrt::get_activation_factory<winrt::Windows::UI::ViewManagement::UIViewSettings>()
.as<IUIViewSettingsInterop>(), &IUIViewSettingsInterop::GetForWindow, hWnd);
return uiSettings.UserInteractionMode() == winrt::Windows::UI::ViewManagement::UserInteractionMode::Touch;
After porting one huge project from BDS2006 to RAD11 (C++ VCL win32 classic compiler) I found out that one checkbox that should be unchecked at app start is always checked...
After breakpoint/tracing I localized the problem to this function:
void main_caption()
{
if (_simple_gfx) { _GLSL=0; Main->Caption=version+" Simplified graphics."; }
else if (_GLSL) Main->Caption=version+" GLSL";
else Main->Caption=version;
Main->ck_simple_gfx->Checked=_simple_gfx; // WTF here _simple_gfx is handled as true on RAD11 even if its not (even watch list shows false)
Main->ck_GLSL ->Enabled=!_simple_gfx;
Main->ck_GLSL ->Checked=_GLSL;
}
where _simple_gfx is simple global bool set to false (confirmed also with watchlist) used to fall back to OpenGL 1.0 on questionable gfx hardware/drivers (which is not the case now), Main is my main window/form and ck_simple_gfx is the checkbox that should not be checked (but it is checked after the assignment marked with comment WTF).
If I reset the _simple_gfx=false; like this:
void main_caption()
{
if (_simple_gfx) { _GLSL=0; Main->Caption=version+" Simplified graphics."; }
else if (_GLSL) Main->Caption=version+" GLSL";
else Main->Caption=version;
_simple_gfx=false;
Main->ck_simple_gfx->Checked=_simple_gfx; // WTF here _simple_gfx is handled as true on RAD11 even if its not (even watch list shows false)
Main->ck_GLSL ->Enabled=!_simple_gfx;
Main->ck_GLSL ->Checked=_GLSL;
}
then its unchecked as it should. What is happening? the main_caption is called from Main constructor if that matters...
I do not think its related to the VCL checkbox itself because if I do this:
if (_simple_gfx)
the stuff inside get executed while _simple_gfx "is" still false. There is no conflict with _simple_gfx identificator that I know of. If the same code (just different project file) is compiled on older IDE (BDS2006 C++ Turbo Explorer) the code works as should.
Changing the bool _simple_gfx to static and or volatile did not change anything.
Does anyone know what kind of bug is this and how to workaround it?
Did global variables behavior changed in newer versions of C++ Builders? (similar to GC compilers buggy behavior for non volatile global variables on MCU platforms)
Sorry I did not create MCVE as the project is really huge which is most likely the root cause of problem like this.
Im using a ForEach loop in my SwiftUI View and I am getting strange warnings.
It works fine like this:
ForEach(0..<7) { i in
// do something
}
Then I changed 7 to a constant:
let numberOfElements = 7
ForEach(0..<numberOfElements) { i in
// do something
}
And got the following warning:
Non-constant range: argument must be an integer literal
I googled an found the following solution which works:
let numberOfElements = 7
ForEach(0..<numberOfElements, id:\.self) { i in
// do something
}
However, I have no idea why it works. Why do I have to give an ID to the ForEach loop, and what is the ID for?
ForEach(0..<numberOfElements) { i in
// do something
}
The reason why using the above ForEach init pops the using literal value warning is because SwiftUI doesn't expect to re-render anything when using the Range<Int> init method. This is a documented requirement / feature. The exceptions are the init methods with id:.
A hashable id matters in SwiftUI as well as in many other view-tree based frameworks like React is because these UI frameworks needs to use these ids to track updates for views inside the ForEach or any other "Container Views", to help the framework achieve usable performance. If you want to dig deeper, take a look at this WWDC video: Demystify SwiftUI.
Hi all I am on a tutorial for maps but it is using Xcode 7 in the tutorial.
In the tutorial he uses this link but it has been stopped in the new version.
Can anybody let me know the best way to duplicate this?
I have added NSLocationWhenInUseUsageDescription in the plist.
func locationAuthStatus() {
if CLLocationManager.authorizationStatus() == .authorizedWhenInUse {
map.showsUserLocation = true
}else {
//cant get this to work in ios10
locationManager.requestWhenInUseAuthorization()
}
}
Any help will be appreciated.
solved....
I realised that I had created a constant named locationManager but spelt it lacationManager instead, I couldn't work out why it was asking me to change it to LacationManager then I realised the spelling mistake.
all works fine now.
What is wrong with this?
if A_OSVersion = WIN_7 or A_OSVersion = WIN_XP
{
MsgBox, Win7 or XP
} else {
if WinActive("ahk_exe Explorer") {
!f::!h
}
}
The goal is to replace Alt+F with Alt+H in Explorer when I'm running Windows 8, 8.1, or 10, and I am testing on a Windows 7 machine, so the code shouldn't run at all, but the hotkey does and the MsgBox doesn't. Do I need to reorder things for it to work? The syntax looks right to me, but I've been having a hard time with syntax for AHKscript.
Kind comments are appreciated!
This
!f::!h
isn't a command, it's a key remap and thus, implicitly contains a return. You cannot use it within executable context. For details, see http://ahkscript.org/docs/misc/Remap.htm#Remarks somewhere below.
You wouldn't wanna have a return somewhere in between the lines which should be executed, would you.
(this was mostly a copy of my answer here)
For context-sensitive hotkeys, use the preprocessor directives:
#if (A_OSVersion = "WIN_7" or A_OSVersion = "WIN_XP") and not winActive("ahk_exe Explorer")
!f::!h
#if
#if winActive("ahk_exe Explorer") and !(A_OSVersion = "WIN_7" or A_OSVersion = "WIN_XP")
!f::!h
#if
To do it within normal script flow you will need to used the Hotkey Command but then it will not be a remap but a hotkey that sends another set of keys...