The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Micheal Beatty (4) [Avatar] Offline
#1
Xcode generates some errors when entering the code as written in the book.

first is

Operator '+' declared in type 'Dictionary<Key, Value>' must be 'static'


Once we add the static keyword, then the line

var languages = someLanguages + moreLanguages 


generates the following error

ambiguous reference to member '+'


I'm not sure how to get past this.
Craig Grummitt (50) [Avatar] Offline
#2
Hi Michael - I believe you may have overloaded the operator inside the Dictionary extension - an easy mistake, and I should have made this clearer in the text, sorry! (Note to self to fix this in the next edition!)

You want to overload your operator in the global scope.

If you'd like, you can check out the Chapter 3 playgrounds here and open the "Extensions" page to see this working.

Let me know how you go with it. Good luck!
Micheal Beatty (4) [Avatar] Offline
#3
OK, that makes sense now. Tried it and it works.
I guess the first step which read

"Redefine the add method in a Dictionary extension" is what threw me off.

Thank you for the quick response!
Craig Grummitt (50) [Avatar] Offline
#4
Yes, exactly. Rereading it I can see how it can be confusing or ambiguous. It's intended to mean something like - "Remember the add method in the Dictionary extension? We're going to redefine that now" - and it should have been specific about defining it in the global scope. Apologies!