iOS Programming Recipe 27: Implementing Blocks Part II

Last time we left off in our block discussion I had gone over some of the basics of blocks. How to implement them, call them, and gave a bit of insight on why they are cool. Now, there is one really big benefit to using blocks and that is Grand Central Dispatch. There are of course many other neat things you can do with blocks and we’ll briefly cover a few of those too.

Assumptions

So What Is Grand Central Dispatch?

Today, I’ll use wikipedia as my crutch:

Grand Central Dispatch (GCD) is a technology developed by Apple Inc. to optimize application support for systems with multi-core processors and other symmetric multiprocessing systems.

Ok this doesn’t tell us a whole bunch, but what it does tell us is that it is a technology developed for multi-core processors. All you need to know is GCD is a set of tools that Apple has provided that allow us to perform blocks serially or concurrently on various queues (which map to either the main thread or another GCD managed thread). We also have the option of doing this either synchronously or asynchronously.

[Read more…]

iOS Programming Recipe 26: Using Collection Operators

Assumptions

  • You have strong knowledge of Objective-C and Core Foundation.
  • You have basic understanding of of KVC (Key Value Coding) within the Objective-C language

Many if not all developers use collection objects everyday while developing great apps, but few know about the power of collection operators. As part of KVC (key value coding), collection operators help make many routine tasks simple by eliminating and simplifying code.

Those of you still waiting on the blocks part II article, hang in there, I’ll get to it soon enough. For now I thought I would give ya’ll something short and sweet that is also really useful.

[Read more…]

iOS Programming Recipe 25: Implementing Blocks Part I

Every now and then new stuff comes along that makes our lives easier. One of the best things to come to Objective-C is the advent of blocks. Blocks can simplify callbacks, enumeration, and they have huge benefits in terms of multi-threading. At first, blocks will blow your mind. Block syntax is weird, but once you get the hang of em’ they’re actually kinda easy.

[Read more…]

iOS Programming Recipe 24: Creating a Mask for Clipping Drawings

This Recipe is inspired by a recent problem I ran into and had quite a bit of trouble with it. Basically I wanted to create a shape and fill it with a gradient. Sounds pretty easy huh? well, not quite as we’ll find out shortly. While my particular application required filling a circle with an ellipse, we can create any shape. In essence we’re creating a window (shaped however we want) where the user can see only a portion of the drawing behind it.

[Read more…]

iOS Programming Recipe 23: Audio Recording and Playback

One of the coolest things about the iPhone is it’s ability to handle audio. Since it was born out of an iPod, the iPhone handles audio quite well. In this recipe we’ll explore audio recording and playback. We’ll be creating a simple app that records a sound file and plays it back. We’re basically making a voice memo app that only saves one memo and plays it back.

[Read more…]

iOS Programming Recipe 22: Simplify UIAlertView with Blocks

Assumptions

Getting Started

Have you ever found yourself wanting to present an alertView to the user to get simple yes or no feedback? If you’re anything like me you were very annoyed that you were required to implement the UIAlertView delegate protocol just to handle this simple task.

Is There A Better Way?

[Read more…]

iOS Programming Recipe 21: Photo Filtering Using Core Image

This week I thought I would have a bit of fun and explore image manipulation using Core Image. This sounds like it could be pretty tough, but Apple has actually made this very easy. In this Recipe we’ll be creating a photo filter app that will let you choose a photo or take a photo using the camera and filter it.

Assumptions

  • You know the basics of Xcode, If not, we got you covered: Familiarizing Yourself With Xcode
  • You know how to create outlets and actions using the interace builder
  • You have a developer account and can run this app on hardware, This will be necessary if you want to capture an image using the camera

Setting Up the Project

Setting Up the Framework

Go ahead and start with a single view controller application using storyboards and title it “ImageFilterApp”.

For this App we’ll need to use the Core Image framework. To add a framework select the top level project from the project navigator on the left and scroll down in the main window to “Linked Frameworks and Libraries”. Here you can press the “+” button to add the new framework. When the dialogue opens choose the “CoreImage.framework” and press the “Add” button.

[Read more…]

iOS Programming Recipe 20: Using CAGradientLayer In A Custom View

This recipe will demonstrate how to use CAGradientLayer to add gradients to a custom UIView.

Assumptions

  • You should have basic knowledge of UIView and Core Animation, specifically CALayer.
  • Basic knowledge of autolayout usage in interface builder.

Getting Started

Setting Up A Sample Application
  • Create a new Single View Application in Xcode named GradientViewDemo. Make sure to check Use Automatic Reference Counting and uncheck Use Storyboards. Our demo app will also be iPhone only to keep things simple, but go ahead make a universal app if you like (everything we will do is applicable on both iPhone and iPad),
  • Create a new UIView subclass named NSCBGradientView. We added the NSCB class prefix, because this may be a valuable component to reuse in future projects and the prefix will help avoid name clashing.
  • Next, we need to add QuartzCore to the target. Do so by selecting the project file in the source list on the left, then ensure the GradientViewDemo target has been selected, select the Build Phases tab from the tab bar at the top, expand the Link Binary with Libraries, and finally click the + button in the lower left corner. Search for QuartzCore, and then add it to the target.

[Read more…]

iOS Programming Recipe 19: Using Core Motion to Access Gyro and Accelerometer

One of the coolest things smartphones are capable of now is the ability to sense motion and orientation. The iPhone does this with the use of a 3-axis Accelerometers and Gyroscopes. In this tutorial we’re going to create an app that indicates the current G and speed of rotation. Not exactly a pretty app but still instructional.

Assumptions

  • You have a developer account and have provisioned a device. Unfortunately we can’t simulate this stuff without hardware. Follow the Apple documentation here to get set up.
  • Make Sure you head over our Github page and download the source code. NSCookbook Github Recipe 19
  • You have looked over some of the past tutorials and are comfortable with creating outlets and actions from the interface builder

Setting Up the Interface

Our Interface will be pretty simple as we will be displaying 12 values. We’ll show Max and Current Acceleration and Rotation about the X,Y and Z axis’.

Start with a new single view project titled “GyrosAndAccelerometers” and make sure the storyboards are selected.

Once the new project is created, open up the storyboard and drag 25 Labels onto the view. Twelve of these labels will be our outlets that will display the output data for each axis. Rename the labels and add a button as shown in the image below:

[Read more…]

iOS Programming Recipe 18: Unit Testing With GHUnit & CocoaPods

This Recipe will cover using GHUnit to unit test the Weather Application we developed in Recipe 15: Building A Weather Application. GHUnit is an open source unit testing framework for Mac and iOS that (in my opinion) has capabilities superior to the unit testing capabilities built into Xcode. Many developers have there own philosophy on unit testing and this Recipe will not attempt to define another. We will not be defining unit testing best practices or even go into detail about writing particular tests. This Recipe is purely about getting started with GHUnit and how it can be used in the context of a real application. Oh and did I mention? GHUnit makes writing asynchronous unit tests a breeze!

Assumptions

  • This recipe uses the Weather Application created in Recipe 15: Building A Weather Application, it is highly recommended that you work through or at least familiarize yourself with that recipe before continuing on to this one.
  • Source code for the weather app can be downloaded via GitHub. The revision of the Weather App after Recipe 15 has been tagged recipe-15, make sure to start there.
  • This recipe also relies heavily on CocoaPods, it is recommended you watch NSScreencast’s video tutorial if you are not familiar with CocoaPods.

Getting Started

Download The Starting Application
  • First download the source code for our starting application, which happens to be the Weather App developed in Recipe 15.
  • Refer to Recipe 15¬†for details on setting up a Weather Underground developer account in order to obtain a personal API key. You will need this key in order to access Weather Underground’s services.
  • The Weather App was built using CocoaPods, so after getting the source code you will need to navigate to the project root directory (where the .xcodeproj file lives) and run the following command in terminal. Note this will not work if you have not yet installed CocoaPods, learn about doing so here.

1
$ pod install
  • This will add all of the necessary external dependencies the Weather App needs. It will also create an .xcworkspace file which you will need to open when accessing this project (not the .xcodeproj file).
  • Add your person API key for Weather Underground to WeatherAPIKey.h, then build & run the application. If everything has been done right you should now have a functioning weather application!

[Read more…]

css.php
Privacy Policy