How to filter NSMutableArray SWIFT - ios

How can I filter NSMutableArray in swift?
Here is the data of my array
(
(
"http://api.preggrz.com/pics/121531121599372/65adec3fdeb58a5c24cb77be3011acd556182f66a1567.jpg",
"http://api.preggrz.com/pics/121531121599372/8e292eb776a62383eff8dc0f43ad5988fc2cee15d542d.jpg",
"http://api.preggrz.com/pics/121531121599372/bf98f74fa24c467ae686ace1676e2e48d7c9d67ccbf8a.jpg",
"http://api.preggrz.com/pics/121531121599372/cf48d39f51511e942f8b8f7e9cf6095c5b38c9228645c.jpg",
"http://api.preggrz.com/pics/121531121599372/fbe5c86f048ece3a3edebf786f30613986ac6f1d97aed.jpg"
),
(
"http://api.preggrz.com/pics/10154319685331226/032e9.jpg",
"http://api.preggrz.com/pics/10154319685331226/0a021363c2820f008968df61340844512d2ea79b781ca.jpg",
"http://api.preggrz.com/pics/10154319685331226/0ca77.jpg",
"http://api.preggrz.com/pics/10154319685331226/133b5b677b4adb2e854822cb13f7afcdb66b0b7d117e8.jpg",
"http://api.preggrz.com/pics/10154319685331226/19baf33927a241299a89069b7f953810a55d58bb73c4f.jpg"
),
(
"http://api.preggrz.com/pics/111896919230617/13878a5cb249a597d6aa72436032f6d535455cbcc76fd.jpg",
"http://api.preggrz.com/pics/111896919230617/9a702645cbdb7dd4565d6e3e8151b1bf32b88d7854453.jpg",
"http://api.preggrz.com/pics/111896919230617/b671642c6aaa09fae96dc437b06ca92fc8f83e6c0bf66.jpg",
"http://api.preggrz.com/pics/111896919230617/c03d17e9d513175390138c8404ec9052f0f50955936ac.jpg",
"http://api.preggrz.com/pics/111896919230617/f05950e92b3b4136d559b65b30bb7dc01d5a10eb7f864.jpg"
),
(
"http://api.preggrz.com/pics/104262049996560/00f87e416ba5f511df29bf327be0dbd15d4c37e236d97.jpg",
"http://api.preggrz.com/pics/104262049996560/02215e416ba5f511df29bf327be0dbd15d4c37e236d97.jpg",
"http://api.preggrz.com/pics/104262049996560/0414f804ac4caaecc484c902cdf8ef52147ddfefa171b.jpg",
"http://api.preggrz.com/pics/104262049996560/123898ad2dc2efd4e50744d93890441e39acce59a8d6f.jpg",
"http://api.preggrz.com/pics/104262049996560/15559.jpg"
),
(
"http://api.preggrz.com/pics/111009959320285/1e0a86087ce3f425a0a257ec3da89ca5b6e98ed86864d.jpg",
"http://api.preggrz.com/pics/111009959320285/4abff6a73c9fc9b6369cdc1df217fc05823f243e89822.jpg",
"http://api.preggrz.com/pics/111009959320285/565f2e9f3b259e131db2eca776259daaa08912355558a.jpg",
"http://api.preggrz.com/pics/111009959320285/605d06087ce3f425a0a257ec3da89ca5b6e98ed86864d.jpg",
"http://api.preggrz.com/pics/111009959320285/89b6a018955e19110b86195f0d1af693c0415add69bbe.jpg"
),
(
"http://api.preggrz.com/pics/120936158325602/1cd7b29d83553396d2da77abcc9e072b43eb07739f800.jpg",
"http://api.preggrz.com/pics/120936158325602/3eb56e0b539512383483e9e817ea5bb853dbda2c50f81.jpg",
"http://api.preggrz.com/pics/120936158325602/4693fe0b539512383483e9e817ea5bb853dbda2c50f81.jpg",
"http://api.preggrz.com/pics/120936158325602/613a09e4d95c89fb24858622c770db7e3de3ea76218ba.jpg",
"http://api.preggrz.com/pics/120936158325602/6361d9e4d95c89fb24858622c770db7e3de3ea76218ba.jpg"
),
(
"http://api.preggrz.com/pics/101520963605089/00d24f7b7f1f9b9eed50291eae536025bf9d43326d6ca.jpg",
"http://api.preggrz.com/pics/101520963605089/049da5cd1ac6b22364e22d98bab30949f534d39d7b2ed.jpg",
"http://api.preggrz.com/pics/101520963605089/04be4f7b7f1f9b9eed50291eae536025bf9d43326d6ca.jpg",
"http://api.preggrz.com/pics/101520963605089/076eaf7570a058c3a55c5260b6dbe3476b8f69e7d1c01.jpg",
"http://api.preggrz.com/pics/101520963605089/0c87ab59f22cf20807326f15da6970af2586a16296f58.jpg"
),
(
"http://api.preggrz.com/pics/108266076261880/0441fdf186cebef98b6d2a5d9457abfcf248789e05347.jpg",
"http://api.preggrz.com/pics/108266076261880/6e6afee3c37663d073c38485704c6284551ca376d48bc.jpg",
"http://api.preggrz.com/pics/108266076261880/a0eb79b908ecd2b80cf82f0f03123377addf03977988c.jpg",
"http://api.preggrz.com/pics/108266076261880/be09d49122ceb9dbba6583844ac2d8e84ded65e4b5155.jpg",
"http://api.preggrz.com/pics/108266076261880/fa1ffe456fdf25ab4fd9a6ece148a2d4a841a7f357de5.jpg"
),
(
"http://api.preggrz.com/pics/115124662241251/07156.jpg",
"http://api.preggrz.com/pics/115124662241251/1f670a26cdc8c32c7f7da4b5a9717a231cc3bb21dfe2f.jpg",
"http://api.preggrz.com/pics/115124662241251/23546a26cdc8c32c7f7da4b5a9717a231cc3bb21dfe2f.jpg",
"http://api.preggrz.com/pics/115124662241251/24603899268824db5bbb325ea974fa740981b24f7bdc6.jpg",
"http://api.preggrz.com/pics/115124662241251/32717.jpg"
)
I would like to filter it according to string that I will input. Thank you for your response.

Try something like this (code is self explanatory or commented):
func filteredStrings(input: String) -> [[String]] {
let items: [[String]] = [
[
"http://api.preggrz.com/pics/121531121599372/65adec3fdeb58a5c24cb77be3011acd556182f66a1567.jpg",
"http://api.preggrz.com/pics/121531121599372/8e292eb776a62383eff8dc0f43ad5988fc2cee15d542d.jpg",
"http://api.preggrz.com/pics/121531121599372/bf98f74fa24c467ae686ace1676e2e48d7c9d67ccbf8a.jpg",
"http://api.preggrz.com/pics/121531121599372/cf48d39f51511e942f8b8f7e9cf6095c5b38c9228645c.jpg",
"http://api.preggrz.com/pics/121531121599372/fbe5c86f048ece3a3edebf786f30613986ac6f1d97aed.jpg"
],
[
"http://api.preggrz.com/pics/10154319685331226/032e9.jpg",
"http://api.preggrz.com/pics/10154319685331226/0a021363c2820f008968df61340844512d2ea79b781ca.jpg",
"http://api.preggrz.com/pics/10154319685331226/0ca77.jpg",
"http://api.preggrz.com/pics/10154319685331226/133b5b677b4adb2e854822cb13f7afcdb66b0b7d117e8.jpg",
"http://api.preggrz.com/pics/10154319685331226/19baf33927a241299a89069b7f953810a55d58bb73c4f.jpg"
],
[
"http://api.preggrz.com/pics/111896919230617/13878a5cb249a597d6aa72436032f6d535455cbcc76fd.jpg",
"http://api.preggrz.com/pics/111896919230617/9a702645cbdb7dd4565d6e3e8151b1bf32b88d7854453.jpg",
"http://api.preggrz.com/pics/111896919230617/b671642c6aaa09fae96dc437b06ca92fc8f83e6c0bf66.jpg",
"http://api.preggrz.com/pics/111896919230617/c03d17e9d513175390138c8404ec9052f0f50955936ac.jpg",
"http://api.preggrz.com/pics/111896919230617/f05950e92b3b4136d559b65b30bb7dc01d5a10eb7f864.jpg"
],
[
"http://api.preggrz.com/pics/104262049996560/00f87e416ba5f511df29bf327be0dbd15d4c37e236d97.jpg",
"http://api.preggrz.com/pics/104262049996560/02215e416ba5f511df29bf327be0dbd15d4c37e236d97.jpg",
"http://api.preggrz.com/pics/104262049996560/0414f804ac4caaecc484c902cdf8ef52147ddfefa171b.jpg",
"http://api.preggrz.com/pics/104262049996560/123898ad2dc2efd4e50744d93890441e39acce59a8d6f.jpg",
"http://api.preggrz.com/pics/104262049996560/15559.jpg"
],
[
"http://api.preggrz.com/pics/111009959320285/1e0a86087ce3f425a0a257ec3da89ca5b6e98ed86864d.jpg",
"http://api.preggrz.com/pics/111009959320285/4abff6a73c9fc9b6369cdc1df217fc05823f243e89822.jpg",
"http://api.preggrz.com/pics/111009959320285/565f2e9f3b259e131db2eca776259daaa08912355558a.jpg",
"http://api.preggrz.com/pics/111009959320285/605d06087ce3f425a0a257ec3da89ca5b6e98ed86864d.jpg",
"http://api.preggrz.com/pics/111009959320285/89b6a018955e19110b86195f0d1af693c0415add69bbe.jpg"
],
[
"http://api.preggrz.com/pics/120936158325602/1cd7b29d83553396d2da77abcc9e072b43eb07739f800.jpg",
"http://api.preggrz.com/pics/120936158325602/3eb56e0b539512383483e9e817ea5bb853dbda2c50f81.jpg",
"http://api.preggrz.com/pics/120936158325602/4693fe0b539512383483e9e817ea5bb853dbda2c50f81.jpg",
"http://api.preggrz.com/pics/120936158325602/613a09e4d95c89fb24858622c770db7e3de3ea76218ba.jpg",
"http://api.preggrz.com/pics/120936158325602/6361d9e4d95c89fb24858622c770db7e3de3ea76218ba.jpg"
],
[
"http://api.preggrz.com/pics/101520963605089/00d24f7b7f1f9b9eed50291eae536025bf9d43326d6ca.jpg",
"http://api.preggrz.com/pics/101520963605089/049da5cd1ac6b22364e22d98bab30949f534d39d7b2ed.jpg",
"http://api.preggrz.com/pics/101520963605089/04be4f7b7f1f9b9eed50291eae536025bf9d43326d6ca.jpg",
"http://api.preggrz.com/pics/101520963605089/076eaf7570a058c3a55c5260b6dbe3476b8f69e7d1c01.jpg",
"http://api.preggrz.com/pics/101520963605089/0c87ab59f22cf20807326f15da6970af2586a16296f58.jpg"
],
[
"http://api.preggrz.com/pics/108266076261880/0441fdf186cebef98b6d2a5d9457abfcf248789e05347.jpg",
"http://api.preggrz.com/pics/108266076261880/6e6afee3c37663d073c38485704c6284551ca376d48bc.jpg",
"http://api.preggrz.com/pics/108266076261880/a0eb79b908ecd2b80cf82f0f03123377addf03977988c.jpg",
"http://api.preggrz.com/pics/108266076261880/be09d49122ceb9dbba6583844ac2d8e84ded65e4b5155.jpg",
"http://api.preggrz.com/pics/108266076261880/fa1ffe456fdf25ab4fd9a6ece148a2d4a841a7f357de5.jpg"
],
[
"http://api.preggrz.com/pics/115124662241251/07156.jpg",
"http://api.preggrz.com/pics/115124662241251/1f670a26cdc8c32c7f7da4b5a9717a231cc3bb21dfe2f.jpg",
"http://api.preggrz.com/pics/115124662241251/23546a26cdc8c32c7f7da4b5a9717a231cc3bb21dfe2f.jpg",
"http://api.preggrz.com/pics/115124662241251/24603899268824db5bbb325ea974fa740981b24f7bdc6.jpg",
"http://api.preggrz.com/pics/115124662241251/32717.jpg"
]]
return items.flatMap { stringArray in
let newArray: [String] = stringArray.filter{ $0.contains(input) } // The inner array of filtered strings. If the string contains an "input" then preserve it
return newArray.count > 0 ? newArray : nil // If the filtered array is empty do not include it.
}
}

Related

How do I force dependencies into separate chunks using manualChunk?

manualChunks: {
'#dnd-kit/core': [
'#dnd-kit/core',
'#dnd-kit/sortable',
'#dnd-kit/utilities',
],
'#radix-ui/react-collapsible': [
'#radix-ui/react-collapsible',
'#radix-ui/react-dropdown-menu',
'#radix-ui/react-navigation-menu',
],
react: ['react', 'react-dom'],
'react-aria': [
'#react-aria/checkbox',
'#react-aria/dialog',
'#react-aria/focus',
'#react-aria/meter',
'#react-aria/visually-hidden',
'#react-aria/utils',
'#react-aria/tooltip',
'#react-aria/overlays',
'#react-aria/radio',
],
'react-stately': [
'#react-stately/radio',
'#react-stately/toggle',
'#react-stately/checkbox',
],
slate: [
'#contra/slate',
'slate',
'slate-react',
'slate-history',
'slate-hyperscript',
],
'stream-chat': ['stream-chat', 'stream-chat-react'],
stripe: ['#stripe/react-stripe-js', '#stripe/stripe-js'],
visx: [
'#visx/curve',
'#visx/event',
'#visx/gradient',
'#visx/responsive',
'#visx/scale',
'#visx/shape',
'#visx/tooltip',
],
},
The above is my rollupjs manualChunk configuration.
Based on this configuration, I would expect to have several chunks that group together these dependencies.
However, almost everything ends up in stream-chat chunk.
What's happening and how do I achieve the desired result?

Adding data-pos info to latex output

As described here, Pandoc records Synctex-like information when the source is commonmark+sourcepos. For example, with this commonmark input,
---
title: "Sample"
---
This is a sample document.
the output in native format starts like this:
Pandoc
Meta
{ unMeta =
fromList [ ( "title" , MetaInlines [ Str "Sample" ] ) ]
}
[ Div
( "" , [] , [ ( "data-pos" , "Sample.knit.md#5:1-6:1" ) ] )
[ Para
[ Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:1-5:5" ) ]
)
[ Str "This" ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:5-5:6" ) ]
)
[ Space ]
, Span
( ""
, []
, [ ( "data-pos" , "Sample.knit.md#5:6-5:8" ) ]
)
[ Str "is" ]
but all that appears in the .tex file is this:
{This}{ }{is}...
As a step towards Synctex support, I'd like to insert the data-pos information as LaTeX markup, i.e. change the .tex output to look like this:
{This\datapos{Sample.knit.md#5:1-5:5}}{ \datapos{Sample.knit.md#5:5-5:6}}{is\datapos{Sample.knit.md#5:6-5:8}}...
This looks like something a Lua filter could accomplish pretty easily: look for the data-pos records, copy the location information into the Str record. However, I don't know Lua or Pandoc native language. Could someone help with this? Doing it for the Span records would be enough for my purposes. I'm using Pandoc 2.18 and Lua 5.4.
Here is an attempt that appears to work. Comments or corrections would still be welcome!
Span = function(span)
local datapos = span.attributes['data-pos']
if datapos then
table.insert(span.content, pandoc.RawInline('tex', "\\datapos{" .. datapos .. "}"))
end
return span
end

Swift password validation using REGEX [duplicate]

I am working on a Swift project and I need to use this regex to check email is valid or not but when the app start the checking the app crash and give me this error:
NSInternalInconsistencyException', reason: 'Can't do regex matching, reason: Can't open pattern U_REGEX_MISSING_CLOSE_BRACKET
This is my REGEX:
^(([^<>()[\\]\\.,;:\\s#\\\"]+(\\.[^<>()[\\]\\.,;:\\s#\\\"]+)*)|(\\\".+\\\"))#((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+[\\.]*)+[a-zA-Z]{2,}))$
Check unescaped brackets in your regex pattern:
let pattern
= "^(([^<>()[\\]\\.,;:\\s#\\\"]+(\\.[^<>()[\\]\\.,;:\\s#\\\"]+)*)|(\\\".+\\\"))"
// [ [ ] [ [ ]
+ "#((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+[\\.]*)+[a-zA-Z]{2,}))$"
// [ ] [ ] [ ] [ ] [ ] [ ] [ ]
You have some mismatching brackets [ ] in the first half of your pattern.
In some dialects of regex, you have no need to escape [ between [ and ], but in some other dialects, you need it.
Try adding some escapes to your regex:
let pattern
= "^(([^<>()\\[\\]\\.,;:\\s#\\\"]+(\\.[^<>()\\[\\]\\.,;:\\s#\\\"]+)*)|(\\\".+\\\"))"
// [ ^^ ] [ ^^ ]
+ "#((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+[\\.]*)+[a-zA-Z]{2,}))$"
// [ ] [ ] [ ] [ ] [ ] [ ] [ ]

Dynamic cell color in jspdf autoTable?

Is it possible to define the cell color with a nested property of the object mapped to the table ?
The JSON structure of the objects is :
objects: [
{
"agent": "agent_1",
"days": {
day_0: {
"code": "ABC",
"color": "#0062cc"
},
day_1: {
"code": "DEF",
"color": "#a09494b2"
}
},
{
[...]
}
]
I have a table defined like this :
let columns = [
{title: "Agent", dataKey: "agent"},
{title: "january 1st", dataKey: "day_0"},
{title: "january 2nd", dataKey: "day_1"}]
let rows = [
{agent: "agent_1", day_0: "ABC", day_1: "DEF"},
[...]
]
All that works fine. But I'd like to set the color of each day cell dynamically, set with the color code of the corresponding object. Something like :
createdCell: function(cell, data) {
{
cell.styles.fillColor = "day_0.color";
}
}
But I can't figure how to pass the data to the table. Is it possible ? Can displayProperty help in any way ?
EDIT: In this case it was that v2.3.4 of jspdf-autotable was needed
Based on our comments discussion I think I understood your problem. You can try something like this (with the hexToRgb function from here)
let columns = [{
title: "Agent",
dataKey: "agent"
},
{
title: "january 1st",
dataKey: "day_0"
},
{
title: "january 2nd",
dataKey: "day_1"
}
]
let objects = [{
agent: "agent_1",
day_0: {
"code": "ABC",
"color": "#00ff00"
},
day_1: {
"code": "DEF",
"color": "#ff0000"
}
// etc
}];
let doc = jsPDF()
doc.autoTable(columns, objects, {
createdCell: function(cell, data) {
let hex = cell.raw.color
if (hex) {
let rgb = hexToRgb(hex)
cell.styles.fillColor = rgb;
cell.text = cell.raw.code
}
}
});
doc.save('jhg.pdf')
function hexToRgb(hex) {
var bigint = parseInt(hex.replace('#', ''), 16);
var r = (bigint >> 16) & 255;
var g = (bigint >> 8) & 255;
var b = bigint & 255;
return [r, g, b];
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.4.1/jspdf.debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf-autotable/2.3.4/jspdf.plugin.autotable.js"></script>
I just leave the answer here just in case anyone needs it.
We can use the didParseCell hook.
doc.autoTable({
head: [[..., color]],
body: [[..., #ffffff], [..., #ff0000]], // pass hexa value to the cell
didParseCell: function (HookData) {
if (HookData.cell == undefined)
return;
// find cell taht contains the hexa value
// the change the fillColor property
// and set the cell value to empty
var color = HookData.cell.text[0];
if (color.match(/^#[a-fA-F0-9]{3}([a-fA-F0-9]{3})/g) != null) {
HookData.cell.styles.fillColor = hexToRgb(color);
HookData.cell.text = [];
}
}
});
Code to convert hexa to RGB:
hexToRgb(hex) {
var bigint = parseInt(hex.replace('#', ''), 16);
var r = (bigint >> 16) & 255;
var g = (bigint >> 8) & 255;
var b = bigint & 255;
return [r, g, b];
}
Package version:
jspdf : 2.5.1
jspdf-autotable :3.5.25

swift - how to parse this JSON object

// Get the #1 app name from iTunes and SwiftyJSON
DataManager.getTopAppsDataFromItunesWithSuccess { (iTunesData) -> Void in
let json = JSON(data: iTunesData)
println(json)
how to access all the elements of["venues"]["pub city"]["venue"] ?
{
"venues":{
"cityuser":"Beirut",
"venue-usernewplace":{
"star":[
],
"idcat":[
],
"namecat":[
],
"name":[
],
"id":[
],
"phone":[
],
"address":[
],
"crossStreet":[
],
"lat":[
],
"lng":[
],
"cc":[
]
},
"placesofpeople":{
"star":"false",
"nameplace":"B0 18",
"idplace":"4b52670df964a520847b27e3",
"count":"4",
"cc":"LB",
"phone":"01580018",
"crossStreet":"Main Highway",
"lat":"33.898404713314",
"lng":"35.534128372291",
"address":"Karantina"
},
"pubcity":{
"venue":[
{
"id":"4fe75b17e4b032d653ce50fd",
"idcat":"4bf58dd8d48988d11e941735",
"name":"Cl\u00e9 Cafe-Lounge Bar",
"phone":"71200712",
"address":"Mohammed Abdel Baki Street, Clemenceau",
"crossStreet":"Hamra, Facing Najjar Hospital",
"lat":"33.897185328966",
"lng":"35.487202808518",
"cc":"LB",
"count":"0",
"namecat":"Cocktail Bar",
"star":"false"
},
{
"id":"4e3e7533fa76455375c56a33",
"idcat":"4bf58dd8d48988d11f941735",
"name":"Skybar",
"phone":"03939191",
"address":"Biel",
"crossStreet":"Downtown Beirut",
"lat":"33.90610643966",
"lng":"35.510663636771",
"cc":"LB",
"count":"0",
"namecat":"Nightclub",
"star":"false"
},
{
"id":"4b52670df964a520847b27e3",
"idcat":"4bf58dd8d48988d11f941735",
"name":"B 018",
"phone":"01580018",
"address":"Karantina",
"crossStreet":"Main Highway",
"lat":"33.898404713314",
"lng":"35.534128372291",
"cc":"LB",
"count":"0",
"namecat":"Nightclub",
"star":"false"
},
There's two methods I know of.
1 Post that wall of text into a JSON formatter which makes that blob more readable. In which case you can then inspect which keys you can pull out from it.
2 Check the documentation.
Using swiftyJson:
if let venues = json["venues"]["pubcity"]["venue"].array {
//venue is an array of the dictionaries.
for venue in venues {
//just printing the name, but you have the whole dictioary of each venue here.
println(venue["name"].string!)
}
}

Resources