iOS Architecture and MVC

11,994 views

Published on

iOS Development course at initLab by TenTouch

Published in: Technology

iOS Architecture and MVC

  1. 1. АРХИТЕКТУРА И MVC Лекция 2 TTLabs - iOS LabsThursday, December 15, 11
  2. 2. КОМУНИКАЦИЯ • http://www.slideshare.net/mignev/tag/ios-development-at- initlab • Google Groups • Skype: dani_rangelov • Facebook • Mail: dani@tentouch.comThursday, December 15, 11
  3. 3. APPSTOREThursday, December 15, 11
  4. 4. APPSTOREThursday, December 15, 11
  5. 5. APPSTOREThursday, December 15, 11
  6. 6. APPSTOREThursday, December 15, 11
  7. 7. APPSTOREThursday, December 15, 11
  8. 8. APPSTOREThursday, December 15, 11
  9. 9. CORE OS iOS is a Mac OS X which is a UNIX - like system Cocoa Touch Security FW Accelerate FW Media External Accessory FW System • Threading (POSIX threads) Core Services • • Networking (BSD sockets) File-system access • Standard I/O • Bonjour and DNS services • Locale information • Memory allocation Core OSThursday, December 15, 11
  10. 10. CORE SERVICES Cocoa Touch Threading High-Level Features File Access • ARC (Automatic Reference Counting) Media • • iCloud GCD(Grand Central Preferences • Dispatch) In-App Purchase • SQLite Core Services Collections Networking • NSArray • NSDictionary • NSSet Core OS Address BookThursday, December 15, 11
  11. 11. MEDIA LAYER Cocoa Touch Core Audio Core Animation AirPlay Audio Recording Media Quartz (2D) Audio Mixing Core Services Video Playback OpenAL JPEG, PNG, TIFF PDF Core OSThursday, December 15, 11
  12. 12. COCOA TOUCH Cocoa Touch Map Kit High-Level Features iAd • Push Notifications • Storyboard Media • • Local Notifications Printing Game Kit • Gesture Recognition • File Sharing Core Services Events (Touch) View Controllers UIKit Core OSThursday, December 15, 11
  13. 13. MVC - MODEL VIEW CONTROLLER Как да се изобрази Controller Определя поведението Променя модела Определя кое View получава touches Описание Изобразяване Model View Запазва състоянието на апликацията Изпраща действията на потребителя към controller Показва функционалността Изисква промяна на модела Съобщава на View за промени Изобразява модела /render/Thursday, December 15, 11
  14. 14. MVC - MODEL VIEW CONTROLLER Controller Model ViewThursday, December 15, 11
  15. 15. MVC - MODEL VIEW CONTROLLER Notification / KVO Controller De leg O ate ut let Notify Model ViewThursday, December 15, 11
  16. 16. CHAPTER 2 APPLICATION EVENTS Core App Objects Figure 2-1 Key objects in an iOS app Model Data Objects Document Controller View UIApplication Application Delegate UIWindow Event Data Model Objects Data Model Objects Data Model Objects Data Model Objects Loop View Controller Views and UI Objects Custom Objects System Objects Either system or custom objects Table 2-1 The role of objects in an iOS appThursday, December 15, 11
  17. 17. MVC - MODEL VIEW CONTROLLER backgroundColor  property hidden  property alpha property Controller userInteractionEnabled  property multi pleTouchEnabled  property autoresizingMask  property autoresizesSubviews  property – initWithFrame: – addSubview: – bringSubviewToFront: – sendSubviewToBack: – removeFromSuperview CoreData + beginAnimations:context: NSArray + commitAnimations NSDictionary plist - viewDidLoad - viewDidUnload – viewWillAppear: – viewDidAppear: – viewWillDisappear: Model – – viewDidDisappear: shouldAutorotateToInterfaceOrientation: - – – willRotateToInterfaceOrientation: didReceiveMemoryWarning dismissViewControllerAnimated: View – presentModalViewController:animated: – dismissModalViewControllerAnimated:Thursday, December 15, 11
  18. 18. ОСНОВИ НА OBJECTIVE C @“Hello World!”Thursday, December 15, 11
  19. 19. OBJECTIVE C • Комбинация межди C & Smaltalk • Superset на С • Компилира С и С++ класове • NeXTSTEP (NS) • Apple • Objective CThursday, December 15, 11
  20. 20. XCODEThursday, December 15, 11
  21. 21. THE APP LAUNCH CYCLE CHAPTER 3 App States and Multitasking Foreground Figure 3-2 Launching an app into the foreground Launch Time Your code User taps app icon main() UIApplicationMain() Load main UI file application: Initialize the app didFinishLaunchingWithOptions: Foreground Activate the app applicationDidBecomeActive: Event Handle events Loop Switch to a different appThursday, December 15, 11
  22. 22. 51). Suspended The app is in the background but is not automatically and does not notify them APPLICATION STATES in memory but does not execute any c When a low-‐memory condition occurs, t to make more space for the foreground Figure 3-1 State changes in an iOS app Not running Foreground Inactive Active Background Background SuspendedThursday, December 15, 11
  23. 23. RUN LOOP main.m • вход към програматаThursday, December 15, 11
  24. 24. .H ( HEADER FILE) AppDelegate.h • публични методи • публични променливиThursday, December 15, 11
  25. 25. .M (IMPLEMENTATION FILE) AppDelegate.m • описание на методитеThursday, December 15, 11
  26. 26. ВИВОДЕ МЕТОДИ • instance • classThursday, December 15, 11
  27. 27. ОСНОВЕН ОБЕКТ NSObject •- (id)init; •+ (id)alloc; •- (void)dealloc; •- (id)copy;Thursday, December 15, 11
  28. 28. MEMORY MANAGEMENT • retain • release • вески обект, който притежаваме трябва да бъде освободен, когато свършим работата си с негоThursday, December 15, 11
  29. 29. APPLICATION SANDBOX APPENDIX A The iOS Environment Figure A-1 Sandbox directories in iOS App Sandbox MyApp.app Documents App • собствени файлове ... Library tmp • няма ... достъм по чужди App Sandbox • сигурност App ... App Sandbox App ... Important: The purpose of a sandbox is to limit the damage that a compromiThursday, December 15, 11 system. Sandboxes do not prevent attacks from happening to a particular app a
  30. 30. XCODE PROJECTThursday, December 15, 11
  31. 31. ЗА СЛЕДВАЩИЯТ ПЪТ ПодгряванеThursday, December 15, 11
  32. 32. DATA MODEL • NSString (NSMutableString) • NSNumber • NSData (NSMutableData) • NSValue • NSDate • NSArray (NSMutableArray) • NSDictionary (NSMutableDictionary) • NSSet (NSMutableSet), NSOrderedSet (NSMutableOrderedSet), NSIndexSet (NSMutableIndexSet)Thursday, December 15, 11
  33. 33. for iOS. Figure 2-‐3 shows the basic structure of an app whose interface is constructed solely using view objects. In BUILDING AN INTERFACE USING UIKIT this instance, the main view spans the visible area of the window (minus the scroll bar) and provides a simple white background. The main view also contains three subviews: an image view, a text view, and a button. VIEWS Those subviews are what the app uses to present content to the user and respond to interactions. All of the views in the hierarchy are managed by a single view controller object. Figure 2-3 Building your interface using view objects View Controller Application controller layer View layer Window View Image View Text View Button In a typical view-‐based app, you coordinate the onscreen views using your view controller objects. An app always has one view controller that is responsible for presenting all of the content on the screen. That view controller has a content view, which itself may contain other views. Some view controllers can also act asThursday, December 15, 11 containers for content provided by other view controllers. For example, a split view controller displays the
  34. 34. СТРУКТУРИ • CGPoint • CGSize • CGRect = CGPoint, CGRectThursday, December 15, 11
  35. 35. БЛАГОДАРЯ!Thursday, December 15, 11

×