— Just past default

JSQMessagesViewController Swift 3

Nov 20, 2016

I actively contribute to JSQMessagesViewController, an Open Source Project, that makes it super easy to get a “iMessages” like feature into any app. Often the first step is the hardest. Many users have different levels of experience, education and understanding and since I am a Swift Nut we’ll explore implementing it in Swift.

So I will outline the minimum you have to do to get this up and running. 🏃

Step 1. Create Your project.

Open Xcode.

Go to File -> New Project.

Select single view application.

Give your project a name and save.

Step 2. Cocoapods to your computer

Cocoapods is a dependency manager for Swift and Objective-C Cocoa projects. It has over 25 thousand libraries and is used in over 1.2 million apps.

To install cocoapods open up terminalCommand + SpaceBar will open SpotLight. type Terminal or use finder -> /Applications/Utilities/Terminal.app
exicute this command in your terminal window and cocoapods will be installed

sudo gem install cocoapods

Once this has complete you need to navigate to your project’s directory(folder). You can open Folders by using the command cd followed by the path/to/file and you can move up a folder with the .. command.
To quickly open a folder in terminal type cd and then drag the file from finder to the terminal window. This will insert the path to the file for us. Hit enter and you are now at your project’s base directory.

Step 3. Adding cocoapods to your project

Run command

pod init

This creates a podfile for you. This is where you can manage pods that you want to incorporate in your app. Open this file up in your favorite text editor.

Step 4. Adding JSQMessagesViewController to your project

Save your file and close it. Now back in terminal type: pod install This will add the JSQMessagesViewController library to your project.

Step 5. Open Workspace

Pods do an interesting thing where they manage the configuration of your project for you so you do not have to. The way that they do this is by generating a .workspace for you. So if you had your project open in XCode previously, Close it and open the YourProjectName.workspace file that was generated.

At this point you should be able to hit run and your project builds. You will not see anything because we have not added anything yet but you should not have any build errors.

Step 6. Adding JSQMessagesViewController to your project

Now let’s code, modify the UIViewController that comes with crating a new project.

The last function in this code snippit is not required is is just a helper to show how you can add messages to your feed.

That’s it 🏁, the minimum amount of code you need to get a chat feature in your own app. There are tons of things that you can do from this point but we’ll save that for another time. Don’t be afraid to explore and change things. That’s how we learn. 🖖

If you have any questions or critiques open an issue on GitHub for this article and Ill see what I can do to help.