Get In Touch
This form does not yet contain any fields.

    Monday
    Nov072011

    Text Input in UIAlertViews

     

    iOS developers have been hacking away at trying to find a good solution for presenting users with a text input on a popup.  Some developers have been successful at getting this to work, but it has never been a pretty or simple solution. iOS 5 provides several simple solutions to this problem with the new UIAlertViewStyles that are now available.

    UIAlertViewStylePlainTextInput is the most simplistic of the new styles and presents a standard UIAlertView with an embeded UITextField.  In order to receive the text input into this UITextField, you must implement the UIAlertViewDelegate method didDismissWithButtonIndex.  A simple example implementation...

    UIAlertViewStyleLoginAndPasswordInput works exactly the same except you receive two text fields for input, the username and password.  Again you can get these contents form the UIAlertViewDelegate method didDismissWithButtonIndex, with the login field having a index of 0 and the password field having an index of 1.

    Tuesday
    Oct252011

    Simple ARC explanation

    Dont worry about it.  Memory management is one of the hardest concepts for new developers to wrap their heads around. With iOS 5 and ARC this issue is mitigated.

    Developers can alloc and init objects like they normally would, but now the compiler takes care of cleaning up memory when the object is no longer needed.  In other words, stop worrying about it, you no longer need to be obsessive about writting a release everytime you write alloc. In fact you can remove dealloc functions from your code altogether.  This even works for Blocks, stop worrying about including the autorelease.

    There is even an automated way to convert old code to ARC, within Xcode go to Edit --> Refactor --> Convert to Objective-C ARC. This will walk you through step by step how to convert your code and even do a precheck to make sure nothing will break.

    There are also compiler flags you can provide to opt-in or opt-out of ARC.  This is incredibly useful if you are using pre-ARC libraries, so you can have ARC on the rest of the project and use retain/release on the older code.

    Opt-in Flag = -fobjc-arc

    Opt-out Flag = -fno-objc-arc

     

    Apple's initial baselines also are showing that there is a healthy performance gain of 2.5x faster than a normal retain/release.  It is 6x faster than autorelease as well.

    Stop Worrying. Start Developing.

    Thursday
    May192011

    iOS Twitter Search Tutorial

    One of the most popular blog entries at RemarkablePixels is an entry I wrote back in December called Parsing JSON in iOS the right way.  Very frequently when people are asking me about parsing JSON they are usually talking about something related to Twitter, commonly the Twitter Search API.

    The Twitter Search API is a very straightforward and powerful API, provided by Twitter to allow developers to get realtime search results.  The resultset from these queries is very robust and contains lots of useful information besides just the text and username of a tweet.  This is presented back to the developer in a JSON wrapper for easy parsing.  Luckily iOS has a great framework for handling JSON data and asynchronous HTTP requests.

    Lets get started...The project and source code is available on GitHub if you would rather see everything together. Otherwise follow along below...

    Create a new project in XCode, a View-based App.

    Download the JSON framework for iOS on GitHub - Here 

    Drag the JSON files into your project.

    This simple example will include 3 pieces. A view controller to control the flow, a Search Twitter class, and a View to present the results.

    Lets start with the heavy lifting first, the Search Twitter class.  Add a new Objective C class to your project and name it SearchTwitter.  

    We will first populate our header with one instance variable and one method we need to search twitter.

    The Search Twitter class will take one input, an NSString from our first view controller, which is the term that the user would like to search twitter for.  We will also need to sanitize this input to substitute any white space in the search term or other characters that are common, but will break the API call.  This is easily handled with a couple of NSRegularExpressions and stringByReplacingMatchesInString functions.  

    Once we have passed through our sanitizer, we then need to create a URL string for the Twitter Search API which will include our search term and the number of results we would like to receive.  We then take this NSString and create an NSURL object which we can use in our next step to retreive the results of this call.

    We then make an asynchronous call with the NSURL object created to start retreiving the results of the search.

    Now that our search is in flight, we need a way to catch the JSON results as they come back.  As I wrote previously, you cannot just take the first set of data that comes back, otherwise you can end up an invalid JSON resultset.  To handle this we will implement the NSURLConnection delegate methods, connection didReceiveData and connectionDidFinishLoading.

    With connection didReceiveData we need to allocate our tweetBlob on the first pass, and then on every subsequent call, append the data to this blob.

    Once all the data has finished downloading the connectionDidFinishLoading will be called.  In here we will want to take the completed blob of JSON tweets and put it through the JSON parser.  We also need a way to signal back to our view that the request has completed, successfully or unsuccessfully.  To do this we will send a notification using NSNotificationCenter, and then setup a listener on our view to receive the dictionary of results.

     Now that we have finished the implementation of the searchTwitter class, we can move on to our view controller and view.

    The view controller is pretty straightforward, we will create three instance variables, one for our SearchTwitter class, and two IBOutlets for our search view.

    The implementation consists of three pieces, the allocation of our SearchTwitter class, the handling of receiving the search term, and then pushing our results view onto the view stack.

     

    The last piece of the puzzle is the tableview that will present our results.  The header file is one simple piece an NSMutableArray that we will use to populate the rows in our table view.

    Within the implementation we need to now setup the NSNotification center to listen for the tweets results, and then handle the data that comes in.

    The last step is to implement the tableview methods to populate our data in the cells.

     

    Thats it we are done.  You should now have a simple example of how to implement the Twitter Search API in iOS.  

    Download this example project on GitHub.

    Tuesday
    Mar222011

    Chameleon - UIKit for OS X

    With the success of Apps on the Mac App store, such as Pixelmator, many devs are sizing up how they can port their existing apps over to OS X.  Today with the release of Chameleon, developers now have the ability to port their existing iOS code directly to OS X.  Chameleon is a byproduct from IconFactory, as they created this framework while porting Twitterific to allow for a direct port from iOS into OS X.  

    Chameleon is definately a work in progress, with 60% of UIKit having been ported so far.  There are some notable missing parts of UIKit, such as the UITabBar and UISwitch.

    Historically the mantra of write once, run everywhere has yielded some poor products, but I'm interested to see how I can leverage Chameleon and specifically how well that will perform on OS X.

    Chameleon on GitHub

    Support Chameleon via Donation

    Sunday
    Mar062011

    Chrome extensions for iOS Developers

    I switched from Safari to Chrome a few months ago and have enjoyed the speed improvements and the many useful extensions.  Although being an iOS developer there are some things that do not work as well in Chrome as they did in Safari.

    The first is iTunes Connect.  When accessing the Sales reports in iTunes Connect from Chrome, you will see the loading spinner, just spin and spin.  After a few refreshes you can finally get the report to come through.  This can be frustrating as this is the only source of information for developers on how many apps have been downloaded.  Luckily there is an extension called iTunes Connect fix which fixes this problem.  Just install this extension and the reports load immediately just like Safari.

    The second is searching for developer documentation within Chrome.  There is a great shortcut extension that will let you search directly within Chrome for content within the iOS and Mac documentation.  AppleDocsChrome will help speed up your search results and makes finding documentation content even easier.

    Another great extension is the AppStore Instant Extension which allows you to get Google Instant like search results from the AppStore.