Published on April 12, 2017
Author: AmrElghadban1
Source: slideshare.net
1. Developing Mobile Application Ios : session # 3 By : Amr Elghadban
2. AMR ELGHADBAN ABOUT ME ——————————— SOFTWARE ENGINEER FCI - HELWAN 2010 ITI INTAKE 32 WORKED BEFORE IN - Tawasol IT - Etisalat Masr - NTG Clarity
3. property @property (nonatomic, weak) NSString *stringProperty; First our property has a locking term (nonatomic) and a storage mechanism (weak) specified. The nonatomic flag prevents the property from being locked which means that multiple threads can access it at the same time. By default, properties are atomic (so they are locked). Weak means that the property is not tied to the owner (i.e. one can be released without affecting the other).
4. The basic collection classes of the Foundation Framework
5. The basic collection classes of the Foundation Framework • NSSet, NSArray is immutable, so you cannot dynamically add or remove items. • Immutable arrays can be defined as literals using the @[] syntax • you’re likely to encounter the more verbose arrayWithObjects: factory method a class method
6. Creating Arrays NSArray *germanMakes = @[@"Mercedes-Benz", @"BMW", @"Porsche",@"Opel", @"Volkswagen", @“Audi"]; NSArray *ukMakes = [NSArray arrayWithObjects:@"Aston Martin",@"Lotus", @"Jaguar", @"Bentley", nil]; NSLog(@"First german make: %@", germanMakes[0]); NSLog(@"First U.K. make: %@", [ukMakes objectAtIndex:0]); As you can see, individual items can be accessed through the square-bracket subscripting syntax (germanMakes[0]) or the objectAtIndex: method, is the standard way to access array elements.
7. Creating Arrays NSArray *germanMakes = @[@"Mercedes-Benz", @"BMW", @"Porsche",@"Opel", @"Volkswagen", @“Audi"]; NSArray *ukMakes = [NSArray arrayWithObjects:@"Aston Martin",@"Lotus", @"Jaguar", @"Bentley", nil]; NSLog(@"First german make: %@", germanMakes[0]); NSLog(@"First U.K. make: %@", [ukMakes objectAtIndex:0]); As you can see, individual items can be accessed through the square-bracket subscripting syntax (germanMakes[0]) or the objectAtIndex: method, is the standard way to access array elements.
8. loops and conditions Loops and Conditionals Objective-C supports common looping and conditionals. Here are examples of the for(each), for(count), and while loops
9. loops and conditions for (NSString *string in array) { //Do Something } for (int i = 0; i < number; i++) { //Do something } while (boolean == true) { //Do something }
10. loops and conditions NSArray *germanMakes = @[@"Mercedes-Benz", @"BMW", @"Porsche",@"Opel", @"Volkswagen", @"Audi"]; // With fast-enumeration for (NSString *item in germanMakes) { NSLog(@"%@", item); } // With a traditional for loop for (int i=0; i<[germanMakes count]; i++) { NSLog(@"%d: %@", i, germanMakes[i]);} }
11. Main.m open up Supporting Files/main.m. we see the entry point to our application. #import "AppDelegate.h" int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } } The UIApplicationMain method is called to start our application and basically says to run the AppDelegate.
12. AppDelegate.h AppDelegate extends UIResponder and implements the UIApplicationDelegate protocol.
13. AppDelegate.m Application methods (didFinishLaunchingWithOptions, applicationWillResignActive, applicationWillEnterForeground, etc. ) These methods (part of the UIApplicationDelegate) are called when certain events happen on the app object. For example, didFinishLaunchingWithOptions will be called when your app starts. applicationWillResignActive is called when your app moves into the background. The majority of these (non-app starting) methods have to do with the app going into the background when you should stop tasks from running, store state, and more or when the application is coming back into an active state
14. UIViewController Any ViewController you will create will extends UIViewController. Methods: viewDidLoad,viewDidAppear,view WillAppear,ViewWillDisappear/ DidDisappear
15. View Lifecycle
16. UIViewController • ViewDidLoad - Whenever I'm adding controls to a view that should appear together with the view, right away, I put it in the ViewDidLoad method. Basically this method is called whenever the view was loaded into memory. So for example, if my view is a form with 3 labels, I would add the labels here; the view will never exist without those forms. • ViewWillAppear: I use ViewWillAppear usually just to update the data on the form. So, for the example above, I would use this to actually load the data from my domain into the form. Creation of UIViews is fairly expensive, and you should avoid as much as possible doing that on the ViewWillAppear method, becuase when this gets called, it means that the iPhone is already ready to show the UIView to the user, and anything heavy you do here will impact performance in a very visible manner (like animations being delayed, etc). •ViewDidAppear: Finally, I use the ViewDidAppear to start off new threads to things that would take a long time to execute, like for example doing a webservice call to get extra data for the form above.The good thing is that because the view already exists and is being displayed to the user, you can show a nice "Waiting" message to the user while you get the data.
17. View Lifecycle
18. Lab •Create ViewController
19. Assignment 1- Searching for the following topics in Objective-C 1- NSARRAY - NSMutableArray 2- NSDictionary - NSMutableArray 3- Autolayout 4- How to make Button rounded border for add Button 2- Create an View Controller that can take the student name and save student object in data collection like "NSMutableArray" 3- after press the save button a result label will display “Hello ” + name of the student 4- Create an method that can print tall the student names that have been entered before 5- Create a button in the screen that can preform the above action for print function loop for the enter student name 6- Advanced task : search for an UINavigation and how to use it to navigate form one screen to another
20. THANKS ▸ Skype : amr_elghadban ▸ Email : [email protected] ▸ Phone : (+20) 1098558500 ▸ Fb/amr.elghadban ▸ Linkedin/amr_elghadban ▸ ios_course facebook group : https://www.facebook.com/groups/ 1161387897317786/ WISH YOU WONDERFUL DAY