if messages[i].header == nil || messages[i].header.sender == nil || messages[i].header.sender.displayName == nil{
snd = "No Name"
}
else
{ snd = messages[i].header.sender.displayName
}
since i got solution of my answer if you have more then 1 values who become nil messages[i] == nill or may be sender could be nill or displayname == nill so for this we have to use or condition to check indiviually
You should really take some care into cleaning up your formatting. It's sloppy. Also, you should use
if letto conditionally unwrap and bind the value inside an optional, if it exists`:Even better, you can use the nil-coalescing operator (
??):In response to your edited question. Again, you're code is a complete mess. This code makes it look like it costs you money to type letters.
msgs?snd?sbj? Really? Ismessages,sender,subjectthat much harder to write? Think of how much cleaner and easier they are for the readers of your code. Without even fixing it yet, just look at how much more manageable this code is after some clean-up:Now, here's my attempt at fixing it up: