Extending Dictionary of key : String value:Array in swift











up vote
1
down vote

favorite












How can I extend a Swift Dictionary of type [String:[Double]]?



What is the protocol/Class_Type to be conformed by the Value while extending the dictionary?



[ P.S : In this Extension I want to return all the keys whose value arrays contains a particular element(Double) that is send to the function.]










share|improve this question
























  • So you want to filter a dictionary to find keys that contain a particular double value?
    – Scriptable
    Nov 20 at 10:44










  • Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
    – Spangen
    Nov 20 at 10:46










  • Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
    – Siva Athi
    Nov 20 at 11:13















up vote
1
down vote

favorite












How can I extend a Swift Dictionary of type [String:[Double]]?



What is the protocol/Class_Type to be conformed by the Value while extending the dictionary?



[ P.S : In this Extension I want to return all the keys whose value arrays contains a particular element(Double) that is send to the function.]










share|improve this question
























  • So you want to filter a dictionary to find keys that contain a particular double value?
    – Scriptable
    Nov 20 at 10:44










  • Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
    – Spangen
    Nov 20 at 10:46










  • Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
    – Siva Athi
    Nov 20 at 11:13













up vote
1
down vote

favorite









up vote
1
down vote

favorite











How can I extend a Swift Dictionary of type [String:[Double]]?



What is the protocol/Class_Type to be conformed by the Value while extending the dictionary?



[ P.S : In this Extension I want to return all the keys whose value arrays contains a particular element(Double) that is send to the function.]










share|improve this question















How can I extend a Swift Dictionary of type [String:[Double]]?



What is the protocol/Class_Type to be conformed by the Value while extending the dictionary?



[ P.S : In this Extension I want to return all the keys whose value arrays contains a particular element(Double) that is send to the function.]







swift dictionary protocols extension-methods






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 15:04









timgeb

48k116390




48k116390










asked Nov 20 at 10:42









Siva Athi

83




83












  • So you want to filter a dictionary to find keys that contain a particular double value?
    – Scriptable
    Nov 20 at 10:44










  • Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
    – Spangen
    Nov 20 at 10:46










  • Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
    – Siva Athi
    Nov 20 at 11:13


















  • So you want to filter a dictionary to find keys that contain a particular double value?
    – Scriptable
    Nov 20 at 10:44










  • Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
    – Spangen
    Nov 20 at 10:46










  • Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
    – Siva Athi
    Nov 20 at 11:13
















So you want to filter a dictionary to find keys that contain a particular double value?
– Scriptable
Nov 20 at 10:44




So you want to filter a dictionary to find keys that contain a particular double value?
– Scriptable
Nov 20 at 10:44












Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
– Spangen
Nov 20 at 10:46




Welcome to stackoverflow.com. Please take some time to read the help pages, especially the sections named "What topics can I ask about here?" and "What types of questions should I avoid asking?". Also please take the tour and read about how to ask good questions. Lastly please read this question checklist.
– Spangen
Nov 20 at 10:46












Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
– Siva Athi
Nov 20 at 11:13




Yes, I know how to Find the keys, But Primarily I need to know How Extend this type of Dictionary.
– Siva Athi
Nov 20 at 11:13












2 Answers
2






active

oldest

votes

















up vote
1
down vote



accepted










Dictionaries have two generic elements Key and Value that need constraining when you create your extension.



You can do that like so:



public extension Dictionary where Key == String, Value == [Double] { }





share|improve this answer























  • Thank You, This Works fine!
    – Siva Athi
    Nov 20 at 13:54










  • @SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
    – royalmurder
    Nov 21 at 13:59










  • Sorry that I forget it.
    – Siva Athi
    Nov 26 at 6:52


















up vote
0
down vote













You can use filter to do that like below:



let dictData = ["a":[1.0,2.0,3.0],
"b":[1.0,112.0,3.0],
"c":[7.0,12.0,3.0]]

let filterData = dictData.filter({$0.value.contains(1)})
print(filterData.keys) //output: ["a", "b"]


You can itrate this array like this:



 for keys in filterData.keys.makeIterator() {
print(keys)
}


Or you can directly access like this:



filterData.keys.first





share|improve this answer























  • yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
    – Siva Athi
    Nov 20 at 11:12










  • @SivaAthi: I have updated answer Please have a look
    – Jogendar Choudhary
    Nov 20 at 11:20










  • Yeah, Taken care of. Thank you for the Update :)
    – Siva Athi
    Nov 21 at 7:09













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391231%2fextending-dictionary-of-key-string-valuearray-in-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Dictionaries have two generic elements Key and Value that need constraining when you create your extension.



You can do that like so:



public extension Dictionary where Key == String, Value == [Double] { }





share|improve this answer























  • Thank You, This Works fine!
    – Siva Athi
    Nov 20 at 13:54










  • @SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
    – royalmurder
    Nov 21 at 13:59










  • Sorry that I forget it.
    – Siva Athi
    Nov 26 at 6:52















up vote
1
down vote



accepted










Dictionaries have two generic elements Key and Value that need constraining when you create your extension.



You can do that like so:



public extension Dictionary where Key == String, Value == [Double] { }





share|improve this answer























  • Thank You, This Works fine!
    – Siva Athi
    Nov 20 at 13:54










  • @SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
    – royalmurder
    Nov 21 at 13:59










  • Sorry that I forget it.
    – Siva Athi
    Nov 26 at 6:52













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Dictionaries have two generic elements Key and Value that need constraining when you create your extension.



You can do that like so:



public extension Dictionary where Key == String, Value == [Double] { }





share|improve this answer














Dictionaries have two generic elements Key and Value that need constraining when you create your extension.



You can do that like so:



public extension Dictionary where Key == String, Value == [Double] { }






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 12:46

























answered Nov 20 at 11:25









royalmurder

13010




13010












  • Thank You, This Works fine!
    – Siva Athi
    Nov 20 at 13:54










  • @SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
    – royalmurder
    Nov 21 at 13:59










  • Sorry that I forget it.
    – Siva Athi
    Nov 26 at 6:52


















  • Thank You, This Works fine!
    – Siva Athi
    Nov 20 at 13:54










  • @SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
    – royalmurder
    Nov 21 at 13:59










  • Sorry that I forget it.
    – Siva Athi
    Nov 26 at 6:52
















Thank You, This Works fine!
– Siva Athi
Nov 20 at 13:54




Thank You, This Works fine!
– Siva Athi
Nov 20 at 13:54












@SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
– royalmurder
Nov 21 at 13:59




@SivaAthi if you've found an answer that resolves your question, try to remember to mark it as the accepted answer! You'll get a small reputation boost, as well as helping other readers with the same problem get to the solution faster!
– royalmurder
Nov 21 at 13:59












Sorry that I forget it.
– Siva Athi
Nov 26 at 6:52




Sorry that I forget it.
– Siva Athi
Nov 26 at 6:52












up vote
0
down vote













You can use filter to do that like below:



let dictData = ["a":[1.0,2.0,3.0],
"b":[1.0,112.0,3.0],
"c":[7.0,12.0,3.0]]

let filterData = dictData.filter({$0.value.contains(1)})
print(filterData.keys) //output: ["a", "b"]


You can itrate this array like this:



 for keys in filterData.keys.makeIterator() {
print(keys)
}


Or you can directly access like this:



filterData.keys.first





share|improve this answer























  • yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
    – Siva Athi
    Nov 20 at 11:12










  • @SivaAthi: I have updated answer Please have a look
    – Jogendar Choudhary
    Nov 20 at 11:20










  • Yeah, Taken care of. Thank you for the Update :)
    – Siva Athi
    Nov 21 at 7:09

















up vote
0
down vote













You can use filter to do that like below:



let dictData = ["a":[1.0,2.0,3.0],
"b":[1.0,112.0,3.0],
"c":[7.0,12.0,3.0]]

let filterData = dictData.filter({$0.value.contains(1)})
print(filterData.keys) //output: ["a", "b"]


You can itrate this array like this:



 for keys in filterData.keys.makeIterator() {
print(keys)
}


Or you can directly access like this:



filterData.keys.first





share|improve this answer























  • yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
    – Siva Athi
    Nov 20 at 11:12










  • @SivaAthi: I have updated answer Please have a look
    – Jogendar Choudhary
    Nov 20 at 11:20










  • Yeah, Taken care of. Thank you for the Update :)
    – Siva Athi
    Nov 21 at 7:09















up vote
0
down vote










up vote
0
down vote









You can use filter to do that like below:



let dictData = ["a":[1.0,2.0,3.0],
"b":[1.0,112.0,3.0],
"c":[7.0,12.0,3.0]]

let filterData = dictData.filter({$0.value.contains(1)})
print(filterData.keys) //output: ["a", "b"]


You can itrate this array like this:



 for keys in filterData.keys.makeIterator() {
print(keys)
}


Or you can directly access like this:



filterData.keys.first





share|improve this answer














You can use filter to do that like below:



let dictData = ["a":[1.0,2.0,3.0],
"b":[1.0,112.0,3.0],
"c":[7.0,12.0,3.0]]

let filterData = dictData.filter({$0.value.contains(1)})
print(filterData.keys) //output: ["a", "b"]


You can itrate this array like this:



 for keys in filterData.keys.makeIterator() {
print(keys)
}


Or you can directly access like this:



filterData.keys.first






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 at 11:19

























answered Nov 20 at 10:59









Jogendar Choudhary

2,3241518




2,3241518












  • yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
    – Siva Athi
    Nov 20 at 11:12










  • @SivaAthi: I have updated answer Please have a look
    – Jogendar Choudhary
    Nov 20 at 11:20










  • Yeah, Taken care of. Thank you for the Update :)
    – Siva Athi
    Nov 21 at 7:09




















  • yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
    – Siva Athi
    Nov 20 at 11:12










  • @SivaAthi: I have updated answer Please have a look
    – Jogendar Choudhary
    Nov 20 at 11:20










  • Yeah, Taken care of. Thank you for the Update :)
    – Siva Athi
    Nov 21 at 7:09


















yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
– Siva Athi
Nov 20 at 11:12




yes, That Works!! But also I would like to know how to extend this type of Dictionary, Primarily.
– Siva Athi
Nov 20 at 11:12












@SivaAthi: I have updated answer Please have a look
– Jogendar Choudhary
Nov 20 at 11:20




@SivaAthi: I have updated answer Please have a look
– Jogendar Choudhary
Nov 20 at 11:20












Yeah, Taken care of. Thank you for the Update :)
– Siva Athi
Nov 21 at 7:09






Yeah, Taken care of. Thank you for the Update :)
– Siva Athi
Nov 21 at 7:09




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391231%2fextending-dictionary-of-key-string-valuearray-in-swift%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen