Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Test-Driven iOS Development with Swift

You're reading from   Test-Driven iOS Development with Swift Create fully-featured and highly functional iOS apps by writing tests first

Arrow left icon
Product type Paperback
Published in Feb 2016
Publisher Packt
ISBN-13 9781785880735
Length 218 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Dr. Dominik Hauser Dr. Dominik Hauser
Author Profile Icon Dr. Dominik Hauser
Dr. Dominik Hauser
Arrow right icon
View More author details
Toc

Implementing a login request to a web service


Let's assume that a colleague is developing a web service, but it is not finished yet. However, we already know what the API will look like. There will be an endpoint for the login. The URL will be https://awesometodos.com/login; it will take two parameters, a username and password, and it will return a token that has to be used with each call to the API.

We need a test that asserts that the token, returned from the login call, is stored somewhere for later use. Tokens should be stored in the iOS keychain. Keychain access is managed by a very low-level API. This means that it is a bit complicated to build a class accessing keychain items (but it's easier than you might think). Because of this, there are a lot of available open source frameworks for reading from and writing to the keychain. Implementing keychain access is beyond the scope of this book. Instead, we will add a protocol that defines the methods that the keychain manager should implement...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime