On Apr 25, 2015, at 7:59 AM, William Squires <wsqui...@satx.rr.com> wrote:

> Where I'm running into problems is this line of code:
> 
> func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: 
> NSIndexPath) -> UITableViewCell
> {
> var cell = tableView.dequeueReusableCellWithIdentifier(simpleTableIdentifier) 
> as? UITableViewCell
> if (cell == nil)
>  {
>  cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: 
> simpleTableIdentifier)
>  }
> cell!.textlabel.text = dwarves[indexPath.row] // Problem here
> return cell
> }
> 
> Xcode is complaining that a "?" or "!" is needed after "textLabel", and 
> before the ".text", but I don't really understand which one to use.

If you know and can prove that textLabel is NEVER nil then use !.
! translates to “I know this is not nil and if I’m wrong it’s OK to throw an
exception that terminates the program”.

If textLabel could be nil then use ?

Also, you are returning cell which is an optional but your function says it
is returning a UITableViewCell.   Either return cell! or change the function
to return an optional UITableViewCell.

I find optionals to be fantastic.  It’s interesting to find how optional
values thread their way through an application until you get to the point
where they must be unwrapped… and then you find it is nil because you made
a coding error 7 levels up the call tree.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to