Professional Documents
Culture Documents
IOS Overview App Development Life Cycle
IOS Overview App Development Life Cycle
History, IOS version, IOS Architecture Hello World App, Structure of project,
SDK Overview. Deploying to an Emulator, Debug app.
Architecture
/ IOS SDK
Tools shipped with SDK:
Xcode
Professional text editor
Debugger
GCC Compiler
Interface Builder
For creating user interface
Instruments
For optimizing applications
Dash Code
For creating web applications for safari
iPhone simulator
Demo
/ App Development Life Cycle
Demo App Development Life Cycle
/ Objective - C
• Objective-c introduction
• Classes and Objects
• Pointers
• Properties and Methods
• Object Properties and ARC
• NSString, NSArray, NSMutableArray, NSDictionary, NSMutableDictionary…
/ Objective-c introduction
• Objective-C is an object oriented language
• Objective-C was invented by two men, Brad Cox and Tom Love at their company Stepstone
• In 1988 Steve Jobs acquires Objective-C license for NeXT and Used Objective-C to build the NeXTSTEP Operating System
• In 1995 NeXT gets full rights to Objective-C from Stepstone
/ Classes
Have both definition file and implementation file: Classname.h and Classname.m
File Classname.m
File Classname.h
#import “ClassName.h”
#import <Cocoa/Cocoa.h> @implementation ClassName
@interface ClassName : NSObject{
@end @end
/ Object
ClassName *object = [[ClassName alloc] init];
• Pointer:
• int *addressofi = &I;
• SimpleClass *model= [[SimpleClass alloc] init];
/ Automatic Reference Counting (ARC)
/ Properties
• Strong pointer là một con trỏ, trỏ đến một đối tượng và sở hữu (own) đối tượng đó.
(tham chiếu mạnh)
#import <Cocoa/Cocoa.h>
@interface ClassName : NSObject • Weak pointer là một con trỏ, trỏ đến một đối tượng nhưng không sở hữu (own) đối
tượng đó.” (tham chiếu yếu)
@property (strong, nonatomic) NSString *str;
@end
C
/ Atomic – nonatomic
(void)setPerson:(Person *)newPerson {
_person.name = newPerson.name;
_person.age = newPerson.age;
}
thread 1 gọi:
setPerson truyền vào object newPerson có value (marry, 30)
Chưa kịp chạy lệnh tiếp theo để set _person.age thì ở thread 2 gọi getter object person;
Và getter chạy trả về (marry, 27)
int a = 1;
float b = 33.22;
char c = ‘A’;
NSLog(@”Integer %d Float: %f Char: %c”, a, b, c);
/ Operators same as C
• +
• -
• *
• /
• ++
• --
/ Conditionals and Loops
• Same as C/C++
• if / else if/ else
• for
• while
• break
• continue
• do-while
/ Functions
return_type functionName(type v1, type v2, ….)
{
//code of function
}
Example
void showMeInfo(int age)
{
printf(“You are %d years old”, age); //or use NSLog(“You are %d years old”, age);
}
/ Non-GUI – text output
Two standard functions you see used:
printf() – same as C
printf(“Hi Lynne”); //this is actual C code
NSLog()
NSLog(@”Hi Lynne”); //this is strictly Objective-C
/ Whats this + and – stuff?
- (void)setAge:(int)number;
+ (void)setName:(NSString)n;
When declaring or implementing functions for a class, they must begin with a + or -
+ indicates a “class method” that can only be used by the class itself. (they are like static methods in Java
- indicates “instance methods” to be used by the client program (public functions) –invoked on an object /
class instance . (they are like regular methods in Java invoked on object)
/ Object data types
NSString *str= @”hello world”;
// NSMutableDictionary
NSMutableDictionary *dict= [[NSMutableDictionary alloc] init];
[dict setObject:value1 forKey:@”key1”];
[dict setObject:value2 forKey:@”key2”];
Nãy giờ nói cái gì mà buồn
ngủ thế.
Nhược điểm
• Trong quá trình làm nhóm, dễ bị conflict.
• Nếu bố trí không tốt, đưa quá nhiều view controller vào một story board sẽ làm rối.
Giải pháp:
• Chia nhỏ thành nhiều các storyboard.
/ Auto layout
• Xuất hiện cùng với Xcode 5
• Auto Layout là một hệ thống cho phép bạn bố trí giao diện của ứng dụng bằng cách tạo ra các mối quan hệ giữa
các yếu tố.
• Người dùng xác định các ràng buộc giữa các view với nhau để bố trí hợp lý, tự động thay đổi linh hoạt kích thước
của chúng trên nhiều loại màn hình.
• Thao khảo thêm:
https://developer.apple.com/library/ios/documentation/UserExperience/Conceptual/AutolayoutPG/Introduction/I
ntroduction.html
Demo Story Board
UIViewController Navigation Controller
Introduction, life cycle, Moving between
Pass data viewcontroller
TableView CollectionView
Introduction, custom Introduction, custom
tableview cell CollectionViewCell
/ UIViewController
• UIViewController Introduction
• UIViewController life cycle
• Pass data UIViewController
/ UIViewController life cycle
viewDidLoad
viewWillAppear
viewDidAppear
viewWillDisappear
viewDidDisappear
/ Navigation Controller
/ Switch UIViewController
• Presentviewcontroller
• Pushviewcontroller (using navigation controller)
UIAlertController * alert= [UIAlertController
/ Alert
alertControllerWithTitle:@”Title"
message:@”This is a message."
preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES
completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[alert dismissViewControllerAnimated:YES
completion:nil];
}];
[alert addAction:ok];
[alert addAction:cancel];
/ Action sheet
preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* ok = [UIAlertAction
actionWithTitle:@"OK"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
//Do some thing here
[view dismissViewControllerAnimated:YES
completion:nil];
}];
UIAlertAction* cancel = [UIAlertAction
actionWithTitle:@"Cancel"
style:UIAlertActionStyleDefault
handler:^(UIAlertAction * action)
{
[view dismissViewControllerAnimated:YES
completion:nil];
}];
[view addAction:ok];
[view addAction:cancel];
[self presentViewController:view animated:YES completion:nil];
/ HUB - Indicator
/ Tableview
/ UICollectionView
Demo
Networking Json
Networking Overview. Json overview, parser
json using jsonmodel
Thread/GCD/NSOperation AFNetworking
Overview AFNetworking for REST
based backends
Network
REST – Methods
HTTP Methods are a key corner stone in REST.
They define the action to be taken with a URL.
Proper RESTful services expose all four – “accidental” expose less.
Nothing stopping you doing some Mix & Match
●Some URL’s offering all of them and others a limited set
What are the four methods and what should they do?
REST CRUD (Create, Read, Update, Delete)
POST Create
GET Read
PUT Update or Create
DELETE Delete
JSON – What does it look like?
• {
• "firstName": "John", Name/Value Pairs
• "lastName": "Smith",
• "address": {
• "streetAddress": "21 2nd Street",
• "city": "New York", Child properties
• "state": "NY",
• "postalCode": 10021
• },
• "phoneNumbers": [
• "212 555-1234", String Array Number data type
• "646 555-4567"
• ]
• }
Difference [] and {}
● In general all the JSON nodes will start with a square bracket [] or with a curly bracket {}.
● The difference between [ and { is:
○ The square bracket ([) represents starting of an JSONArray node.
○ The curly bracket ({) represents JSONObject.
•
● If your JSON node starts with [, then we should use getJSONArray() method. Same as if the
node starts with {, then we should use getJSONObject() method.
/ JSON Model
Demo
/ NSThread
/ NSThread
/ NSOperation
/ GCD - Grand Central Dispatch
Bạn không phải chỉ định có bao nhiêu thread được phép khởi tạo trong một hàng đợi, ios sẽ tự tính toán cho
phù hợp.
NSUserdefaults File
NSUserdefaults File overview
Overview.
[nsu synchronize];
/ NSUserdefaults
LẤY RA:
NSUserDefaults * nsu = [NSUserDefaults standardUserDefaults];
NSString *userName = [nsu objectForKey:@"USER_NAME"];
BOOL isLogin = [nsu boolForKey:@"IS_LOGIN"];
/ File
/ CORE DATA
Demo