I have been trying to use shift operator and unwrapping in a piece of code, as I'm learning Swift (FYI just a beginner), so I'm trying out multiple things, but I'm stuck with this operator. Looking at different threads about shift operators, I came to a conclusion that,, I may have to overload my operands and then use them accordingly.
My piece of code :
var p : Int!
p = 24 >> 2;
if let msg = p{ print (msg); }
else { print("abcd"); }
Please, help! And also advice if my thinking is correct or not.
All I want to achieve is that both may work together.. If there is any way applicable... xD
If I understand the question correctly this is a misunderstanding and has nothing to do specifically with using optionals and shift operators together
If you want to use the syntax
if let x = y {then this is only allowed ifyis declared as optional since the code is pointless ifyis never nil because then you can safely useydirectly.When it comes to shift operators then neither value can be optional as far as I know so your example is a little contrived.
or unwrap with default value