In a previous article we introduced CocoaPods, a dependency management tool for cocoa development, and covered the why and how of using it. In this article, we are going to look at how to create your own CocoaPod and make it available for others to use in their projects.
For this tutorial, I have a class that formats phone numbers that I would like to make into a CocoaPod. My phone formatting library consists of the class files
To begin, run the following command to make sure that you have the latest CocoaPods version. The command will install CocoaPods if it isn’t already installed and will update if it is installed and needs updating.[code language='bash'][sudo] gem install cocoapods
Use of the
sudocommand depends on your Ruby installation. More on this in the previous tutorial.
I recommended that you use the latest version of CocoaPods because the command syntax may have changed and new features added.
To check the CocoaPods version, run
pod --version. At the time of writing this article, the latest version is 0.33.1.
There are various files that you need to include in your CocoaPod. These include the class files, Podspec, license, assets used in your library and a demo project that shows the use of your Pod (this is run when a user types
pod try [LIB_NAME]to see what it does before using it in a project).
You can create your own Pod directory structure and files or you can use a command that CocoaPods makes available which creates a template library structure to get you started quickly. This generates a Podspec file (we will look at what this is later in the article), license file, readme and a demo project complete with test files and a Podfile.
CocoaPods is a dependency management tool for iOS and OS X development that has been gaining a lot of traction in the Cocoa community. When using CocoaPods, you define your project’s dependencies in a file, which CocoaPods uses to determine and resolve dependencies between libraries before downloading the needed source code and linking it in an Xcode workspace.
As your project scales, you’ll be spending a lot of time managing its dependencies, time that could be better used writing code.
CocoaPods make managing dependencies in your code easier. Adding and removing dependencies is just a matter of defining them in a file and running a command to install them. CocoaPods reads the file, determines the dependencies that the listed libraries have and if there are any shared dependencies, it tries to determine the version that will satisfy all of them. It uses Semantic Versioning to try to resolve dependency versions.
It is a common requirement for apps to require a backend for data to be saved, shared with other users and synced between a user’s devices.
Building this backend can require time, a different skill set and other resources (e.g., servers, push notification services, etc). Fortunately, there are several platforms that provide ready-made customizable backends you can integrate with your apps. These are known as ‘Backend as a Service’, or BaaS in short.
Pros and Cons of Using BaaS
- Saves you time and resources.
- Provides different services in one package. Most of the available BaaS vendors not only provide backend cloud storage for you data, they also offer such services as push notifications, analytics, social network integration, etc.
- Caters to scaling. The BaaS platforms are built for scaling and as a developer, you will not need to do any extra work if you gain a large amount of users, just pay more.
- Easy to make changes. You can easily make changes to your application’s functionality without requiring a lot of rewrites to its backend. It is easy to change your database models using the platform’s dashboard. This comes in handy to anyone following the iterative ‘lean startup methodology’ of shipping and improving the app based on usage data.
- Using a BaaS can be expensive. While most of these services offer a free package for a certain number of requests a month. Things can suddenly become costly if your app was to become successful and rapidly gain many users.
- You might experience vendor lock-in where a switch to another platform is difficult. This is becoming less of a problem as most services now allow for easier migrations. You may have to give up some features as not all BaaS platforms offer the same.
- A huge disadvantage to consider before using a BaaS is the dependence of your app on a third-party service. A provider might make changes to its service (e.g. change pricing plans) which you will either have to accept or look for another solution. There is also the possibility of a service being shut down. This is a huge inconvenience as you will be forced to migrate your data to another provider or to build your own backend. An example of this is the recent shutdown of StackMob which forced developers to migrate their data.
For this tutorial, we are going to look at Parse to provide a backend for an iOS application. We’ll briefly look at what it offers, followed by building an application that will use it for user registration, authentication and storing of user data.
Parse is one of the more popular Backend as a Service platforms. The service offers three products in one package: Parse Core, Parse Push and Parse Analytics.
Parse Core generally handles the saving of data and social media integration. It also enables you to write your own code that will be run in the cloud thus providing custom server-side logic.
Parse Push is used to send push notifications. It enables the developer to customize, schedule and send push notifications to all registered users or a select group of users.
Parse Analytics enables you to track your app’s data. You can track usage data such as installations, active users, user retention, push notification open rates etc.
To start off, download the project file which includes a starter project and the completed final project. The application is a simple note taking application that enables a user to save and retrieve notes to the cloud, thus maintaining the same data across devices.
The project consists of a login, signup, notes table view and an add/edit note view as shown below.
On running the app, you will see an empty table view with Logout and Add buttons on the navigation bar. The app should require the user to login before using it. If the user is logged in, it will take them directly to the table view showing a list of saved notes. Otherwise it will bring up the Login view. If the user isn’t registered, then they will have an option of signing up.
To start, you should first create an account on parse.com if you don’t already have one. Once logged in, access the Dashboard where you should be able to create a new app and also see a list of all your apps. Create an app called NoteApp.
On creating the app, you will see a window containing your app IDs and keys. These will be used later in the iOS app.
Download the Parse SDK here. Unzip the file and drag the framework into your project’s Frameworks group folder.
Next we need to add some libraries to the project. Select your project on the project navigator, make sure the project target is selected and then click on the ‘Build Phases’ tab. Expand ‘Link Binary With Libraries’.
Click the Add icon at the bottom of the listed frameworks and add the following libraries.
Open the[code language="objc"]
AppDelegate.mfile and add the following import to the top of the file and make the following modification to the
application:didFinishLaunchingWithOptions:, method placing in your app id and client key.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
[Parse setApplicationId:@"YOUR APP ID"
clientKey:@"YOUR CLIENT KEY"];
To test the SDK, paste the following lines below the method call that sets the application id and client key in[code language="objc"]PFObject *testObject = [PFObject objectWithClassName:@"TestObject"];
testObject[@"foo"] = @"bar";
Run the app and navigate to the Parse dashboard on your browser. Select your app and click on the Data Browser tab. You should see a table data of the object that was created above.
In the Dashboard, you will find controls to add/remove rows and columns, set permissions, export the class and even drop the whole class. Drop the
TestObjectclass as we won’t need it for our app. Drop it by clicking on the More button and selecting Drop Class. Also delete the code that creates the
TestObjectwhen the application launches.
Not only can you create objects programmatically as we did above, but you can also do so using the Dashboard. We are going to create a
Postclass and some test posts that will be loaded in our app.
Click on the New Class button and name the class
Post. Leave the type as Custom. Add two string columns:
content. Add a few rows of data, just fill the title and content fields.
Apart from the
contentcolumns, other columns are also generated — objectId, createdAt, updatedAt and ACL. The ACL stands for Access Control Lists. These are used to specify the access control users and/or roles have on particular objects.
Back in our app, we’ll create a view controller for the notes table view. Parse has a convenient class which is a subclass of
PFQueryTableViewController. We’ll be using some of the functionality it offers like pull to refresh and pagination (which enables you to set the number of results each query gets you).
The App Store is a global market. Taking international users into consideration and building an app that adapts to them can greatly increase your market reach and/or your business growth. Instead of forcing users to make do with the default language, you could instead give them an app that presents information in their language. With […]
Introduction Localization is the process of providing the appropriate resources for your app based on the device’s language settings. If your app targets a specific locale, then localizing it might not be necessary. If it targets different regions speaking different languages, it might increase its reach and make it more usable to people speaking other […]
Periodically your Android application might need to perform a task, such as checking a server for updates. The AlarmManager class can be used to schedule and execute operations that need to occur even if the application isn’t running. The AlarmManager class enables the scheduling of repeated alarms that will run at set points in the […]
The action bar is an important design element, usually at the top of each screen in an app, that provides a consistent familiar look between Android apps. It is used to provide better user interaction and experience by supporting easy navigation through tabs and drop-down lists. It also provides a space for the app or activity’s identity, thus enabling the user to know their location in the app, and easy access to the actions that can be performed.
The action bar was introduced in Android 3.0, although support for older versions can be achieved by using the Android Support Library. Before its release, the Options Menu was usually used to provide the actions and functionality that are now put on the action bar. The action bar is included by default in all activities for apps with a
minSdkVersionof 11. You can disable it and opt to only use the options menu, but for better user experiences it’s better to use the action bar as it is visible to the user, while the options menu needs the user to request it and the user might not be aware of its existence in the first place.
This tutorial explores setting up the action bar and discusses the different configurations that it offers.
Setting up the Action Bar
To start off, we are going to create a new project. We won’t be using the Android Support Library, so make sure to select a minimum SDK version of 11 or above. When you run your project, the action bar will be included at the top of your app’s screen. It is included in all activities that use or inherit from the Theme.Holo theme – which is the default when the
minSdkVersionis set to 11 or greater. A typical action bar is shown in the following figure.
The ability to download data in pdf format is a common requirement that you will encounter when building web applications. There are different ways that this can be achieved in Rails. We are going to look at the two major ways used to generate pdf documents: with Ruby using a DSL for defining and styling the documents, or by using a library that will convert your HTML to PDF.
Application administration is a common requirement in most web applications and building one from scratch can be a daunting task. There are, however, some options that can save you from starting from nothing when creating your admin interface. We’ll be looking at one of the popular options available – Active Admin.
Why Responsive? These days, a lot of users read their emails through their mobile devices (about 48% according to this statistic) and if you want to provide a good user experience to your subscribers you should consider responsive email design. There are several ways to approach this. You could build the emails yourself from scratch […]