2. JSON Web Services
● Javascript Object Notation
● The JSON data format is widely used across the
modern web and it is one of the most common
ways to transfer data.
● Many modern APIs, RESTful web services in
particular, support the JSON data format.
● JSON is a commonly used data format that is
used for communication between, for example,
clients and servers.
● It is popular because of it's usability across
virtually any mobile platform such as iOS,
Android, Windows Phone, and web browsers.
● The code snippet on the right side is an
example of the JSON data format.
{
"dataTitle": "JSON Tutorial!",
"swiftVersion": 2.1
"users": [
{
"name": "John",
"age": 25
},
{
"name": "Mark",
"age": 29
},
{
"name": "Sarah",
"age": 22
}
],
}
3. JSON Web Services - Contd.
As you can see in the code snippet, the JSON data format is easy to understand. JSON is structured using two
collection types, dictionaries and arrays. Dictionaries contains one or more of key-value pairs and are enclosed by
curly braces, {}. Arrays contain a list of ordered items and are enclosed by square brackets, []. Almost every
programming language defines these collection types, which is why JSON is supported by nearly every every
language around.
The following is a list of the supported data types in a JSON object:
● String
● Number (integer, float, double, etc.)
● Boolean
● Array
● Dictionary
Part of the reason why JSON is so popular is because it is easy to read by humans and it can also be easily parsed
and serialized by machines. Parsing and serializing is when the machine takes in raw data and turns that into an
object useable by the application.
4. JSON Web Services - Sample
func getIPAddress()
{
let session = URLSession.shared
let urlPath = URL(string: "https://api.ipify.org/?format=json" )
var request = URLRequest(url: urlPath! as URL)
request.httpMethod = "GET"
let task = session.dataTask(with: request, completionHandler: {(data, response, error) in
if(error == nil)
{
do
{
let JSON = try JSONSerialization.jsonObject(with: data!, options:JSONSerialization.ReadingOptions.allowFragments)
print("IPAddress response is (JSON)")
let ipAddressDict = JSON as! [String: Any]
let ipAddress: String = ipAddressDict["ip"] as! String
print(ipAddress)
}
5. JSON Web Services - Sample
catch let JSONError as NSError
{
print("IPAddress API Error - (JSONError)")
}
}
else
{
print("IPAddress API Error - (error!)")
}
})
task.resume()
}
6. Source Control
● Source control (or version control) is the practice of tracking and managing changes to code.
● Source control management (SCM) systems provide a running history of code development and help to
resolve conflicts when merging contributions from multiple sources.
● Whether you are writing a simple application on your own or collaborating on a large software development
project as part of a team, source control is a vital component of the development process.
● Source code management systems allow you to track your code change, see a revision history for your code,
and revert to previous versions of a project when needed.
● With source code management systems, you can collaborate on code with your team, isolate your work until
it is ready, and quickly troubleshoot issues by identifying who made changes and what the changes were.
● Source code management systems help streamline the development process and provide a centralized
source for all your code.
7. Source Control - Git
● Git is an open-source distributed source code management system.
● Git allows you to create a copy of your repository known as a branch.
● A branch is way to keep a set of commits together. By working on different branches, you can keep features
separated and reduce your risk of totally breaking your project.
● Using this branch, you can then work on your code independently from the stable version of your codebase.
● Once you are ready with your changes, you can store them as a set of differences, known as a commit.
● You can pull in commits from other contributors to your repository, push your commits to others, and merge
your commits back into the main version of the repository.
● Three Steps:
○ Commit
○ Pull
○ Push
9. Source Control - How it works in Xcode
● To understand how Source Control works, open AppDelegate.swift and make some changes to the method
application(_:didFinishLaunchingWithOptions:)
● After you save the file, you will note that AppDelegate.swift now has an “M” badge next to the filename as
the image shown in Image-1. The “M” badge stands for “modified.” It means you have modified the file but
have not yet committed the changes to your local Git repository.
● The next step is to commit the changes made as shown in Image-2.
10. Source Control
● Once you click on commit, the
screen is split into two panes.
● The left pane shows the file in its
current state with all changes
made since the last commit.
● You can enter the commit message
and Commit the code.
11. Source Control
● Once you have committed the code, your next step is to pull the changes(if any) from the remote server to
your local repository (Image 1)
● The next step is to push your local changes to the server.
12. Other Useful features - Comparison
● Comparing versions is especially important when newly added code doesn’t work as it was expected and you
need to find any changes been made since the last stable version.
● To compare two different versions of a file, either use the View > Version Editor > Show Comparison View, or
click on the Version Editor button on the right-top corner of xcode, as shown below:
● Once you do any of the above, the editor splits up to two parts. The the left pane shows the current version
of the file, while the right one shows the previous revision.
● The known blue areas indicating the modified code are displayed, and that makes tracking down code
additions really easy.
● So, you can select any previous commit and watch the differences appeared between the two panes.
13. Other Useful features - Blame
● Further than comparing file versions,
Xcode allows to track down the person
who did a commit, as well as the one
who modified parts of code.
● This is a feature quite useful in cases of
projects in which work more than one
people.
● To use it, simply open the View >
Version Editor > Show Blame View
menu, or click on the Version Editor
button on the toolbar, and then select
the Blame option. Refer the image in
the previous slide.
● A window similar to the image will
appear to you.
14. Dependency Management - Cocoapods
CocoaPods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 40 thousand libraries
and is used in over 2.9 million apps. CocoaPods can help you scale your projects elegantly.
To create a new project with CocoaPods, follow these simple steps:
● Create a new project in Xcode as you would normally.
● Open a terminal window, and $ cd into your project directory.
● Create a Podfile. This can be done by running $ pod init.
● Open your Podfile. Pods would have created default values as below -
platform :ios, '8.0'
use_frameworks!
target 'MyApp' do
// mention the pods to be installed
end
15. Cocoapods - Contd.
● Mention the required cocoapods in the pod file and save it as below -
target 'ProjectName' do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
Use_frameworks!
pod 'RealmSwift'
pod 'Crashlytics', '~> 3.9.3'
end
● Then enter the $ pod install command in the terminal to install the cocoapods.
● You have to always open the Xcode workspace instead of the Xcode project file for further development.
● You can import the installed pods in your files like below -
import Crashlytics
import RealmSwift
16. Signing Identities and Certificates
● Code signing your app lets users trust that your app has been created by a source known to Apple and that it
hasn’t been tampered with.
● All apps must be code signed and provisioned to launch on a device, to use certain services, to be distributed
for testing, or to be uploaded to iTunes Connect.
● Code signing uses cryptographic technology to digitally sign your app and installer package.
● You create signing identities—stored in your keychain—and certificates—stored in your developer
account—to sign and provision your app.
● These assets uniquely identify you or your team, so it’s important to keep them safe.
● Code signing is used in combination with your App ID, provisioning profile, and entitlements to ensure that:
○ Your app is built and signed by you or a trusted team member.
○ Apps signed by you or your team run only on designated development devices.
○ Apps run only on the test devices you specify.
○ Your app isn’t using app services you didn’t add to your app.
○ Only you can upload builds of your app to iTunes Connect.
17. Identifiers, Devices, and Profiles
● You use your developer account to manage the identifiers, devices, and profiles used to code sign your app,
enable it to launch on devices, and use certain app services.
● Xcode creates and manages these assets for you during development.
● When you’re ready to distribute your app for testing, you use your developer account to manage some of
these assets yourself.
● For example, you can create custom development provisioning profiles, and bulk register devices used for
testing.
18. App Deployment
● You must have an iTunes Connect app record to validate and upload your app to iTunes Connect. To create
your app record, read more on Creating an App Record.
● The bundle ID you enter in iTunes Connect must match the bundle ID in your Xcode project.
● After you upload your first build, you can’t change the bundle ID in iTunes Connect.
● Choose Product -> Archive in Xcode. In the Archives organizer, select the archive you want to upload, and
click “Upload to App Store.”
● In the dialog that appears, choose a team from the pop-up menu and click Choose.
● If necessary, Xcode creates a distribution certificate and distribution provisioning profile for you. The name
of the distribution provisioning profile begins with the text XC:.
● In the dialog that appears, review the app, its entitlements, and provisioning profile and click Upload.
● Xcode uploads the archive to iTunes Connect and iTunes Connect runs validation tests.
● If issues are found, read the error messages, and click Done.
19. App Deployment - Contd.
● For a complete list of issues you should fix before distributing your app, read App Store Review Guidelines.
For more information on the app review process, go to App Review.
● If no issues are found, click Done.
● Xcode transmits the archive to Apple, where the build is examined to determine whether it conforms to
Apple guidelines. If the build is rejected, correct the problems that were identified and upload a new build. If
you successfully upload your app, view the version and build of your app in iTunes Connect.
● If your build has been successfully uploaded and you are ready to submit your app to App Review, submit
your App to the Store.