iOSライブラリ管理ツールのCarthageが0.4にアップデート

Release 0.4: Carthage Unpinned · Carthage/Carthage · GitHub

大きな変更としては、3つ!

1. ディレクトリ構造
以前は

Cartfile
Cartfile.lock
Carthage.build
Carthage.checkout

だったのが

Cartfile
Cartfile.resolved
Carthage/
    Build/
    Checkouts/

になりました。

2. Cartfileで任意のブランチやタグが指定可能に

こんな感じ

# Require version 2.3.1 or later
github "ReactiveCocoa/ReactiveCocoa" >= 2.3.1

# Require version 1.x
github "Mantle/Mantle" ~> 1.0    # (1.0 or later, but less than 2.0)

# Require exactly version 0.4.1
github "jspahrsummers/libextobjc" == 0.4.1

# Use the latest version
github "jspahrsummers/xcconfigs"

# Use a project from GitHub Enterprise, or any arbitrary server, on the "development" branch
git "https://enterprise.local/desktop/git-error-translations.git" "development"

3. Carthage生成によるApp Storeリジェクト回避

Carthageを利用したプロジェクトをそのままリリースするとリジェクトされる問題について
iOS frameworks built with Carthage cannot be submitted to the App Store · Issue #188 · Carthage/Carthage · GitHub

こちらのissueで開発者達の苦労の後が見られて楽しいです。
Add `copy-framework` by robb · Pull Request #208 · Carthage/Carthage · GitHub

方法はREADMEにて説明されています。
Carthage/README.md at a8a6bb83229892e57530ac6096e85907078bd061 · Carthage/Carthage · GitHub

  • Cartfile作成
  • “General” settings tab, in the “Linked Frameworks and Libraries” sectionに追加したいframeworkをCarthage/Buildフォルダからドラッグ&ドロップ
  • Run Script追加する
/usr/local/bin/carthage copy-frameworks
  • “Input Files”にパスを追加する
$(SRCROOT)/Carthage/Build/iOS/LlamaKit.framework
$(SRCROOT)/Carthage/Build/iOS/ReactiveCocoa.framework

SwiftのCompilerバグ

optimization levelを-OFastestにすると
DataTypeRef?.toOpaque()がnilを返すためkeychainからデータを上手く読み出せない。


対策

  • optimization levelを-ONoneにする
  • objective-Cを使う

objective-Cを使う場合の例です。
ここでは、SSKeychainというライブラリを利用しています。
この場合loadの返す値が若干異なるので注意して下さい。
全く同じ実装にはなっていません。

様々なAPIドキュメントを確認できるDevdocs.io

DevDocs: Open-source / Offline API Documentation Browser
にアクセスすると、Ruby, Rails, Redis, HTML, CSS, Ember.js, Git...などなど様々なAPIドキュメントを検索、参照出来ます。

リポジトリThibaut/devdocs · GitHubにて公開されてます。

SendGridでメールを送信する

1. mailerを作成

$ rails generate mailer UserNotifier

app/mailers/usernotifier.rb

class UserNotifier < ActionMailer::Base
  default :from => 'any_from_address@example.com'

  # send a signup email to the user, pass in the user object that   contains the user's email address
  def send_signup_email(user)
    @user = user
    mail( :to => @user.email,
    :subject => 'Thanks for signing up for our amazing app' )
  end
end

2. templateを作成
app/views/Usernotifier/send_signup_email.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
  </head>
  <body>
    <h1>Thanks for signing up, <%= @user.name %>!</h1>
    <p>Thanks for joining and have a great day! Now sign in and do
awesome things!</p>
  </body>
</html>

3. SendGridを利用するように設定
config/environment.rb

ActionMailer::Base.smtp_settings = {
  :user_name => 'your_sendgrid_username',
  :password => 'your_sendgrid_password',
  :domain => 'yourdomain.com',
  :address => 'smtp.sendgrid.net',
  :port => 587,
  :authentication => :plain,
  :enable_starttls_auto => true
}

4. UserNotifier.send_signup_email(@user).deliverなどの様にして呼び出す。
app/controllers/users_controller.rb

class UsersController < ApplicationController
  def create
    # Create the user from params
    @user = User.new(params[:user])
    if @user.save
      # Deliver the signup email
      UserNotifier.send_signup_email(@user).deliver
      redirect_to(@user, :notice => 'User created')
    else
      render :action => 'new'
    end
  end
end