Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
90 changes: 45 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ A quick reference cheat sheet for iOS developers so that you turn coffee into co
- [Delegates](#delegates)
- [Blocks](#blocks)

###Foundation Framework Classes
### Foundation Framework Classes

- [NSString](#nsstring)
- [NSArray](#nsarray)
- [NSDictionary](#nsdictionary)
- [Objective-C Literals](#objective-c-literals)

###C Related Code
### C Related Code

- [Enumerated Types](#enumerated-types)


##Objective-C Basics
## Objective-C Basics

###Classes
### Classes

####Class header
#### Class header

```objc
@interface Human : NSObject
Expand All @@ -44,10 +44,10 @@ A quick reference cheat sheet for iOS developers so that you turn coffee into co
@end
```

####Class implementation
#### Class implementation

```objc
#import "Human.h"
# import "Human.h"

@interface Human ()
// Define private properties and methods
Expand All @@ -62,16 +62,16 @@ A quick reference cheat sheet for iOS developers so that you turn coffee into co
@end
```

####Creating an instance
#### Creating an instance

```objc
Human * anObject = [[Human alloc] init];
```


###Methods
### Methods

####Defining methods
#### Defining methods

```objc
// Returns nothing and has no arguments
Expand All @@ -87,7 +87,7 @@ Human * anObject = [[Human alloc] init];
+ (void)aClassMethod;
```

####Implementing methods
#### Implementing methods

```objc
- (NSString *)fooWithArgument:(NSObject *)bar{
Expand All @@ -96,7 +96,7 @@ Human * anObject = [[Human alloc] init];
}
```

####Calling a method
#### Calling a method

```objc
[anObject someMethod];
Expand Down Expand Up @@ -170,9 +170,9 @@ Operator | Description
* | Pointer


###Properties
### Properties

####Define properties
#### Define properties

```objc
@property (attribute1, attribute2) NSString *aProperty;
Expand All @@ -191,7 +191,7 @@ readonly | Generates only getter
getter=method | Use this to specify a different name for the property's getter method
setter=method | Use this to specify a different name for the property's setter method

####Access Properties
#### Access Properties

```objc
[anObject aProperty];
Expand All @@ -201,24 +201,24 @@ anObject.aProperty
```


###Constants
### Constants

####Preprocessing Macros
#### Preprocessing Macros

This is not an actual constant because it defines a macro which replaces all occurrences of ```MAX_NUMBER_OF_ITEMS``` with the actual value before compile time.

```objc
#define MAX_NUMBER_OF_ITEMS 10
```

####Using const
#### Using const

A better approach is to use ```const```.
```objc
NSString *const kMyName = @"Clark";
```

####Static and extern
#### Static and extern

If you know that the constant will only be available within it's implementation file, then you can use ```static```. Using ```static``` means that the constant will only be available in that file.

Expand All @@ -238,9 +238,9 @@ extern NSString * const kMyName;
NSString * const kMyName = @"Clark";
```

###Flow control statements
### Flow control statements

####If-else statement
#### If-else statement

```objc
if (someCondition) {
Expand All @@ -252,37 +252,37 @@ if (someCondition) {
}
```

####Ternary operator
#### Ternary operator

```objc
someCondition ? @"True" : @"False";
```

####For Loops
#### For Loops

```objc
for (int i = 0; i < totalCount; i++) {
// Do something here
}
```

####While Loop
#### While Loop

```objc
while (someCondition) {
// Do something here
}
```

####Do While Loop
#### Do While Loop

```objc
do {
// Do something here
} while (someCondition);
```

####Switch
#### Switch

```objc
switch (aLabel)
Expand All @@ -302,11 +302,11 @@ switch (aLabel)
```


###Delegates
### Delegates

Delegates are a design pattern. A delegate allows one object to send messages to another object when an event happens. Check out [Apple docs](https:// developer.apple.com/library/ios/documentation/general/conceptual/CocoaEncyclopedia/DelegatesandDataSources/DelegatesandDataSources.html):

####Become the delegate of a framework class
#### Become the delegate of a framework class

**Step 1**

Expand Down Expand Up @@ -337,7 +337,7 @@ Set your object as the delegate.
Implement the delegate methods.


####Implement your own delegate for a custom class
#### Implement your own delegate for a custom class

**Step 1**

Expand Down Expand Up @@ -435,19 +435,19 @@ typedef returnType (^TypeName)(parameterTypes);
TypeName blockName = ^returnType(parameters) {...};
```

##Class Specific
## Class Specific

###NSString
### NSString

####Quick examples
#### Quick examples

```objc
NSString *firstName = @"Clark";
NSString *lastName = @"Kent";
NSString *fullName = [NSString stringWithFormat: @"My full name is %@ %@", firstName, lastName];
```

####NSString format specifier
#### NSString format specifier

Specifier | Description
:---: | ---
Expand All @@ -462,9 +462,9 @@ Specifier | Description
%% | Literal %


###NSArray
### NSArray

####Quick examples
#### Quick examples

```objc
// Create an array
Expand All @@ -491,9 +491,9 @@ NSString *superman = anArray[0];
[anArray removeObjectAtIndex:0];
```

###NSDictionary
### NSDictionary

####Quick examples
#### Quick examples

```objc
// Create a dictionary
Expand All @@ -518,16 +518,16 @@ NSLog(@"Superman's first name is %@", [person objectForKey:@"firstname"]);
[person removeObjectForKey:@"firstname"];
```

##Objective-C Literals
## Objective-C Literals

**Available from LLVM Compiler version 4.0 made available with Xcode 4.4**

###Strings
### Strings
```objc
NSString *string = @"This is a string.";
```

###Numbers
### Numbers
```objc
NSNumber *number = @126; // int : Equal to [NSNumber numberWithInt:126];
NSNumber *number = @126u; // unsigned int : Equal to [NSNumber numberWithUnsignedInt:126u];
Expand All @@ -537,7 +537,7 @@ NSNumber *number = @126.544; // double : Equal to [NSNumber numberWithDou
NSNumber *number = @YES; // bool : Equal to [NSNumber numberWithBool:YES]
```

###Containers
### Containers
```objc
NSArray *array = @[object1,object2,object3]; // Creating NSArray
Object *object2 = array[1]; // Accessing NSArray
Expand All @@ -548,11 +548,11 @@ Object *object2 = dictionary[@"key2"]; // Accessing NSDictionary
mutableDictionary[@"name"] = @"Henry"; // Adding to NSMutableDictionary
```

##C References
## C References

###Enumerated Types
### Enumerated Types

####Apple's Examples
#### Apple's Examples

Each enumerate is given a corresponding integer value, so

Expand Down Expand Up @@ -584,7 +584,7 @@ typedef NS_ENUM(NSInteger, UIButtonType) {

Explicitly defining the first enumerate's value is not required and it will default to 0.

####Using an enumerated type
#### Using an enumerated type

```objc
UIButton *button = [UIButton buttonWithType:UIButtonTypeInfoLight];
Expand Down