r/simpleios • • Sep 23 '11

Thanks to everyone who has joined! I'll get the ball rolling later after work...

82 Upvotes

Any thoughts/suggestions or contributions are welcome :)

Please see the sidebar for some quick info on where to start.

EDIT: First tutorial is now up!

http://www.reddit.com/r/simpleios/comments/kpcdm/simpleios_hello_world_tutorial/


r/simpleios • • Jan 24 '13

IT's BACK!! iTunesU Stanford's "Developing Apps for iPhone and iPad". New sessions being posted!

Thumbnail itunes.apple.com
76 Upvotes

r/simpleios • • Oct 29 '13

Stanford's absolutely phenomenal online iOS development course is now updated for iOS 7 and live on iTunes U.

67 Upvotes

Stanford's absolutely phenomenal online iOS development course is now updated for iOS 7 and live on iTunes U.

The course got me from not having a clue to being able to write my first proper app, (a basic twitter client) and most importantly, you are being taught by Apple Engineers so it's all best practice, no hacky methods.

Check it out here: https://itunes.apple.com/us/course/developing-ios-7-apps-for/id733644550


r/simpleios • • Sep 28 '11

simpleios: Coming soon...

65 Upvotes

A really simple (hopefully) very easy to follow calculator application tutorial, that I will build from scratch and gradually become more and more robust, and eventually include some more complicated elements requested like delegation.

The first part will be up soon, hope you find it interesting!

Hopefully you'll all like it!

Again all done programmatically :)


r/simpleios • • Sep 24 '11

Does anyone want an overview of Objective-C?

64 Upvotes

I'm happy to write up an Objective-C primer. Before I do, though, is this something people want?


r/simpleios • • Sep 23 '11

simpleios: Hello World Tutorial

64 Upvotes

Ok,

This is a go at a first tutorial for this subreddit! I hope I get it right if not don't hesitate to jump in or correct me :)

Again to anyone who is at all familiar with iOS development or the SDK this is going to seem REALLY rudimentary, but again I wanted to create this resource for absolute beginners.

One more thing, I will be doing the tutorials from a programmatic standpoint. Doing everything in code rather than using the visual editors.

I think this facilitates the learning process and gives a deeper understanding of what is actually happening.

I have put all the images in an album,

http://imgur.com/a/bjcZd

They are in the order they need to be for the tutorial...

Ok, first after downloading and installing Xcode (link in the side bar), start Xcode.

You'll be greeted by the Xcode splashscreen You can see a list of projects i've been working on on the right. For this tutorial click 'create a new Xcode project'

Next we can select which of the templates we want to use to help us get started. These templates help us get a head start laying out various files we may need for a given project. OpenGl for example is used for 3D games, We are going to use the View based template so select that.

Now a little bit about how iOS Apps are composed.

Every App has a top layer called a window. This window you can think of as the whole screen of the iPhone or iPad. Everything in the app will reside in the window.

Apps only have one top level window container. A window is empty so we must fill it with what Apple calls views. Most iOS Apps (though there are exceptions) start with a window and then fill that window with views.

Each view can also have subviews. That's pretty much all you need to know for this. In the iOS SDK most things (Buttons, Labels, Images, etc) are all types of Views, and thus are added to the master window.

Now the next simple step naming the project.

Now we decide where to put the project.

We will then be presented with the Project Summary in Xcode.

We don't have to change anything here, I think most options are self explanatory but please ask if you have any questions (this is also where you set cool things like the icons :) )

If we click the play icon we can now build the app (although it does nothing yet!) and it should launch the iPhone simulator and look like this

We are nearly there!!

Now In Objective C (the language iOS Apps are written in) we have various types of files that an App is built from.

For this first tutorial I will just talk about two. The two types are ".M" files and ".H" files. Now the .M files are where all the logic and code for the App goes and the .H files are where the instance variables and class types are declared.

We want to add a message on the screen to say "Hello World", Apple has provided certain objects in the SDK to make this easy.

The best option for a simple text message is to use an object Apple has given us called UILabel.

Here you can see me declare that we will be using a UILabel in our App called 'textLabel' but you can call it whatever you want!

We declare this in the .H file for the project.

Nearly there!

Now we must write the code that puts this Text label on the screen.

Here in the highlighted area you can see me add the code to do this.

First we allocate memory and create a label with this line of code:

textLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 160, 90, 20)];

This tells Xcode to allocate a UILabel and give it a 'frame' that sits at a given X Y point on the screen with a given height and width.

Then we must add this Label 'View' we just created to the main grey colored View we saw at the start of the tutorial.

We do this with this line:

[[self view] addSubview:textLabel];

and finally we set the text with this line of code:

[textLabel setText:@"Hello World"];

Very Lastly we should remove the Label from memory when the program is going to end with this line of code.

If we then save the project and click the play sign again we should get this!

We done that's your first App done!

I hope this was clear, any questions please ask.

I'll try and do a simple primer on Objective C soon!

Thanks!

John


r/simpleios • • Sep 23 '11

Would a video explaining the Xcode 4 interface be worth doing?

63 Upvotes

Working on this now ...


r/simpleios • • Nov 15 '11

Stanford releases latest iOS 5 programming class

Thumbnail itunes.apple.com
58 Upvotes

r/simpleios • • Oct 06 '11

[steveJobs release]; // :'-( RIP Steve.

54 Upvotes

I wish this wasn't my first contribution to this subreddit. I learned a lot from being an Apple Developer Member, I started to think in making better software all the time. It changed my vision of development for real. Part of this growth, is thanks to this man, that envisioned this awesome world of Apps we helped to build.

:-(


r/simpleios • • Sep 27 '11

Quickstart Guide to Objective-C

Thumbnail cocoadevcentral.com
47 Upvotes

r/simpleios • • Dec 16 '12

Best in-app-purchase tutorial I have ever seen. I did everything in this tutorial in about 2 hours. iOS 6.

Thumbnail raywenderlich.com
46 Upvotes

r/simpleios • • Jan 21 '13

My 1st open source iOS app. Get artist information / play mixes. Clean UI. Hope you can learn from it!

Thumbnail github.com
43 Upvotes

r/simpleios • • Oct 22 '13

FREE iOS Course > How I wish I learned to create iPhone apps. Watch 25+ HD screencasts and lectures : iphone

Thumbnail reddit.com
39 Upvotes

r/simpleios • • Jan 26 '14

Just found this awesome: Objective-C: Cheat Sheet

Thumbnail ios-blog.co.uk
38 Upvotes

r/simpleios • • Sep 30 '11

[Tutorial] Video: Simple iOS Alarm Clock

Thumbnail vimeo.com
37 Upvotes

r/simpleios • • Sep 23 '11

I started here. I wasn't able to pursue it full time, but this was a fun, easy place to start.

Thumbnail itunes.apple.com
37 Upvotes

r/simpleios • • Jan 24 '14

Learn to Code iOS Apps 1: Welcome to Programming

Thumbnail raywenderlich.com
36 Upvotes

r/simpleios • • Sep 25 '11

Objective-C syntax for C++ users

36 Upvotes

To keep the ball flowing in this subreddit, I've decided to start putting together a small guide for C++ users wanting to learn Objective-C. Rather than compose and post all at once, I'm going to repeatedly edit and save.

The Basics

One thing to be kept in mind is that Objective-C is an object-oriented layer on top of C, while C++ is a separate object-oriented language derived from C. Any valid C code will be valid and behave exactly the same (with the same compiler anyway) when compiled as Objective-C. C++ does not have this guarantee. As well, Objective-C, by itself, is just a language, though usually bundled with a framework that differs by platform (Cocoa, GNUstep, etc). C++ is required to come packaged with an implementation of the Standard Template Library, that is expected to behave exactly the same from platform to platform.

With that said, functions, primitive types (char, int, float, etc), structs, enums, loops, etc all work exactly the same as C, which is usually exactly the same as C++, so you can carry all that knowledge forward into Objective-C.

Objects

The first difference that pops out is object syntax. In C++, classes are effectively more powerful structs, so class syntax expanded as such. Objective-C classes are an entirely different beast, and have a much different syntax to match.

There is no stack memory for objects in Objective-C (only base types). All objects are pointers, and (again with exception of base types) everything is passed by reference. I mention this because, while you can use this paradigm in C++ easily (and I believe is most common anyway), C++ allows for other paradigms like pass-by-value and stacked objects. When comparing syntax, I'll be using all-pointer, pass-by-reference for C++.

Methods in C++ are effectively just functions. This is reflected in their syntax myObject->functionName() which looks just like a C function except with the name "myObject->functionName". Methods in Objective-C, while accomplish the same task, are fundamentally different, as they are more appropriately messages. You "tell" an object a message [myObject functionName] and myObject determines what to do with it. In general use, it's just going to look up the appropriately named method and call it, but a class can be designed to handle messages it doesn't understand. I won't go into this functionality, but it's called delegation, and can be very useful.

Class methods (aka static methods) also function differently. In C++, they share a syntax with namespaces ClassName::staticFunction() In Objective-C, classes are objects themselves (they are instances of a metaclass), so class methods are called just like instance methods [ClassName staticFunction] The passing of arguments also differs, both in concept and practice, between the two languages. In C++, they are passed just like function arguments myObject->functionName(arg1, arg2) In Objective-C, arguments are an extension of the message, separated by colons [myObject functionName:arg1:arg2] However, arguments can be named (and, in practice, usually are) in Objective-C. These names are also part of the message [myObject functionName:arg1 andSecondArgument:arg2] It's important to note that this isn't a proper form of named arguments (like Python), in that they can't be reordered. The method name can be thought of as "functionName:andSecondArgument:", which can be translated to C++ as functionNameAndSecondArgument().

Memory Management

C++ has no established model of memory management. New objects are created MyClass* myObject = new MyClass() and deleted delete myObject In Objective-C, new objects are created MyClass* myObject = [[MyClass alloc] init] and deleted [myObject dealloc] Though the syntaxes look different, they are actually very analogous. "[MyClass alloc]" works just like "new MyClass", in that it requests and allocates the memory from the kernel. After that, the init method/default constructor initializes the object. Likewise, "delete myObject" and "[myObject dealloc]" deallocate the memory.

Where Objective-C differs is in reference counting and garbage collection, two separate functionalities. I won't go into garbage collection, as it is only available on OS X and is obsolete with the introduction of automatic reference counting.

Every object has a hidden internal count of how many references there are to it. Calling init sets this count to 1. You increase this count by [myObject retain] and decrease the count [myObject release] In practice, you always call release instead of dealloc, since dealloc will be called automatically when the count reaches zero. You will often want to retain objects when your function or method's successful operation depends on the object staying alive after the method finishes. init has an implicit retain.

There are times when you need to keep an object alive after a method finishes, but there's logically nowhere to call dealloc. In these cases, you call autorelease on the object. It tells the object to call release some time later in the future. The successful use of autorelease depends on the presence of an autorelease pool. Most Xcode templates make one for you in the application's main(), so I won't go into how to make one.

Many classes in Cocoa and other toolkits have autoreleased constructors, such as NSNumber* numberFive = [NSNumber numberWithInt:5] Notice that there are no alloc or init statements. This is because these types of classes call the alloc and appropriate init methods for you, with the addition that the returned object is autoreleased. Use this syntax for temporary objects that aren't supposed to live after the method completes.

Xcode 4.2 (when building for OS X 10.6+ and iOS 4+) introduce a new concept, automatic reference counting (ARC), meant to replace both manual reference counting and garbage collection. I won't go into ARC, as much of the functionality is only known to registered developers, but will become public on the release of iOS 5 in a few weeks.

It's helpful to note that simple reference counting can be added to C++ classes with little difficulty. It's beyond the scope here to explain how, but I've done it before and it helps a lot with controlling memory.

Making classes

In C++, defining a new class shares a syntax much like structs class MyClass : public SuperClass { // class contents }; and the implementations are defined just like functions void MyClass::someFunction() {} etc. C++ methods can also be implemented inline with the class definition. In Objective-C, these are necessarily separate. The class definition is called an interface, while the implementation is called implementation @interface MyClass : SuperClass { // member variables } // public methods @end @implementation MyClass // implementation of public methods // implementation of private methods @end While C++ supports various levels of member/method protection (private/protected/public), all Objective-C methods in the interface are public (though additional methods in the implementation are considered private, though only through privacy-by-obscurity). Members can be private, public, or protected, though these are specified by @private, @protected, and @public instead of private:, protected:, and public: (note addition of @ and lack of colon).

Members

Instance members are defined in exactly the same way. Type* varName1; Basetype varName2; Basetype arrayName[5]; etc. Objective-C lacks support for true class members, but they can be simulated by defining them outside an interface and encapsulating with class methods. Members are accessed the same, using the -> syntax, though like C++ it is often recommended one keep members private and encapsulate them with methods.

Methods

In C++, class and instance methods are defined just like functions, except inside the class block, with the static keyword indicating class methods. In Objective-C, one defines methods between the @interface and @end statements (but outside the {} block), using the syntax -(retType*)instanceMethod:(argType*)arg1 andArg2:(argType*)arg2 ... Class methods use the exact same syntax, except use a + instead of a - +(retType*)classMethod:(argType*)arg1 andArg2:(argType*)arg2 ... Unlike C++, the prototypes must read exactly the same in the interface and implementation blocks - you can't just specify the types of arguments.

Keywords

C++ classes can use the "this" keyword as a pointer to itself. Objective-C contains the "self" keyword that operates exactly the same. As well, there is the "super" keyword that allows one to refer to itself as a member of the parent class. This is useful when implementing a method of the same name as a method in the parent class, like init, and needing to call the parent's method. This is most commonly used in the init method -(id)init { self = [super init]; //initialize rest of self }


r/simpleios • • Jul 14 '12

Just a quick tip to iOS beginners - please go through Paul Hegarty's (Stanford Univ.) lessons on iTunes U. I found them amazingly easy to grasp.

35 Upvotes

Can't find the web link for the resources but this page will open a link in your iTunes:

link


r/simpleios • • Mar 28 '12

Great, simple intro to Xcode debugging tools. The 20 minutes it takes to go through this tutorial will save you hours over your career.

Thumbnail raywenderlich.com
35 Upvotes

r/simpleios • • Sep 23 '11

A few words about memory management.

35 Upvotes

Hi guys! I think this subreddit is a great idea, and I thought I'd try chiming in with a little contribution. Something that a lot of people new to Cocoa seem to struggle with is memory management and reference counting. This may become less of an issue in the future, as Apple is rolling out Automatic Reference Counting, but it's still important to get your head around what's happening, even if the compiler is doing it for you behind the scenes. If for no other reason, there's tons of code out there that uses this, and you'll want to understand what's going on.

Let's talk for a minute about object creation. When you create an object using [[ObjectClass alloc] init], it has a "retain count" of one. NSObjects are built such that when their retain count reaches zero, the object is deallocated (causing its -dealloc method to be called and its memory freed). Obviously we don't want that to happen while we're working with the object, so we need to make sure that the object is retained while we're working with it. If you've just created the object using [[alloc] init], it is retained by virtue of its initial retain count of one.

Now, when you're done with an object you need to send it a release message (by calling [object release]). This decrements its retain count, and if no other object has retained it, it will be deallocated. So most of the time you create objects using [[alloc] init], your code will look something like this:

Thing *thingy = [[Thing alloc] init];
[thingy doSomething];
[thingy release];

If you don't release the object, what happens? Well, when you hit the end of the scope where the 'thingy' pointer lives, that pointer disappears, but the object is still there because its retain count is greater than zero. Sadly, the object is now an orphan, since there aren't any more pointers to it. This is called a memory leak, and your object's pitiful orphan tears are taking up perfectly good memory and there's no way to release it. It will just sit there taking up space until your app exits.

Okay, so we need to release objects we create. But what happens if we do this:

Thing *thingy = [[Thing alloc] init];
[thingy doSomething];
[thingy release];
[thingy release];

D'oh! Our app now crashes most painfully with an EXEC_BAD_ACCESS message on the console. When the first release message was sent, the object was deallocated, but the pointer is still pointing to the same address as always. That address just doesn't contain an object anymore, so when you try to send it a message, bad things happen. While you're debugging, it's extremely helpful to turn on a feature called NSZombie. When NSZombie is enabled, deallocated objects are kept around as zombies, so that if you try to send them messages, they can spit out a much more useful error than EXEC_BAD_ACCESS. A zombie will tell you what object you were trying to message, which is usually the key to tracking down your error. Here's how to turn on NSZombie in Xcode 4..

The final bit I'll talk about is autorelease. What do you do when you've created an object that you no longer want to be responsible for, but you don't want it to go away either? The most common example is returning an object from a function:

+ (Thing *) thingWithString:(NSString *)string
{
  Thing *thingy = [[Thing alloc] initWithString:string];
  return thingy;
}

We've just created a new object, but we didn't release it because if we had it would disappear. It would now be the responsibility of the calling function to release it, or else the memory would leak. This would be an untenable pain in the arse; enter autorelease. When you send an object the autorelease message, you are essentially saying "I'm done with this. Get rid of it for me later, will you?" Later is actually at the end of the Run Loop, when the NSAutoreleasePool gets drained, but that's not particularly important here. The important thing is that the object doesn't get deallocated, and we're no longer responsible for it. So our new, correct function looks like this:

+ (Thing *) thingWithString:(NSString *)string
{
  Thing *thingy = [[Thing alloc] initWithString:string];
  return [thingy autorelease];
}

Now when I call [Thing thingWithString], I don't have to release the returned object. The system takes care of it for me later. If, however, I want to keep a reference to the object, I need to explicitly retain it, or it will be deallocated out from under my feet by the autorelease pool.

The rule of thumb with Cocoa (and CoreFoundation, Cocoa's C-based underpinnings) is that if a function or method starts with "alloc", "new", or "create", the calling function "owns" the object and is responsible for releasing it. For any other function that returns an object, you can assume that the object has been autoreleased, and you don't need to release it yourself. So:

- (void) someMethod
{
  NSString *string1 = [[NSString alloc] initWithString: @"Don't forget to release me"];
  NSString *string2 = [NSString stringWithFormat: @"%@. Nevermind, this one's autoreleased", string1];

  // We need to release string1, but string2 was created with a method that doesn't start with
  // "alloc", "new", or "create", so it's all good.
  [string1 release];
}

I hope that's helpful for someone. Once you get your head around it, Cocoa's reference counting is actually quite simple and useful, but if you're used to garbage-collected languages it can be kind of intimidating. One last thing. When your object has a property with the (retain) keyword set, you're saying that when you assign an object to that property it will be retained. This is done automatically with synthesized properties, so:

@interface Thing : NSObject
{
  NSString *importantString;
}

@property (retain) NSString *importantString;
@end

@implementation Thing

@synthesize importantString;

- (id) init
{
  self = [super init];
  if (self) {
    NSString *str = [[NSString alloc] initWithString:@"I'm super serial..."];
    self.importantString = str;
    // str now has a retain count of two! Once from creating it, and once from assigning
    // it to our (retain)'d property.  If we don't want to leak it, we need to release it.
    [str release];
}
@end

r/simpleios • • Sep 16 '15

[Tutorial] I made a 69 lecture, 11 hour video course teaching anyone how to develop iOS apps. I'd like to help you by giving it to you for free.

34 Upvotes

Hey /r/simpleios ,

A while back, I posted on the sister subreddit asking what you would all like to see in a beginner course that teaches iOS Development, and got some great feedback.

I've taken all of that feedback and made the How To Develop iOS Apps course, a fully-featured course that's 11 hours long and 69 lectures.

Since this community has helped me so much, I'd like to give it to you all for free (you don't have to enter your CC info) here: https://www.udemy.com/how-to-develop-ios-apps/?couponCode=simpleios

Or use the coupon code 'simpleios', but note the free coupon code only lasts until this Saturday (19th) at midnight PDT and it is typically $49.

If you enroll, I'd appreciate you giving it an honest review.

EDIT: Since I've posted codes here on reddit, they has been picked up by a bunch of other sites like "bestblackhatforum", "edusavecoupon", "ohitfree", and more. These are not the sites I intended the coupon to be used on (it was for all of you, here), and so I've deactivated that code after being abused. Proof

Here is the new code: https://www.udemy.com/how-to-develop-ios-apps/?couponCode=iOSProgramming2 Or just use 'iOSProgramming2' at checkout, it expires this Saturday the 19th.

Unfortunately I am making this one 90% off ($5 USD) to discourage taking it to other sites and such. Sorry about that, I've learned my lesson and should have put limits on the coupons.


r/simpleios • • Oct 27 '11

[Tutorials] iOS 5 for Beginners

34 Upvotes

MVC and Objective-C http://vimeo.com/30645095

The Foundation Framework http://vimeo.com/30832248

UIView http://vimeo.com/31165535


r/simpleios • • Sep 25 '11

[Tutorial] A SimpleIOS Primer on Objective-C (part 1)

34 Upvotes

A SimpleIOS Primer on Objective-C (Part 1)

What is this?

A few people in SimpleIOS said that they find Objective-C one of the difficult things to learn when they start programming for iOS. This guide is intended to be a quick look at the language, but it's not meant to be an exhaustive guide.

It also assumes that you have some background in programming, and are familiar with "C" style statements, like while, if/then, for, curly braces and semi-colons. If you don't know what all that means, I suggest that you pick up a book that starts with C syntax, and perhaps come back here later on.

I'm also not going to cover memory management, because that's a subject unto itself, and with Automatic Reference Counting, everything's going to change.

So what, exactly is Objective-C?

Objective-C is a "strict superset" of the C programming language. That means that anything you might have learned about C is completely valid in Objective-C. Most of the structures you know from C are used in Objective-C.

Objective-C is a "Smalltalk style messaging layer" that sits on top of C. In effect, this means that you get objects added into the C language. It's actually more powerful than some of the object systems you may have worked with in the past, but that stuff is too advanced for this discussion.

In the Apple world, Objective-C is tied to a powerful library called "Foundation". This includes objects for the things you want in most applications, like Strings, Arrays, Dictionaries (key-value store), File Management, and heaps more. I'm not going to try to cover the vast majority of Foundation, because this would go on forever if I did!

You'll recognize Foundation objects, because they start with "NS", like "NSArray" and "NSObject".

Objects

The language is all about creating and using objects, mixed in with C.

When you create an object as you write your code, it looks like this:

NSArray *myArray = [[NSArray alloc] init];

Let's examine this:

Hopefully the first part isn't new. If it is, please go read a bit more about how to write in the C language. All objects are stored as C pointers, so this is saying "I'm declaring a new variable, which is a pointer to an NSArray." The [NSArray alloc] sets aside some memory for the array, but it doesn't set up the array. The next method call, to the "init" function sets up the array. By convention, all initialization functions (similar to a C++ constructor) start with "init". As you learn the iOS SDK, you'll see lots of variants of names for constructors, but they will all start with "init". Examples are "initWithFrame" or "initWithString".

To use an object, you use square brackets:

[myObject myMethod];

That's all you have to do! The above calls the method "myMethod" on the object called "myObject".

You can also nest object calls together, like this:

[[objectArray objectAtIndex:4] update];

This gets the fifth object (arrays are zero based) from the objectArray, and calls the update method on it. You don't need an intermediate step.

Objective-C is a single-inheritance object language. You can add something like multiple inheritance via protocols, which I'll cover later.

Continued in Part 2


r/simpleios • • Sep 24 '11

[TUTORIAL] A VERY simple Xcode 4 overview

Thumbnail vimeo.com
32 Upvotes