テスト用のターゲットを作成する必要があります。 ユニットテストを有効にした場合は、MyApplication_Testsという名前のターゲットが既に存在しているかもしれません。 その場合に、もしそのターゲットをユニットテスト用に使用しないのであれば、そのターゲットをKIF用に使用しても構いません。 それ以外の場合は、以下の手順で新規にターゲットを作成してください。
- Xcode上でプロジェクトやターゲット選択欄から、ターゲットの追加を押す
NSHTTPURLResponse *httpurlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"/hoge/"] | |
statusCode:200 | |
HTTPVersion:nil | |
headerFields:@{}]; | |
RKResponseMapperOperation *responseMapperOperation = [[RKResponseMapperOperation alloc] initWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"/hoge/"]] | |
response:httpurlResponse | |
data:[NSData new] | |
responseDescriptors:@[ | |
[RKResponseDescriptor responseDescriptorWithMapping:responseMapping | |
iOS9からApp Transport Security(ATS)が追加されました。 ATSとは安全なネットワーク接続を実現するための機能であり、Appleの要件を満たしていない場合は接続失敗という扱いになります。
対象となるのは、自社内サーバ、WebView経由、サードパーティライブラリ(SNS、広告、分析など)だと思います。 ATS自体を無効にするのはあまり良いやり方ではないので、これらのドメインをATSの例外に設定するのが一般的なやり方だと思います。
設定方法はInfo.plist
に指定の情報をセットするだけです。 しかし、プロジェクトのTarget
が多かったりConfiguration
によって設定を分けたい場合には、Info.plist
を個別に用意して管理する必要がありますが、無駄にInfo.plist
ファイルが増えるので良い方法ではないと思います。
この記事では、Protocol BuffersをSwiftでどう使うかサンプルアプリを使って説明します。Protocol Buffersの詳細はこちらの記事を先に読むと大体のイメージが掴めると思います。個人的には Protocol Buffersのメリットは型安全に書けて高速な通信が実現する ことだと思います。
今回のサンプルアプリは、クライアント側はAPIKit、サーバ側はKituraで 通信処理を実装します。サンプルアプリはGitHubで公開しているので、こちらからダウンロードして試してみてください。
また、URLSession
で実装したサンプルアプリもこちらに用意しました。URLSession
だけでも楽に実装できるので、こちらも参考にしてみてください。
import UIKit | |
protocol StoryboardInstantiable { | |
static var storyboardName: String { get } | |
static var storyboardIdentifier: String { get } | |
} | |
extension StoryboardInstantiable where Self: UIViewController { | |
static var storyboardName: String { return String(describing: self) } | |
static var storyboardIdentifier: String { return String(describing: self) } |
import Foundation | |
protocol UserDefaultsStorable { | |
associatedtype UserDefaultsKey: RawRepresentable | |
static func userDefaultsValue(forKey key: UserDefaultsKey) -> Bool? | |
static func userDefaultsValue(forKey key: UserDefaultsKey) -> Int? | |
static func userDefaultsValue(forKey key: UserDefaultsKey) -> Int64? | |
static func userDefaultsValue(forKey key: UserDefaultsKey) -> Double? | |
static func userDefaultsValue(forKey key: UserDefaultsKey) -> String? |
import UIKit | |
extension UICollectionView { | |
func registerNib<T: UICollectionViewCell>(forCellType type: T.Type) { | |
let name = String(describing: type) | |
let nib = UINib(nibName: name, bundle: nil) | |
register(nib, forCellWithReuseIdentifier: name) | |
} | |
func registerNib<T: UIView>(forSupplementaryViewOfKind elementKind: String, withType type: T.Type) { |
import Foundation | |
import APIKit | |
protocol ProtobufRequest: Request {} | |
extension ProtobufRequest { | |
var dataParser: DataParser { | |
return ProtobufDataParser() | |
} | |
} |
Apple recently open sourced swift-protobuf which is a plugin of Protocol Buffers for swift language. Protocol Buffers in Swift enables us to have type safety, make API faster and unify schema documentation of structured data. I had a chance to use swift-protobuf in my project and thought that there are many benefits for us, so I would like to share my thoughts.
I also created a repository which has sample server/client app with Protocol Buffers. Please take a look here if you're interested in what implementation looks like.
import UIKit | |
import RxSwift | |
import RxCocoa | |
extension Reactive where Base: UITableView { | |
func items<S: Sequence, Cell: UITableViewCell, O: ObservableType> | |
(cellType: Cell.Type) | |
-> (_ source: O) | |
-> (_ configureCell: @escaping (Int, S.Iterator.Element, Cell) -> Void) | |
-> Disposable |