I want to loop through my list and create Tuple adding items from that list. I can't make it working
var arr = "PAR: Parent,SVE: School visit from an engineer,SCI: Science teacher";
var query = arr.Split(',').Select(x => x.Split(':'))
.ToDictionary(x => x[0], x => x[1]);
var list = query.ToList();
var tupleList = new List<Tuple<string, string>>
{
foreach (var i in list )
{
Tuple.Create(i.Key, i.Value);
}
};
What you need is
var tupleList = new List<Tuple<string, string>>();
foreach (var i in list)
{
tupleList.Add(Tuple.Create(i.Key, i.Value));
}
Collection initializer such as
var tupleList = new List<Tuple<string, string>>
{
foreach (var i in list)
{
Tuple.Create(i.Key, i.Value);
}
}
will not work.
Related
#State var sortDescriptor: SortDescriptor<Spell> = SortDescriptor(\.name)
I want to define the SortDescriptor so that letters come first than numbers.
Example: ["2st", "Cant", "1st"] -> ["Cant", "1st", "2nd"]
I don't know how to.
let array = ["2nd", "Cant", "1st", "Abc", "12some", "hello"]
extension Array where Element == String {
func sortedNrLast() -> Self {
self.filter { !"0123456789".map {$0}.contains($0.first) }.sorted() +
self.filter { "0123456789".map {$0}.contains($0.first) }.sorted()
}
}
print(array.sortedNrLast())
I have a visualization table that has an event listener on select.
The need: I want the user to be able to delete documents on the google drive without having to leave the webpage
The set up: I added a button so that when clicked, I get a confirm alert box that includes the value. Once I click OK, it runs the scripts from the client-side with an event handler. This works perfectly!
The problem: I can move one document at a time but if I need to move 20+ documents it gets really tedious to click rows one after the other. Is it possible to pass multiple values to the successhandler?
google.visualization.events.addListener(archiveChart.getChart(), 'select', function () {
$("#docArchive").on("click", function() {
var selection = archiveChart.getChart().getSelection();
var dt = archiveChart.getDataTable();
if (selection.length > 0) {
var item = selection[0];
var docurl = dt.getValue(item.row, 2);
var docname = dt.getValue(item.row, 1);
var folder = dt.getValue(item.row, 4);
if(confirm("Are you sure you want to archive " + docname + "?") == true) {
archiveChart.getChart().setSelection([]);
return google.script.run.withSuccessHandler(onSuccessArchive).withFailureHandler(function(err) {
alert(err);
}).archiveDoc(docurl,folder);
} else {
archiveChart.getChart().setSelection([]);
}
}});
})
I feel like I might need to add this:
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
I'm struggling a little with understanding what I might need to change (still learning). Any help or guidance is appreciated!
recommend confirming once, for all documents
then loop the selection to archive each document
google.visualization.events.addListener(archiveChart.getChart(), 'select', function () {
$("#docArchive").on("click", function() {
var selection = archiveChart.getChart().getSelection();
var dt = archiveChart.getDataTable();
var docNames = selection.map(function (item) {
return dt.getValue(item.row, 1);
}).join('\n');
if (selection.length > 0) {
if(confirm("Are you sure you want to archive the following document(s)?\n" + docNames) == true) {
for (var i = 0; i < selection.length; i++) {
var item = selection[i];
var docurl = dt.getValue(item.row, 2);
var docname = dt.getValue(item.row, 1);
var folder = dt.getValue(item.row, 4);
return google.script.run.withSuccessHandler(onSuccessArchive).withFailureHandler(function(err) {
alert(err);
}).archiveDoc(docurl, folder);
}
}
archiveChart.getChart().setSelection([]);
}
});
});
I am fetching user's information like his name,phone number and email id from contacts.But it is only showing first contact number.IF a person has more than one contact number,it didnt show that second number.Can someone help?I am using this function
where EVContactProtocol is part of Library
func didChooseContacts(_ contacts: [EVContactProtocol]?) {
var conlist : String = ""
if let cons = contacts {
for con in cons {
if let fullname = con.fullname(),let email1 = con.email , let phoneNumber = con.phone {
conlist += fullname + "\n"
print("Full Name: ",fullname)
print("Email: ",email1)
print("Phone Number: ",phoneNumber)
}
}
self.textView?.text = conlist
} else {
print("I got nothing")
}
let _ = self.navigationController?.popViewController(animated: true)
}
You should try this:
import Contacts
class ViewController: UIViewController
{
lazy var contacts: [CNContact] =
{
let contactStore = CNContactStore()
let keysToFetch = [
CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
CNContactEmailAddressesKey,
CNContactPhoneNumbersKey] as [Any]
// Get all the containers
var allContainers: [CNContainer] = []
do
{
allContainers = try contactStore.containers(matching: nil)
}
catch
{
print("Error fetching containers")
}
var results: [CNContact] = []
// Iterate all containers and append their contacts to our results array
for container in allContainers
{
let fetchPredicate = CNContact.predicateForContactsInContainer(withIdentifier: container.identifier)
do
{
let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
results.append(contentsOf: containerResults)
}
catch
{
print("Error fetching results for container")
}
}
return results
}()
override func viewDidLoad()
{
super.viewDidLoad()
print(contacts[0].givenName)
print(contacts[0].phoneNumbers)
print(contacts[0].emailAddresses)
print(contacts)
}
}
I have two dynamic texts, both of them are going to generate numbers. If one has a greater value then the other one, a movie clip must be loaded, else, another movie clip must be loaded.
It's also important to note that I need to choose exactly the place that this movie clip will be load.
I create this code, but it's not working.
btn01.addEventListener(MouseEvent.CLICK, fl_ClickToGoToAndStopAtFrame_27);
function fl_ClickToGoToAndStopAtFrame_27(event:MouseEvent):void
{
var texto.text;
function testGuess():void{
if (parseInt(texto.text) == 8)
var fl_MyInstance_3:greenlight = new greenlight();
addChild(fl_MyInstance_3);
}}}
stop();
// timer loading
var timer:Timer = new Timer(2500);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
function onTimer(evt:TimerEvent):void {
//primeiro indicador parte
var loader:URLLoader = new URLLoader(new URLRequest("bdaily.txt"));
loader.addEventListener(Event.COMPLETE, completeHandler);
function completeHandler(event:Event):void {
var loadedText:URLLoader = URLLoader(event.target);
bdaily.text = loadedText.data;
}
// segundo indicador.
var loader1:URLLoader = new URLLoader(new URLRequest("bmtd.txt"));
loader1.addEventListener(Event.COMPLETE, completeHandler1);
function completeHandler1(event:Event):void {
var loadedText1:URLLoader = URLLoader(event.target);
bmtd.text = loadedText1.data;
}
//terceiro indicador
var loader2:URLLoader = new URLLoader(new URLRequest("bwtd.txt"));
loader2.addEventListener(Event.COMPLETE, completeHandler2);
function completeHandler2(event:Event):void {
var loadedText2:URLLoader = URLLoader(event.target);
bwtd.text = loadedText2.data;
}
//terceiro indicador
var loader3:URLLoader = new URLLoader(new URLRequest("basketdtarget.txt"));
loader3.addEventListener(Event.COMPLETE, completeHandler3);
function completeHandler3(event:Event):void {
var loadedText3:URLLoader = URLLoader(event.target);
basketdtarget.text = loadedText3.data;
}
var loader4:URLLoader = new URLLoader(new URLRequest("basketwtdtarget.txt"));
loader4.addEventListener(Event.COMPLETE, completeHandler4);
function completeHandler4(event:Event):void {
var loadedText4:URLLoader = URLLoader(event.target);
basketwtdtarget.text = loadedText4.data;
}
var loader5:URLLoader = new URLLoader(new URLRequest("basketmtdtarget.txt"));
loader5.addEventListener(Event.COMPLETE, completeHandler5);
function completeHandler5(event:Event):void {
var loadedText5:URLLoader = URLLoader(event.target);
basketmtdtarget.text = loadedText5.data;
}
//condicionais para gerar movieclip condicional
var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
var new_clp = clp_index == 1 ? new clp_01() : new clp_02()
addChild(new_clp)
var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
var new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
addChild(new_clp2)
var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
var new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
addChild(new_clp3)
}
try this :
btn.addEventListener(MouseEvent.CLICK, btn_on_Press);
function btn_on_Press(e:MouseEvent):void {
var clp_index = parseInt(txt_01.text) > parseInt(txt_02.text) ? 1 : 2
var new_clp = clp_index == 1 ? new clp_01() : new clp_02()
// to set the new_clp position
new_clp.x = 250 // left position
new_clp.y = 50 // top position
addChild(new_clp)
}
Last Edit :
stop()
var new_clp, new_clp2, new_clp3
var timer:Timer = new Timer(3000)
timer.addEventListener(TimerEvent.TIMER, onTimer)
timer.start()
function onTimer(evt:TimerEvent):void {
var loader:URLLoader = new URLLoader(new URLRequest('bdaily.txt'))
loader.addEventListener(Event.COMPLETE, function(e:Event){
bdaily.text = loader.data
})
var loader1:URLLoader = new URLLoader(new URLRequest('bmtd.txt'))
loader1.addEventListener(Event.COMPLETE, function(e:Event){
bmtd.text = loader1.data
})
var loader2:URLLoader = new URLLoader(new URLRequest('bwtd.txt'))
loader2.addEventListener(Event.COMPLETE, function(e:Event){
bwtd.text = loader2.data
})
var loader3:URLLoader = new URLLoader(new URLRequest('basketdtarget.txt'))
loader3.addEventListener(Event.COMPLETE, function(e:Event){
basketdtarget.text = loader3.data
})
var loader4:URLLoader = new URLLoader(new URLRequest('basketwtdtarget.txt'))
loader4.addEventListener(Event.COMPLETE, function(e:Event){
basketwtdtarget.text = loader4.data
})
var loader5:URLLoader = new URLLoader(new URLRequest('basketmtdtarget.txt'))
loader5.addEventListener(Event.COMPLETE, function(e:Event){
basketmtdtarget.text = loader5.data
})
if(new_clp){
new_clp.parent.removeChild(new_clp)
new_clp = null
}
if(new_clp2){
new_clp2.parent.removeChild(new_clp2)
new_clp2 = null
}
if(new_clp3){
new_clp3.parent.removeChild(new_clp3)
new_clp3 = null
}
trace('new_clp : '+new_clp)
trace('new_clp2 : '+new_clp2)
trace('new_clp3 : '+new_clp3)
var clp_index = parseInt(bdaily.text) >= parseInt(basketdtarget.text) ? 1 : 2
new_clp = clp_index == 1 ? new clp_01() : new clp_02()
addChild(new_clp)
var clp_index2 = parseInt(bwtd.text) >= parseInt(basketwtdtarget.text) ? 1 : 2
new_clp2 = clp_index2 == 1 ? new clp_03() : new clp_04()
addChild(new_clp2)
var clp_index3 = parseInt(bmtd.text) >= parseInt(basketmtdtarget.text) ? 1 : 2
new_clp3 = clp_index3 == 1 ? new clp_05() : new clp_06()
addChild(new_clp3)
}
This is the simplest way, you can optimize it later.
I try to select/highlight an item of nestedlist with this code:
var activelist= nestedList.getActiveItem();
var listselectednode = activelist.getNode(1);
nestedPanel.fireEvent('itemtap',activelist,1,listselectednode ,e);
but not work.
Help
For posterity's sake here is how you just select (highlight) a node. This answer was adapted from the comments on the question.
var activeList = nestedList.getActiveItem();
// By index<br/>
activeList.getSelectionModel().select(index)
// By ID<br/>
var targetNode = activeList.store.getById(id);
activeList.getSelectionModel().select(targetNode);
And here is how you select and tap a node (by ID).
var activeList = nestedList.getActiveItem();
var targetNode = activeList.getNode(activeList.store.getById(targetNodeId));
var e = {} // You can provide event data here, if you like.
if (targetNode) {
var targetIndex = activeList.indexOf(targetNode);
nestedList.fireEvent('itemtap', activeList, targetIndex, targetNode , e);
activeList.getSelectionModel().select(targetIndex, true);
}