last day (15 days later) » 

12:16 PM
1
A: issue with passing array of dictionaries into function

Marcus RosselIt's an issue of scope. br, sr, and or were defined in the scope of the if-statement: if b == bnk && c == crnc { let br = dict["buyrate"] let sr = dict["sellrate"] let or = dict["officialrate"] println("\(br) -> \(sr) -> \(or)") } Therefore they are only useable within that blo...

 
I am afraid it is not working or I am doing something wrong:( swiftstub.com/980363852
 
Here's your version fixed: swiftstub.com/229281236 Here's my version: swiftstub.com/815194052
 
still something is wrong cause function returns nil swiftstub.com/376288768
 
hmm... I'm workin' on it.
 
You dont need one of returns in my version. By the way how to unwrap values? swiftstub.com/456023066 Don't know how to fix yours version
 
12:16 PM
Ah, there you go. Here's a version that's a little safer: swiftstub.com/189943415
 
Do you know how to unwrap values? Now it is (Optional(3.11), Optional(4.222), Optional(5.15))
 
Is the function ever supposed to be able to return some nil, and some actual values in the tuple? Or are all values supposed to be nil, or all have a value?
 
Function is not supposed to return nil. It should always return actual values
 
Well, that's not possible because you are using dictionaries, but in the end that means all or nothing I guess. So either (1, 2, 3) or (nil, nil, nil). Therefore you could just declare the whole tuple as optional, instead of each value: swiftstub.com/857545158
 
Thanks a lot! @Marcus
Hi Marcus I have an issue with the same function! Could you help me please? I have sent facebook request or you can give me you email. I will send few screenshots.
as you can see I am passing parameters and they reach function
then I print an array
and there is matching row there
but why function returns 0.0 I cant get it
everything was working when I was calling function showBankRates("SEB", currency: "AUD")!
but when I replaced strings to variables and started to call like this showBankRates(bname, currency: cname)!
it stoped working
 
 
4 hours later…
4:19 PM
Oh, you are Aleksej...
It would be great if you could just paste the portion of the code in SwiftStub and send me the link. It's kind of hard to tell what's happening just from the picture.
(Don't worry about any excess code being part of the block, I'll just ignore it)
 
4:58 PM
Yeah it was me:)
problem that in web it works fine! http://swiftstub.com/676005036/
but in xcode something is wired is going on there
 
Oh you just want the function to return (0.0, 0.0, 0.0) when it fails?
 
no I was experimenting.
there are three arrays
two of them are banks and currencies - user can pick them from UIPicker
so when they are picked I want to pass them as parameters into function which you helped me to create
BUT!!!!
it goes into loop ... (prints parameters correct) but doesn't go into loop of dictionaries

if dict["bank"]! == bank && dict["currency"]! == currency
scratching my head WHY!? when if I call function like this showBankRates("Swedbank", currency: "GBP - Great Britain Pound")!
everything works fine
for me it is not important what function will return ... nil or 0.0 0.0 0.0 ..
 
ok, I'm currently checking your dropbox-code...
 
cool
arrays are not not presented in that file. they were declared in another view
but you can copy form swiftstub
 
ok
Now when exactly are `testButton()` or `testIssue()` called?
And what purpose is `testButton()` supposed to have?
 
5:19 PM
they are called from storyboard. they are just to show that one function is not working and another is working
 
which one is working?
 
testbutton
working fine
 
and testIssue() isn't?
 
yes.. it is returning 0.0 0.0 0.0 and it even dont pass if clause if dict["bank"]! == bank && dict["currency"]! == currency
I cant understand why
 
I haven't changed anything relevant here, but could you send me the output of this: swiftstub.com/344606780
 
5:39 PM
>> we are calling: showBankRates(, )
>> 'showBankRates' called with (bank: , currency:
[officialrate: 2.15, currency: GBP - Great Britain Pound, buyrate: 0.1, sellrate: 1.5, bank: Swedbank]
[officialrate: 9.15, currency: RUS - Russian Ruble, buyrate: 7.11, sellrate: 8.222, bank: Swedbank]
[officialrate: 9.15, currency: USD - Russian Ruble, buyrate: 7.11, sellrate: 8.222, bank: Swedbank]
>> 'rates' is nil
>> 'testButton()' was successfully called.
>> 'showBankRates' called with (bank: Swedbank, currency: GBP - Great Britain Pound
 
You see that: "we are calling: showBankRates(, ) "
So `bname` and `cname` are still empty `String`s.
I assume `func pickerView(pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)` is supposed to be the function that sets these values, but isn't doing that correctly.
 
sorry I think it my fault ... will do it once again
SEB
RUS
>> we are calling: showBankRates(SEB, RUS)
>> 'showBankRates' called with (bank: SEB, currency: RUS
[officialrate: 2.15, currency: GBP - Great Britain Pound, buyrate: 0.1, sellrate: 1.5, bank: Swedbank]
[officialrate: 9.15, currency: RUS - Russian Ruble, buyrate: 7.11, sellrate: 8.222, bank: Swedbank]
[officialrate: 9.15, currency: USD - Russian Ruble, buyrate: 7.11, sellrate: 8.222, bank: Swedbank]
>> 'rates' is nil
>> 'testButton()' was successfully called.
>> 'showBankRates' called with (bank: Swedbank, currency: GBP - Great Britain Pound
I forget to choose parameters in the picker. and they don't have default value yet
 
I guess the problem is that you are passing strings that are simply different from the ones in the `bankDict`.
When you call `testButton()` it passes "Swedbank" and "GBP - Great Britain Pound " - which both exist in `bankDict`.
When you call `testIssue()` it passes "SEB" and "RUS" - which are not found in `bankDict`. Therefore the if-statement never becomes true.
 
6:00 PM
Oh God ...you are right ... ! the issue is in the text itself. So there is no ghost here!
 
:)
I just love, when it's actually that simple ^^
 
yeah ... I had idea to populate small arrays from big array of dictionaries. But did not find solution how you can extract distinct values from dictionaries.
do you have any apps published in app store?
 
wait, could you elaborate on that?
no, I don't even have xCode yet ^^
 
what do you mean elaborate?
 
what's your native language?
 
6:05 PM
you dont have xcode but you know a lot about programming:)

mine is russian and lithuanian because I am from Lithuania...
 
I read the book on swift, and that taught me a ton about the concepts that are used. If you haven't read it you should.

By elaborate I mean: https://translate.google.com/#auto/ru/genau%20darstellen
 
what is the name of the book?
google translate doesn't help much :) do you mean earn money from that?
 
"The Swift Programming Language" (https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/index.html) - The beginning might seem quite redundant, and the book pretty long in general, but you don't just learn about the syntax, but all kinds of stuff. Since you have a Mac, you can also download it in the iBooks-Store. I personally find it very usefull to mark things I don't know, so I can look them up quicker later on.

"to elaborate on something" means portraying it in a detailled way.
Oh, and a great website to find out about the details of swift is: http://swiftdoc.org/
It has great documentation on all the types, and protocols in Swift.
 
6:22 PM
yes I have this book and I am looking into it but was not reading it from the beginning till end. Actually I started to learn swift only one week ago. I just took took a simple idea and decided to realise it.

regarding details about arrays. I have array of dictionaries. And I am going to retrieve data from this array with help of my function. The function uses parameters to retrieve necessary data. These parameters user will select in application using UIPickerViews. To populate UIPickerViews we need also an array. So it is very logical to populate this array automatically from big one (ar
 
oh wow, did you have prior experience with objective-C?

Hm.. I still don't get it - nevermind ^-^
 
no ... I am working as a database developer right now. so I am good at SQL also VBA.
do you know how to populate array from json file?
 
Oh, nice!
Actually I don't, but this might be usefull: http://stackoverflow.com/a/27454804/3208492
 
I was leaving in Erlangen for half of the year by the way! Very nice country
 
6:37 PM
Wow, that's pretty close: https://www.google.de/maps/dir/Zella-Mehlis/Erlangen/@50.1731825,10.047915,8z/data=!4m13!4m12!1m5!1m1!1s0x47a39af2bbf23d7d:0x4208ec1743560c0!2m2!1d10.6649645!2d50.658799!1m5!1m1!1s0x47a1f8c7d57c34a1:0x41eda32beb5c7d0!2m2!1d11.0119611!2d49.5896744?hl=de

What's fundamentally different about Lithuania?
 
yeah pretty close. that's I decided to mention about that :)
was going to Dresden and Frankfurt for business meetings quite often

well ... it is small country .. not as rich as Germany. average salary is much smaller. But if you have good job it is comfortable to live here. I mean everywhere it is better to be rich :)
 
Dresden is nice!

Oh yeah it's just 3mio. people. So according to wikipedia people aren't to happy about how democricy is working out?
true ;)
 
a lot of people think that it is better to go to London and wash dishes in Chinese restaurant all life and earn 1500 EUR than to work normal work in Vilnius for 1000 EUR that is why they go to western Europe
actually evrything is fine here. Yesterday was drinking beer with guys from Norway. They come every two years to Lithuania for a trip
I am just a bit worried that Russia will start war against Lithuania
it wont be cool
 
7:03 PM
Well washing dishes is probably not as fun as programming ^^
Is there a lithuanian beer you could recommend?

Yeah Russia's being kind of weird at the moment :/ But I guess with english skills you can live in many places :D
What does your keyboard look like?
cause mine has the € symbol ^^
 
7:30 PM
there are a lot of beers in lithuania almost all of them are good! just don't buy the choppiest one! as well as in Germany beer considered as a national drink.
yes with English you can live almost everywhere but i don't want to leave my hose here and rent small apartment in the suburb of London :)
 

last day (15 days later) »