Swift得到的文本框值由optional()包围

时间:2016-01-15 22:42:52

标签: ios swift

我的ViewController

class MandrillDeviseMailer < Devise::Mailer

  def confirmation_instructions(record, token, opts={})
    # code to be added here later
  end

  def reset_password_instructions(record, token, opts={})
    options = {
      :subject => "Reset your password",
      :email => record.email,
      :global_merge_vars => [
        {
          name: "password_reset_link",
          # content: "http://www.example.com/users/password/edit?reset_password_token=#{token}"
          content: "http://www.cr.com/users/password/edit?reset_password_token=#{token}"

        },

        {
          name: "PASSWORD_RESET_REQUEST_FROM",
          content: record.full_name 
        }
      ],
      :template => "Forgot Password"
    }
    mandrill_send options  
  end

  def unlock_instructions(record, token, opts={})
    # code to be added here later
  end

  def mandrill_send(opts={})
    message = { 
      :subject=> "#{opts[:subject]}", 
      :from_name=> "Reset Instructions",
      # :from_email=>"example@somecorp.com",
      :from_email=>["PROD_WELCOME"],
      :to=>
            [{"name"=>"#{opts[:full_name]}",
                "email"=>"#{opts[:email]}",
                "type"=>"to"}],
      :global_merge_vars => opts[:global_merge_vars]
      }
    sending = MANDRILL.messages.send_template opts[:template], [], message
    rescue Mandrill::Error => e
      Rails.logger.debug("#{e.class}: #{e.message}")
      raise
  end
end

当我在文本字段上按回车代码

<a href="*|password_reset_link|*">Change my password </a>

被调用。但是,labelTop的文字如下:

  

搜索可选(&#34;文字&#34;)

我查看了选项(大多数时候他们使用?而不是!对吗?)但是不明白我应该如何在没有周围的&#39;可选(&#34;&#34;)&#39的情况下获得价值;

1 个答案:

答案 0 :(得分:1)

您需要展开可选值。

if let text = textInput?.text {
    labelTop.text = text
    textInput.enabled = false
}