Giter Site home page Giter Site logo

ios-afternoon-project-memory-management's Introduction

Contacts MRC

Introduction

The goal of this project is to solidify your understanding of the reference counting memory system by writing a project using Objective-C and manual reference counting (MRC).

Instructions

Fork and clone this repository.

You will need to create your own Xcode project. Commit regularly as you complete the requirements in this project.

You will be implementing a basic contacts manager app. It should include:

  • A main view with a table view displaying contact names
  • A plus (+) button used to create a new contact
  • A detail view controller used to display, enter, and edit more information for each contact, including at least:
    1. name
    2. email address
    3. phone number
  • Tapping a contact should show the detail view controller and allow you to edit it.
  • For testing add some test data so that there's initial contact cards you can see. (You can remove if you have persistence or a web backend)

Disable ARC First

When you create a new project, by default, ARC is enabled. You'll need to disable ARC so you can use manual reference counting. To do so, follow these steps:

  1. Create the project
  2. Select the project itself in the files navigator
  3. Select the "Build Settings" tab
  4. Select the Project itself under "PROJECT", not the app target (This will set it for all targets, but you can enabled it for individual targets)
  5. Search for "objective-c automatic" which will bring up the "Objective-C Automatic Reference Counting" setting.
  6. Change the setting to NO to disable automatic reference counting.

Xcode 11 Bug

Xcode 11's template has changed for an iOS app, and your app with MRC may crash in the main.m file. Make sure you change the main.m so that all the logic happens within the @autorelease block. (Paul reported the Apple Bug: FB7388324)

Your main.m file should look like:

#import <UIKit/UIKit.h>
#import "AppDelegate.h"

int main(int argc, char * argv[]) {
	@autoreleasepool {
		return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
	}
}

Part 1 - Storyboard

Build your storyboard as you normally would. MRC makes no difference in Interface Builder, and you'll build things as you always have.

Part 2 - Write the Code

Implement the app code. At a high level, this code will be identical to what you're used to, except that you will be responsible for memory management. As you work, remember the 5 rules of MRC:

  1. If you get an object from a method that starts with alloc/init, new, copy, or mutableCopy, you own it.
  2. Otherwise, call retain to take ownership of an object.
  3. If you own an object you must release it (or autorelease it) when you’re done.
  4. If you don’t own an object you must not release it.
  5. If you need an object to stick around longer than the current method, you must own it.

Part 3 - Testing and Analysis

Run the static analyzer using Product->Analyze in the menu (or command-shift-B). If the analyzer finds any problems, fix them. When you're done, the static analyzer should not report any problems.

Run the app and test to make sure it functions correctly.

Go Further

If you finish early or want to push yourself, here are a few additional features you can implement:

  • Add support for contacts having a photo. Does this effect memory usage as the app runs?
  • Stylize the table view cell using tips from Refactoring UI
  • Add an option to export the contact information as a "contacts.CSV" file to disk (comma separated file)
  • Add an option to share a contact card using a CIQRCodeGenerator filter from Core Image (See HackingWithSwift tutorial).
  • Implement persistence using Core Data.
  • Download "fake" users from a web API like Random User and present these as contacts

ios-afternoon-project-memory-management's People

Contributors

paulsolt avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.