News/Rumor: Apple to introduce new XCode environment later this year

XCodeLogoAccording to our sister web site AppleScoop.com going on a tip from 9to5Mac.com, Apple is said to be redoing its XCode developers environment to be introduced later this year.  The update could see a major revamp of the look and its testing tools.

No other information was available.

iOS: Considering writing iOS apps? Here’s what you need

MacComputerEver since I started writing iOS apps, I’ve seen other programmers inquire about how they can get started with writing iOS and/or Objective-C apps.

From what I could find, there isn’t a real YES or NO answers to those what seems like basic questions for inquiring minds – until now.

I will tackle the most asked questions that I could find.  If you have any others, please feel free to ask them in the comments section below.

Q: What do I need to develop iOS apps?
A: You’ll need a Mac computer.  Any recent Mac will do – even the Mac Mini.

Q: Can I develop iOS apps on a Windows computer?
A: No.  Developers must use Apple’s development environment – Xcode.

Q: How much is it to become an iOS developer?
A: $99.00 per year, which includes access to all developer’s documentation, libraries, and more.

Q: What books can I get to learn more about Objective-C programming?
A: I use Amazon.com for all of my books.  Click here to see what they have.

Q: Are their any free resources to learn Obj-C programming?
A: Yes their are.  Search Google.com to find them.

Q: Are there any online resources I can use to learn?
A: Yes.  YouTube is a fantastic resource.  I also recommend this site as well.

I hope to be expanding the above sometime soon.  Please keep those questions coming.

Obj-C: How to do basic math

MathTestMath has not been one of my strong points – even with the computer helping me throughout the years.  So, when I had to learn how to format a math problem using languages such as Objective-C, I was not a happy camper.

But formulating a math problem for the computer to see, figure out, and spit the answer out is easier then I thought it would be, especially for a math dunce like myself.

This article will cover the basics of how to give the computer a problem so it can give you a result.

For those of you who are using Xcode, this will be a simple program that will output the result to a NSLOG and print the answer to the console and everything will be done in the .m file.  Create a new single screen application and name it MATHTEST or something like that.

Here is the entire code.  I’ll explain what’s going on after….

    int x = 15;

    int y = 23;

    int answer = 0;

    answer = (x + y);

    NSLog(@”%d”,answer);

 Okay, let’s run down what’s going on here:

1.  We initialize the “X” variable to hold the number “15”.
2.  We initialize the “Y” variable to hold the number “23”.
3.  We initialize the “answer” variable with the value of “0”  *
4.  Let the value of answer add the
 and values (in this case, X = 15 and Y = 23).
5.  Now print the value of answer to the console (which should be 38).

That’s it….Happy coding.

Learn how to code iOS from your own home/office

iOS-SDKLogoI don’t usually do this, but this offer seems to be la-git.  If I am wrong, then please forgive me.

A web site called (strangely enough) “App School” is offering basic courses on how to code in iOS for as little as $125.00.

According to the information:

Do you have an idea for an app but don’t know how to build it?

Learn how to write your first app for iPhone or iPad using Objective-C, the primary language for Apple iOS Platform. This class is designed for absolute beginners, no programming experience is required.

The class will touch upon the topics explained below:

  • Intro to Object-Oriented Programming: Learn the basics of programming and how to use virtual objects to design and build applications.
  • Model View Controller: Design your application to work in the most efficient manner possible, separate Data, View, and Logic classes.
  • Objective-C 101: Grasp a few simple principles of the grammar and syntax.
  • Making Your First App: Experience step-by-step how to build a Tip Calculator.

The class will be four hours, from 10am to 2pm. There will be an break at Noon for a break and lunch.

What’s Included

  • 4 Hours of Lecture with Online Slide Deck
  • 3 Class Exercises with Source Code
  • Complimentary Coffee & Snacks
  • Wifi & Power Provided

Required Materials

  • Macbook with Mac OSX Lion or Mountain Lion
  • XCode 4.5 or higher installed.

You can download Xcode from the Mac App Store.

Terms

  • No refunds can be provided after purchase, we can provide a credit to a future class with at least 24 hours notice before the original class begins. Course dates are subject to change due to enrollment.

For more information (including the teacher’s bio), click here.

If anyone has taken any courses from the above web site, please let us know in our Discussion Forums below.  Thanks!

News: Apple updates XCODE to Version 4.6

iOSLogoOn Monday, Apple released an update for its iOS operating system and its XCode Developer’s tools.

iOS 6.1 is now available and can be gotten by going into Settings > General > Update Software on the device.  The update takes about 15-20 minutes to complete and cannot be interrupted.

The company also updated its XCode development environment to version 4.6 to help handle the new version of iOS.  This update can be gotten from the Mac App Store on a Mac.

iOS: How to take a screen shot and save it to a file inside your app

iOSLogoFrom time to time, we write applications that need to take a screen shot of the user’s screen and save it to a file inside our app.  Sure, they can use the HOME and POWER buttons to do the same thing, but what if you want to just save a part of the user’s screen to a file?

Fortunately, iOS makes it easy to do.  The below code takes a screen shot when a user taps a button, and then saves it to a file on the device.

1.  Name the project: screenshotexample and use a single view.

2.  Next, go out on the web (I use Google Imageshttp://images.google.com) and select any image.

3.  Now save the image to the Desktop, and then go back into Xcode.

4.  Add the image to the project (Right click on the project name, and then select the ADD FILES TO PROJE CT command).

5.  Select the image from the desktop.
-> Make sure the Destination field has a check mark in it, to add it to the project’s tree.

Since we want a user to tap a button so they can save the screen shot to a file, go in to Interface Builder and drag a Navigation Bar and button to the canvas.  Now, search for and then drag a button on to the Navigation Bar.  Name the button “Take Screen Shot.

Now, search for an UIImageView and drag/drop it to the canvas.  Click on the imageView, and select the Attributes Inspector (on the upper-right).

In the ImageView – image – field, use the drop down box to find and insert the image that you added to the project earlier.  It should now appear on the canvas.

Save and exit back in to XCode.

Now, go into the .h file and type in:

-(IBAction)btnSave:(id)sender;

This is the button that will trigger the save when a user taps a button.

Now, go into the .m file.  We first have to tell the iOS device to “look” in the /Documents/ folder to read/write files:

// Make device ‘look for’ its Document’s Directory:

-(NSString *)dataFilePath {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

NSString *documentsDirectory = [paths objectAtIndex:0];

return [documentsDirectory stringByAppendingPathComponent:@”filename.png”];

}

Where filename is, is where you’d make up a filename to hold the data on the iOS device.

Now, let’s put in our button so that when a user taps it, it will save the photo to the filename you specified above.

-(IBAction)btnSave:(id)sender

{

// Save to File:

UIGraphicsBeginImageContext(self.view.bounds.size);

[drawImage.layer renderInContext:UIGraphicsGetCurrentContext()];

    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    NSData *data = UIImagePNGRepresentation(image);

    [data writeToFile:@”filename” atomically:YES];

 }

1.  The above code takes the screen, sizes it to the bounds of the screen.

2.  It draws the layer that the photo is on.

3.  Since we’re saving an image to the file, the UIImage is used.

4.  The device then goes to the end of the image and preps it to be written to the file.

5.  The NSData tells the device that its saving the data of the image.

6.  We’re writing a PNG graphics file to storage.

7.  Finally, the device writes the data to its /Documents/ Folder within the app’s sandbox.

BONUS TIP:

Lets suppose we wanted to save the photo to the Photo Album itself?  Use the below code:

 // Save to Photo Album:

    CGRect screenRect = [[UIScreen mainScreen] bounds];

UIGraphicsBeginImageContext(screenRect.size);

CGContextRef ctx = UIGraphicsGetCurrentContext();

[[UIColor blackColor] set];

CGContextFillRect(ctx, screenRect);

 [self.view.layer renderInContext:ctx];

 UIImage *image1 = UIGraphicsGetImageFromCurrentImageContext();

UIImageWriteToSavedPhotosAlbum(image1, nil, nil, nil);

UIGraphicsEndImageContext();

    NSString *title = @”Imaged Saved to Device“;

    NSString *msg = @”This image has been saved to your Photo Album”;

    NSString *button = @”OK”;

    UIAlertView *alert = [[UIAlertView alloc]

                          initWithTitle:title

                          message:msg

                          delegate:self

                          cancelButtonTitle:button

                          otherButtonTitles:nil];

    [alert show];

    [alert release];

    [title release];

    [button release];

 That’s it….Happy Coding!

iOS: The difference between an IBAction and an IBOutlet

iOSLogoAs I was learning Objective-C to make iOS apps, one of the areas that got me confused was knowing the difference between what was an IBAction and an IBOutlet.  Although simple now, this topic seems to also confuse a lot of new iOS programmers as well.

To put it in English terms so that everyone can understand what they are:

IBAction:
Defines what a user will do when they take “action” inside your app – such as tap on a button.

IBOutlet:
An IBOutlet defines what the app may show to a user – such as a message inside of a UILabel.

Examples:

-(IBAction)btnSave:(id)sender;

IBOutlet UILabel *showMessage;

Also remember, that the IB means that you’re going to be making connections inside of Interface Builder – whether it is an Action or an Outlet.

I’ll post a programming example of the above commands sometime next week – stay tuned!

Happy Coding!

How to develop for Windows or Windows Phone on a Mac

VirtualBoxLogoIf you want to develop apps for Android or iOS, then a Mac will do just fine.  The Android programming language has a GUI called Eclipse that will let one compile, test, and even upload the app to Google’s Play Store.

iOS has Xcode that programmers can use to develop Mac and iOS programs.

But what if you want to develop for the Windows platform?  One does not want to spend big bucks getting a Windows computer just to make Windows or Windows Phone apps.

Fortunately, their is a way.  You’ll have to obtain a full version of Windows though.

You can run the Windows environment inside of what is known as a “Virtual Window.”  To do this, you’ll need a Mac application that puts a virtual drive on your Mac for Windows to reside in.

Unlike what these companies would lead you to believe, you do not have to purchase the program.  You can download a program called VirtualBox from here.

Once the program is installed, follow the installation instructions.  Then, put the Windows installation DVD in your DVD drive.  Launch VirtualBox, and follow the screens to configure the “Virtual Drive” for the version of Windows you’re installing.

After Windows installs, go in to the operating system and download/install the required Visual Studio files as if you were on a “real” Windows machine.

Happy Coding!

iOS: The differences between the .h and .m project files

When I was first learning how to code for iOS devices, one thing got me confused: “What the heck are the .h and .m files?”  This article will tackle that question, and also answer the ultimate question: “Where do a put what when?”

The .h (heading) file is where you ‘prep the program’ and tell it all of the variables and delegates that will be used throughout an application.  This is also where you can #import any Frameworks that you may need during an application’s run.  For example, you may want to have:

#import <UIKit/UIKit.h>

To use all of the features that would be in the UIKit framework.

The .h file can also be used to prep the application to assign a UILabel to a variable.  Like so:

UILabel *fullName;

… and so on …

The .m file is where the bulk of your application’s code will go.  Code such as:

-(void)viewDidLoad
{
// code goes here.

}

In any of our sample code that you may find, I will always specify what code goes in what file.  This is how I learned and know how hard it was to get that straight by the time I was ready to write my first iOS app.

 

iOS: How to go from one viewController to another

Although this topic may seem basic, a lot of programmers (including me) get stuck on how to go from one view to another by code.  Sure, one can use StoryBoarding as a way around it, but that only works with apps from iOS 5 on up.  You have to keep in mind that some of the end users are still running older versions of iOS.  I met someone that was still using iOS 3.

In order for you to know what to use, you first have to decide what view your coming from.  If it is a tableView, you use one option.  If it’s a standard view, then you use another.  A standard view has many more transition options: from non to a complete flip animation.  I have used several and feel it helps keep the user‘s attention.

I will go over the two options below.

First, let’s go over going from one viewController to another:

ViewController *controller = [[ViewController alloc] initWithNibName:@”ViewController” bundle:nil];

controller.modalTransitionStyle =  UIModalTransitionStyleCrossDissolve;

[self presentModalViewController:controller animated:YES];

[controller release];

The above code seems simple enough. This block of code is contained inside a -(IBAction) code block.  When a user taps on a button, the code will activate, the transition will begin, and they will be taken to the viewController that’s specified in the code block.

Now, let’s see how to go from a tableView option to a standard viewController:

if (indexPath.row == 0) {

aViewController *AVC = [[aViewController alloc] init];

[self.navigationController pushViewController:AVC animated:YES];

[AVC release];

This is how I take the user from a tableView option to a standard viewController if the tableView only has a few options on it.

Again, the code is simple enough.  If the end user taps tableView row 0 (the very first cell) then go to a viewController that I specify within the first command in the second line of the code block.

In a later article, I will show you how to make the iOS device decide what cell the user tapped on and go to the correct viewController.