Wednesday, November 18, 2015

Catalog App Tutorial: Part 3

Hey again everyone! We finished part 2 in this series last night and I'm back to continue part 3. I'm sorry about how many parts this tutorial is being split into, but its kind of a large project that needs some time to develop. Anyway, we're going to make this UITableView begin to work tonight. First, we're going to start off with Parse.

Open up your web browser and head over to www.parse.com. Open up the project we created a couple of days ago and select the core button. This is where we will create our clothing objects. To the left there is going to be a little pane. In this pane, click on the "Add Class" button. Keep the selector on "Custom" and name the class Clothing. Now a whole new table will appear. Click on the "+ Col" button to create a new column. Make the column a string object and name it "name". Then create five more string objects and name them "price", "link", "type", "description", and "featured". Now create another column, but this time make the object type "PFFile". Name this object "pic1". Do this two more times and name the other objects "pic2" and "pic3". Now that we created all of the pieces of the object, we are going to create our first object. Press the "+ Row" button to add a new row to the table. Find a piece of clothing from the web that you like and put in the corresponding information. Make sure the link is valid. Also, to add an image, double click the area under the PFFile title that says "undefined". This will allow you to add an image from your computer. Once your done creating your object, open up your Xcode project.
Now, add the following import to your customCellFile.h and tableViewController.h files:

 #import <Parse/Parse.h>

This allows us to use the Parse SDK in the project. Now add the following property under the @interface section in tableViewController.m:

@property NSMutableArray *arrayOfClothes;

This creates an editable array that we will put all of our clothing objects into. Now add the following method somewhere the "viewDidLoad:" method.

-(NSMutableArray *)loadClothing
{
    
    NSMutableArray *clothesArray = [[NSMutableArray alloc]init];
    
    PFQuery *query = [PFQuery queryWithClassName:@"Clothing"];
    
    [query orderByDescending:@"createdAt"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        //3
        if (!error) {
            

            clothesArray = [NSMutableArray arrayWithArray: objects];
            [self.tableView reloadData];
            
            
        } else {
            
            //4
            NSString *errorString = [[error userInfo] objectForKey:@"error"];
            UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:errorString delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
            [errorAlertView show];
        }
    }];

    
    return clothesArray;
}

This method is what retrieves our "Clothing" class we just created and return all of the objects within that class. In order to make this method useful, we'll have to call it in "viewDidLoad:". Add the following line of code in the "viewDidLoad:" method.

self.arrayOfClothes = [self loadClothing];

This method makes "arrayOfClothes" hold what is returned by the method. This allows "arrayOfClothes" to hold all of the objects from Parse. Now that we actually have an array with items in it, find the method that is called "numberOfRowsInSection". After the part that says return, type out the code [self.arrayOfClothes count]. This line allows the table view to know how many rows to display on the table. Now we need to make the table view cell actually display some information. Find the method that is called "cellForRowAtIndexPath. Add the following code after the line that creates a new custom cell.

PFObject *clothing = [self.searchArray objectAtIndex:indexPath.row];
        NSString *name = [clothing objectForKey:@"name"];
        NSString *description = [clothing objectForKey:@"description"];
        NSString *price = [clothing objectForKey:@"price"];
        NSString *url = [clothing objectForKey:@"link"];
        PFFile *clothingFile = [clothing objectForKey:@"pic1"];
        PFFile *clothingFile2 = [clothing objectForKey:@"pic2"];
        PFFile *clothingFile3 = [clothing objectForKey:@"pic3"];
        NSString *clothingPicUrl = clothingFile.url;
        NSString *clothingPicUrl2 = clothingFile2.url;
        NSString *clothingPicUrl3 = clothingFile3.url;
        
        cell.imageArray = [NSArray arrayWithObjects:clothingPicUrl,clothingPicUrl2,clothingPicUrl3, nil];
        cell.clothingUrl = url;
        cell.currentObject = clothing;
        
        cell.nameLabel.text = name;
        cell.descriptionLabel.text = description;
        cell.priceLabel.text = price;

        [cell awakeFromNib];

This code sets all of the different labels we have equal to the info of our object in the database. It also creates an array of the three images we have for each object. This code will be used to display multiple images in the cell later. The part that says [cell awakeFromNib] is calling the method that loads up the cell in order to display an array of images within the cell. This call is normally not needed for simpler table view projects, however, this project make the table view cell handle a little more code. Now open up customTableViewCell.h.

Under the @interface section of the file, add the following properties.

@property PFObject *currentObject;
@property NSInteger currentIndex;
@property NSArray *imageArray;
@property NSString *clothingUrl;

The PFObject allows the cell to know what object we are looking at in the array, currentIndex is for displaying multiple images in one imageView, imageArray is the array that contains all of the images in the Parse database, clothingUrl holds the url for the object. Now open up the customTableViewCell.m file.

In the "viewDidLoad" method add the following code.

    UISwipeGestureRecognizer *swipeLeft = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeImage:)];
    swipeLeft.direction = UISwipeGestureRecognizerDirectionLeft;
    [self.clothingImage addGestureRecognizer:swipeLeft];
    
    UISwipeGestureRecognizer *swipeRight = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeImage:)];
    swipeRight.direction = UISwipeGestureRecognizerDirectionRight;
    [self.clothingImage addGestureRecognizer:swipeRight];
    
    self.currentIndex = 0;
    [self showImageAtIndex:self.currentIndex];
    self.control.numberOfPages = self.imageArray.count;

This code allows our UIImage on the cell to recognize swipe gestures that will change the pictures within the UIImageView. It sets the number of pages to be displayed from the number of objects in our array from Parse. It also sets the first index to 0 so we start at the first picture. Now we will add some more methods to help the swiping gestures work. At this time we will need to link another library to our project. This library is called SDWebImage. This lets us load images from the internet easily without taking too much data. It uses a process called "lazy loading" which sets an image that we already have on our device to the table view cell image while we're loading the real image from the internet. It also makes all of the image loading occur on a background thread. For now, search "SDWebImage iOS" in google and follow the installation instructions on their GitHub site.

Now that SDWebImage is hooked up, we can continue. Add the following methods under the "viewDidLoad" method.

-(void)showImageAtIndex:(NSInteger)index
{
    
    [self.clothingImage setImageWithURL:[NSURL URLWithString:[self.imageArray objectAtIndex:index]] placeholderImage:[UIImage imageNamed:@"Place Holder.jpg"]];
}

//method to detect swipes on mainImage
-(void)swipeImage:(UISwipeGestureRecognizer*)recognizer
{
    NSInteger index = self.currentIndex;
    
    if (recognizer.direction == UISwipeGestureRecognizerDirectionLeft)
    {
        index++;
    }
    else if (recognizer.direction == UISwipeGestureRecognizerDirectionRight)
    {
        index--;
    }
    
    if (index >= 0 && index < ([self.imageArray count]))
    {
        self.currentIndex = index;
        [self showImageAtIndex:self.currentIndex];
        [self.control setCurrentPage:self.currentIndex];
    }
    else
    {
        NSLog(@"Reached the end, swipe in opposite direction");
    }
    
}

The "showImageAtIndex" method uses an SDWebImage method to set the correct image to the cell. The image file called "Place Holder.jpg" can be any image that you put into your project. Make sure the name matches exactly. The "swipeImage" method detects if the swipe is to the left or to the right and changes the index accordingly. It then displays the image at the corresponding index in the array. Now, if you run the application you should be able to see a table view with your object from Parse in it! Congratulations on displaying your first database item! Currently, the buy button, wish list button, and share button will not work, but we will hook those up within the next couple of tutorials. Take a break from coding and enjoy the progress you've made. We've gone through a lot of different topics in this one short section. I hope you enjoyed part 3 of this catalog app tutorial series! Remember to contact me if you have any questions and most importantly have a great night!

Tuesday, November 17, 2015

iOS Catalog App: Part 2

Hopefully everyone enjoyed Part 1 of the Catalog App Tutorial series. Once again, if anybody needs any help, feel free to contact me. Just to review, in the last section, we created a Parse account, set up an Xcode project and create our initial view by using a TabBarController, NavigationController, and UITableViewController. Today, we're going to create the cell that will hold our catalog's information and begin the code for the table view. This is the main part of the app so make sure you follow closely and understand all of the details. Let's begin!

First things first, open up the Xcode project we made yesterday. Once thats up, get into your storyboard and focus on the UITableViewController. We're going to start off by creating the file that will control your UITableViewController. Press "File" in the upper left corner of your computer screen. Then go to "New" and then select "File". From there, you'll have a lot of choices appear. Under "iOS", select "Source" and then "Cocoa Touch Class". Next, choose "UITableViewController" in the section that says "Subclass of". Then name your file and make sure "Objective-C" is checked and "Create XIB file" is unchecked. Then press next and your file should be made! Now we need to make a second file for our custom UITableViewCell. Press "File" again and then go to "New" and then "File". From there, select "iOS", then "Source", then "Cocoa Touch Class". Next choice "UITableViewCell" in the section that says "Subclass of". Then name your file and make sure "Objective-C is checked and "Create XIB file" is unchecked. Press "Next" and your custom table view cell is ready! Get back to your storyboard and select the UITableViewController. In the right hand pane, click the button at the top that looks like an ID and says Identity Inspector when you hover over it. Click the section that says "Class" and find the name of the class that we just created. Set the class to this file. Now on your UITableViewController, you should see a little view that says "Prototype Cells". Click on this view and you should see a small area where you can drag the view at the bottom of the view. Drag this to a height of about 372. You can change it if you want, but thats just what I used for myself. Next, drag in a UIImageView and make the width the same as the Prototype Cell. The height should be around 371, but this is also up to you. Now, drag in three labels. One will be for the name, one will be for the price, and one will be for the description. Bring the price label to the top left hand corner of the image view. Make the width of the label almost as long as the cell. Make the name label to the left of the cell and directly under the ImageView. Under the name label place the description label. Make the width of both of these almost as long as the cell. Make the description label a bit longer than the name label so it can hold a long description. Also, select the name label and on the right hand pane, make the section that says "Lines" have two. Do the same with the description label, but make the "Lines" section say 3 or 4. Next add a UIPageControl and put that toward the bottom of the UIImageView but horizontally centered. Finally, drag three buttons onto the storyboard. Click on each one and to the right enter in the name field as "Share", "Buy", and "Wishlist" respectively. Drag these to the very bottom of the cell. You image should look like the image below minus the "Filter" button and the search bar, we'll add those later.

Now, we'll move onto making connections. Open the assistant editor by clicking on a button that looks like two intersecting circles in the top right corner. This will create two different screens. Select the custom table view cell file we made earlier to place on the second screen using a selector at the top. To make connections, we right click on an interface piece and drag it over to the area under "@interface". We'll start with the UIImageView. Right click on the UIImageView and drag it over to the area under the "@interface". When you let go make sure the "Connection" area says "Outlet" and make a name for the UIImageView. I used "clothingImage" as the name of the connection since I was making a fashion catalog app. Name yours whatever you want. Go over this same procedure with the UIPageControl, name label, description label, and price label. The procedure is a little different with the button. Do the same right click drag under "@interface", but when the box pops up, make the "Connection" area say "Action" then make sure it says "TouchUpInside". After that create a name for this action. Do the same with the other two button. Now your UITableViewCell is all connected!

Now we'll start the basics of the UITableViewController. Open up the UITableViewController we created a little while ago. Scroll to an area that says "numberOfSectionsInTableView" replace the section that says "return 0;" say "return 1;". This creates one section for the UITableView. Now, uncomment the area that says "cellForRowAtIndexPath". Replace the old cell declaration code with this:

YourCellFileName *cell = (YourCellFileName *)[self.tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];

Go back to your UITableViewController in the Storyboard. After that select the "Prototype Cell" that is inside the TableViewController. When you click on the cell, look to the right pane. In this section, make sure the area that says "Identifier" say "cell". Make sure this is lower case because Objective-C is Case Sensitive. This is it for today. Later, we'll be making many more adjustments to these two views. However, first we'll need to make Parse imports so we can successfully download the objects that we will end up displaying in the UITableViewController. Stay tuned for Part 3 of this tutorial series! Have a good night!

Monday, November 16, 2015

Creating an iOS Catalog App: Part 1

In this series of tutorials, I'm going to go through how to make a fully functional Catalog app. If you don't know what a catalog app is, its an app that displays a list of a items that you are able to interact with. I will be using Objective-C for this tutorial.

In this tutorial you will learn:

  • Using Parse databases
  • Creating a UITableViewController
  • Implementing search bars
  • Implementing a filter feature with a custom xib
  • Sharing to Facebook and Twitter
  • Creating a "Wish List" mechanism
  • Using UIWebView to display content
  • Using UIPageControl to create a gallery of images
  • Using iAd banners and interstitial ads
All of these components will be spread out over a course of at least a few different articles. This may seem like a huge task, but this app is actually fairly easy to create. If you want to view an example of the outcome of this tutorial, check my last post.

Today, I will go over creating an app, creating a UITableViewController and creating a Parse account.

To start off this tutorial, we will first need to create an app. I'm assuming anyone viewing this tutorial is using a Mac so if you don't have Xcode, download it from the app store. Otherwise, open Xcode at this time. When you first open Xcode, select "Create a new Xcode Project". After this, you will encounter a few various options. For our purposes, find the section labeled "iOS"and then select "Application". Next, click on "Single View Application". There are a lot of options when creating a new project so feel free to test everything out some time. Maybe I'll even do a tutorial on other options at some point! Now, you have successfully created your first project. Just create a name for your project and save it to where you want.

Now we get into the fun part. Minimize your Xcode tab and open up your internet browser. Go to www.parse.com. From here, make an account for free. Next, press "Create an App" from the menu. Once your here, enter in whatever app name you like. Now, from the parse site, click on "Docs" and click the download button under the iOS symbol. This will download the SDK you need for Parse. After this search "Cocoa Pods" in google. Go to the website and follow the instructions to set up Cocoa Pods on your mac with terminal. Once this is finished, create a pod file for your app using Google's instructions. Then add "pod 'parse'" to your pod file. After that, go into terminal and type "pod install" in the same directory as your project (you can change directories using the cd command). Congratulations! Parse is now a part of your project!

Lets start some real code now. Open up your Xcode project again and click on storyboard. This area is where we'll create most of the interface for the app. To start, you should have one traditional UIViewController in your storyboard. Let's start off by deleting this since we won't need it for this project. We will be using tab controllers and navigation controllers with this tutorial. Start off by dragging a TabBarController into your storyboard. You can search for this on the bottom right hand side of your screen. Once you have the TabBarController in place, delete any views that are connect to it by an arrow. Next, drag a NavigationController to your storyboard and delete any views connected to this also. Now, click on your TabBarController. There should be a small yellow circle at the top that says "Tab Bar Controller" when you hover your mouse over it. Right click this circle and drag the line that appears over to your NavigationController and release. A menu will appear. Under "Relationship Views", select "View Controllers". This will make your tab bar appear on anything that is controller by your navigation controller. Finally, add a UITableViewController to your storyboard. This can also be found in the bottom right hand corner of the Xcode screen. Click on the Navigation Controller and you should see a little yellow circle at the top of it that says "Home". Right click on this circle and drag it over to your UITableViewController. A menu will pop up. Under "Relationship Segue" select "Root View Controller". This will make a navigation bar appear on your table view. Now select your TabBarController again. On the right hand pane find a section that says "View Controller". Make sure that the check box label "Is Initial View Controller" is checked. This will make sure that a view appears when the app is started. If you run the app now you will see a table view with a navigation bar at the top and a tab bar at the bottom.

This is a lot of information to take if you're just a beginner, so take some time to relax and maybe even review what we've gone over today. All in just one tutorial you created an app, started a Parse profile, and create three different views in your application. If anything in this tutorial isn't working for you, feel free to leave a comment. I'll gladly answer any questions. Hopefully, you enjoyed part one of this tutorial series and I hope to have you back for part two. Have a great night!

Sunday, November 15, 2015

Update: My newest weekend project

Hey everyone! I'm sorry that I haven't blogged at all since my first post about starting with iOS development. I'll try to post frequently now. I've been pretty busy because I've been working on multiple iOS app projects while attending school. Let me tell you guys about my newest project that I completely entirely this past weekend.
My newest app is called Fashion Connection. This app helps shopper find great deals on clothing from many different websites. This app covers clothing from sites such as Amazon to sites like Forever 21. In the app, the user is able to browse clothes, buy clothes directly in the app, share their favorite clothing on Facebook or Twitter, and add clothing to their wish list. I believe this is a useful app for shoppers especially during the holiday seasons. I love the interface I developed for this app because I think its very clean and simple. Since I'm a fan of modern design, I love a nice flat UI. Now, I'll get more into the details of this app and how I created it.
To start, I used Objective-C to program my app. I haven't had to much time to really learn Swift so I thought I should stick to Objective-C for this one. This app is comprised of a three different UITableViews and a xib for choosing clothing categories. Each table view cell has a lot of functionality though. On these cells, the user is able to view three different photos of the product, view the product name, view the product price, view the product description, share the product to social media, or add the product to their wish list. This app is really pretty simple, but it has lots of great functionality. In addition, the app uses a Parse backend to store all of the clothing items. I really love Parse because of its simplicity and easy-to-use API. I'd really recommend it for anyone with smaller projects. Finally, to monetize the app I used a combination of iAd banner ads and interstitial ads. Of course, I had to use some Photoshop to create app icons and screenshots.
This was a really fun weekend project for me and let me use my creativity to make some cool UI designs and solve a problem for holiday shoppers. If anyone is interested, I can whip up a quick tutorial on how to create this app for my next blog post. Just post a comment if you're interested. It's a great beginners project that'll really teach you a lot. Anyway, I just wanted to check in and give an update about my newest app. It'll likely be out in a couple of weeks. I'll post some images below.
I'm also still working on Sneaker Connect and will let you guys know the progress of this app in my next post! I've made some pretty awesome updates to the app! Thanks for checking in and have a great week!






Sunday, October 4, 2015

Getting Started with iOS Development (Including learning links!)

At first, learning about iOS development can seem like a daunting task. With other obligations such as school or work, it may seem like you'll never have enough time to start. However, I believe that anyone can learn to code with any type of schedule. I began to learn Objective-C while in school. I even developed and released my first app during the school year. On this post, I'll share my story and give you tips for getting started.

My journey with iOS development started a few years ago. I actually became interested in mobile development because I started to see the insane amount of success many developers were obtaining. I thought that I might as well start learning to code with Objective-C on the side. I took about a year to try learning the new language by viewing tutorials, reading books, and creating my own trial projects. You can actually learn Objective-C much faster, but I liked taking my time. My first project that I actually released was a Flappy Bird clone called Birdlet. I used Sprite Kit within Objective-C to help me create the physics. This project only took me about a month or two including the time I took to create the custom images. My success with this app was fairly limited, but I spent basically no time marketing. I gained around 800 downloads within the first few months of the app's release. During this time I made about $50 just from iAd revenue. When the downloads began to drop steeply, I sold my app for $50 on Flippa.

This was the first of five apps that I ended up releasing to the app store. All together, I have made over $1,000 in profits without doing any marketing for my apps. My point for telling you this story is to prove that anyone can learn to code and even make money from it. I was in school while making all my apps and didn't even spend a minute marketing my apps and had pretty good success. My main advice is really just to get started!

I think that your number one resource when learning to create mobile apps is the internet. This is where I did most of my learning. You can find great articles, tutorials, and videos all about creating apps. There are so many knowledgeable people posting great free content so you should really take advantage of it. In addition, if you want a more advanced understanding of the topic, there are many great books you can find in the bookstore or on your iPad or Kindle. For now, all you need to get started is a mac, some tutorials, and a little perseverance!

Later on in my blog, I'll begin posting some tutorials for iOS development in addition to the projects that I'm working on. If you have any questions or topics you want me to post about, just shoot me a quick email! Thanks for reading and I've provided some great links with information about mobile programming below. Enjoy!


Hopefully this is a good list to get you started! Have fun and good luck!