Using the below code it’s possible to create a basic three-column iPad layout.
#main
struct threepanelApp: App {
var body: some Scene {
WindowGroup {
NavigationView {
List(0..<10, rowContent: { i in
Text(String(describing: i))
})
.listStyle(SidebarListStyle())
.navigationTitle("One")
List(10..<20, rowContent: { i in
Text(String(describing: i))
})
.navigationTitle("Two")
VStack {
Text("Panel Three")
}
.navigationTitle("Three")
}
}
}
}
However, when the app launches, it does so in its two-column layout.
What I'd like to achieve is the app launching in its three-column layout:
Is this possible with SwiftUI 2?
Figured out a hacky way to do this:
Dip into UIKit in .onAppear, find the UISplitViewController, and set its preferredDisplayMode.
var body: some Scene {
WindowGroup {
NavigationView {
List(0..<10, rowContent: { i in
Text(String(describing: i))
})
.navigationTitle("One")
ListTwo()
VStack {
Text("Panel Three")
}
.navigationTitle("Three")
}.onAppear {
let controller = UIApplication.shared.windows.first { $0.isKeyWindow }!.rootViewController
guard let split = controller?.children[0] as? UISplitViewController else {
print("not a split view")
return
}
split.preferredDisplayMode = .twoBesideSecondary
}
}
}
when adding this extension, then everything is expanded on app start:
extension UISplitViewController {
open override func viewDidLoad() {
super.viewDidLoad()
preferredDisplayMode = .twoBesideSecondary
}
}
Related
For some reason, a List will reset its selection to nil when the app is in the background.
Steps to reproduce the issue:
Run attached sample project
Once the app has launched, select a name in the sidebar
Move the app to the background
Wait a few seconds
Bring back the app to the foreground
Expected result:
The list selection should still be valid
Actual result:
The list selection is set to nil
Notes:
I’m using a StateObject, which should be the way to ensure that data isn’t regenerated when views are rendered. Is this a bug or something else needs to be taken care of?
class AppModel: ObservableObject {
#Published var selectedPerson: Person?
}
#main
struct NilListSelectionApp: App {
#StateObject var appModel = AppModel()
var body: some Scene {
WindowGroup {
ContentView()
.environmentObject(appModel)
}
}
}
struct Person: Identifiable, Hashable {
let id: UUID
let firstname: String
init(firstname: String) {
id = UUID()
self.firstname = firstname
}
}
struct ContentView: View {
#EnvironmentObject private var appModel: AppModel
var body: some View {
NavigationSplitView {
SidebarView()
} detail: {
PersonView(person: appModel.selectedPerson)
}
}
}
struct SidebarView: View {
#EnvironmentObject private var appModel: AppModel
private let persons = [Person(firstname: "Joe"), Person(firstname: "Jane")]
var body: some View {
List(persons, id:\.self, selection: $appModel.selectedPerson) { person in
Text(person.firstname).tag(person)
}
.listStyle(.sidebar)
}
}
struct PersonView: View {
let person: Person?
var body: some View {
if let person {
Text(person.firstname)
}
else {
Text("No Selection")
}
}
}
I have a text file that looks like this:
;MPV_F4(isHold, taps, state)
MPV_F5(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
MPV_F6(isHold, taps, state)
;MPV_F7(isHold, taps, state)
;MPV_F8(isHold, taps, state)
;MPV_F9(isHold, taps, state)
;MPV_F11(isHold, taps, state)
MPV_N2(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
;MPV_N3(isHold, taps, state)
;MPV_N4(isHold, taps, state)
;MPV_N5(isHold, taps, state)
which essentially consists of a repeating pattern of:
FunctionName(isHold, taps, state)
{
<Function Body>
}
I am trying to break it down into arrays that consists of the function name and body. I cant use the string MPV in my regex as there are other similar texts files whose function names does not contain MPV.
My exepected output is:
$MyVar [0] :
MPV_F5(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
$MyVar [1] :
MPV_N2(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
At first I tried to use Get-Content's -Delimeter parameter:
$mytextfile = "c:\temp\mytextfile.txt"
Get-content $mytextfile -Delimiter '.*[^;]\(isHold, taps, state\)'
It keeps returning the entire content as a single object, After a few more variations I resorted to just using Get-Content -Raw and then -Split operator:
$MyVar = $mytextfile -Split (?m).*[^;]\(isHold, taps, state\)(?s).*\}
I continue to get unexpected results, most commonly the entire content being returned instead of arrays.
I am using RegEx101*, and options are closesly aligned to what powershell expects. I have tried many variations with no desired results.
Here is a link my RegEx101 page.
What could I be doing wrong here?
Any help would be truelly wellcome.
Try the following:
$MyVar =
[regex]::Matches(
(Get-Content -Raw $mytextfile),
'(?sm)\w+\(isHold, taps, state\)\s*\{(?:.(?!\w+\(\w))+\}'
).Value
Note that this approach is computation-intensive and relies on detecting the end of a function not by properly detecting nested { / } pairs, but by assuming that the presence of any subsequent <funcname>(<wordcharacter> substring (e.g. 'MPV_F6(i') implies that the most recent } ended the function body.
See this regex101.com page.
I created a multi-timbral instrument application based on multiple AVAudioUnitSampler instances (one per Midi channel), wrapped in a custom AVSampler class.
I want to expose it also as an AUv3. I followed some articles and samples and put the view controller and other classes in a Framework target, created an AudioUnit extension target (with a dummy/empty class file as I've no implementation to provide).
In the extension's Info.plist (NSExtensionAttributes) I added AudioComponentBundle (points to the AUFramework) and AudioComponents item with factoryFunction (points to $(PRODUCT_MODULE_NAME).MultiSamplerViewController), aumu type. Also added NSExtensionPrincipalClass pointing to AUFramework.MultiSamplerViewController.
In the shared MultiSamplerViewController I implemented
(AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
return [[[multiSampler engine] outputNode] AUAudioUnit];
}
It also contains an - (id)initWithCoder:(NSCoder*)decoder method, that instantiates the wrapping MultiSampler and starts an enclosed MidiManager.
The host application target runs fine, however the AU extension plugin isn't listed in GarageBand (even after runnig the host application once). The target platform is iPad.
I added code to load the appex plugin bundle, however it doesn't seem enough to register the plugin. Also I cannot use the AUAudioUnit registerSubclass as I've no concrete AU implementation class (only my wrapper class).
I'm in the same configuration as an application built on AudioKit framework (that originally wrapped AVAudioUnitSampler - and now uses a custom implementation). I looked into AudioKit code and found they implemented AudioUnit protocols methods in their wrapper class (https://github.com/AudioKit/AUv3-Example-App/blob/master/Example%20Plugin%20App%20AU/Audio%20Unit/ExampleApp_AudioUnit.swift). However I don't know what to do in AUAudioUnit methods implementation (setOutputBusArrays, allocateRenderResources, internalRenderBlock, etc.)
EDIT :
I may have to implement AUaudioUnit callbacks.
To pass mainMixerNode buffers to AUaudioUnit render callback I could store (in memory, so would grow over time... not ideal) these through installTapOnBus, and then access these from render callback.
AVSampler : AUAudioUnit
createAudioEngine
...
[mixerNode installTapOnBus:0
bufferSize:4096
format:[[AVAudioFormat alloc]initWithStreamDescription:&audioFormat]
block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[self.timeToBuffer addObject:buffer forKey:when];
}];
(AUInternalRenderBlock)internalRenderBlock {
return ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags,
const AudioTimeStamp *timestamp,
AVAudioFrameCount frameCount,
NSInteger outputBusNumber,
AudioBufferList *outputBufferListPtr,
const AURenderEvent *realtimeEventListHead,
AURenderPullInputBlock pullInputBlock ) {
int outputNumBuffers = outputBufferListPtr->mNumberBuffers;
float *ptrLeft = (float*)outputBufferListPtr->mBuffers[0].mData;
float *ptrRight = NULL;
if (outputNumBuffers == 2) {
ptrRight = (float*)outputBufferListPtr->mBuffers[1].mData;
}
AVAudioPCMBuffer *mixerNodeBuffer = [self.timeToBuffer objectForKey:timestamp];
mixerNodeBuffer.audioBufferList.pointee.mBuffers
int n = frameCount;
if(mixerNodeBuffer.frameLength == frameCount)
for (int i=0;i<n;i++) {
ptrLeft[i] = mixerNodeBuffer.floatChannelData[0].pointee[n];
ptrRight[i] = mixerNodeBuffer.floatChannelData[1].pointee[n];
}
}
}
I have a very large dataset with multiple columns to sum and categories, but here is an example of what i am trying to do:
I want to sum up the "dollars" column to the total Account Number level based on which line with account number has the highest number in the "people" column. So there is just 1 line for every account number, and the State column will have whichever state has the higher people in it.
Account Number State Dollars People
1 MA 200 5
1 NY 100 2
2 CT 150 3
3 OH 100 3
4 VA 300 7
4 FL 100 3
and it will look like this after the code:
Account Number State Dollars People
1 MA 300 7
2 CT 150 3
3 OH 100 3
4 VA 400 10
I think this may be a simple fix but please help!
Thanks in advance!!
proc sql;
create table T2 as
select 'Account Number'n, State, sum(Dollars) as Dollars, sum(People) as People, People as People_Order
from T1
group by 'Account Number'n
order by People_Order desc
;quit;
/* keep the first row within previously performed Order By: */
proc sort data=T2 (drop=People_Order) nodupkey; by 'Account Number'n;run;
Sorry I'm lost I really appreciate if you can help me calculate the follwoing
So I've a table two fy data LY(Last Year) FY2020 and (This Year) or FY2021,
I would like to compare this year we spent on Agency vs Avg Spent on LY
Agency spend vs last year average; expressed as % of total people costs spend in month
The table output is like
2020 2021
F_Month AgencyPaid2020 msrAgencyPayPrv AgencyPay msrAgencyPayPrv
1 217922 18161 37930 18161
2 296460 24705 56155 24705
3 298863 24905 0 24905
. xxxx xxxxx 0 xxxx
.
12 110166 9181 0
--- --------- ------------ ------------- --------------
Total 169955 141630 18225 141630
I'm expecting 141630 should show in all rows for above table(Col2) but when I drag the measure into table its calculating differently
The measure I've calculated is
> msrAgencyPayPrvYearAvg =
> CALCULATE(SUM(Data[IM_Actual_Positive]),Data[EBITDA]="2
> Pay",Data[PayCat_1]="Agency",Data[int_fyear]=2020)/12'''
Thanks for you help
The 4th column should not show 2021 is there a way I can hide as its coming because in the 'Visualization' under column I've put 'int_fyear' column
and vales I've (Agency Pay and msrAvgAgencyPay) , sorry I 've lost the plot
Kind regards,
Farhan
I've found the answer I should use the following function
msrAgencyPaySheet =
CALCULATE(Sum(Sheet1[Actual]),filter(ALLSELECTED(Sheet1), Sheet1[FY]=2020))/12