Section 1

Preview this deck

@property (nullable)

Front

Star 0%
Star 0%
Star 0%
Star 0%
Star 0%

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Active users

0

All-time users

0

Favorites

0

Last updated

1 year ago

Date created

Mar 1, 2020

Cards (73)

Section 1

(50 cards)

@property (nullable)

Front

- optional - pointer may have a NULL or nil value - For Xcode 7+ (Like ? in Swift)

Back

@property (weak)

Front

- Create a non-owning relationship between the property and the assigned value. - Use this to prevent retain cycles. - Makes it possible to maintain a cyclical relationship (the children should store a __ reference back to the parent) - Is a possibility that the obj will be destroyed while the related obj still has a reference to it. Should this happen, the __ attribute will conveniently set the property to nil in order to avoid a dangling pointer.

Back

SEL | data type

Front

- Used to store selectors, which are Objective-C's internal representation of a method name. -------------- Example: __ stepOne = NSSelectorFromString(@"startEngine"); __ stepTwo = @selector(sayHello); // end with colon if the method has parameters __ stepThree = @selector(turnByAngle:quickly:);

Back

@property (readonly)

Front

- Don't synthesize a setter method - Prevents assignment via dot-notation - The getter is unaffected.

Back

Closure

Front

- Inside of a block, you have access to same data as in a normal function: local variables, parameters passed to the block, and global variables/functions. - Have access to non-local variables. - Creates a snapshot of the variables. They are frozen at whatever value they contain when the block is defined, and the block always uses that value, even if the non-local variable changes later on in the program. - An incredibly convenient way to work with the surrounding state. - Eliminates the need to pass in extra values as parameters—you simply use non-local variables as if they were defined in the block itself.

Back

Independent automatic variables

Front

- Default - __ declared inside of a function are reset each time the function is called. - The function behaves consistently regardless of how many times you call it. -------------- Example: NSLog(@"%d", countTwo()); // 2 NSLog(@"%d", countTwo()); // 2 NSLog(@"%d", countTwo()); // 2

Back

id | data type

Front

- The generic type for all Objective-C objects. - Object-oriented version of C's void pointer. - Can store a reference to any type of object. - The __ type automatically implies that the variable is a pointer, so this is not necessary to be declared with pointer notation (the asterisk *) -------------- Example: __ mysteryObject = @"An NSString object"; // String mysteryObject = @{@"model": @"Ford", @"year": @1967}; // Dictionary

Back

Function

Front

- They let you reuse an arbitrary block of code throughout your application. - Are code blocks that are unrelated to an object / class, just inherited from c. - Has no implicit arguments - everything it needs must be passed in. - It does not alter the state of the object. - Use if the code is used frequently within a given class, or throughout the project, that it warrants being generalized. - Use if it has no side-effects or context dependancies (none of that void *context mess). -------------- Example: RETURN_TYPE NAME(TYPE PARM-NAME, TYPE PARM-NAME...) {} int foo(int a, int b) { return a+b; } // call int ab; ab = foo(a, b);

Back

NSNull

Front

- empty/zero/nothing - is a Class pointer - Defines a singleton object used to represent null values in collection objects(NSArray,NSDictionary) and other situations where nil isn't allowed. -------------- Example: The [__ null] will returns the singleton instance of __.

Back

@property (copy)

Front

- Create a __ of the assigned value instead of referencing the existing instance. - The __ attribute is an alternative to strong. Instead of taking ownership of the existing object, it creates a __ of whatever you assign to the property, then takes ownership of that. - Create another object with duplicate values/a clone. - You do NOT share the clone/new instance with whomever passed it to you. - Has the added perk of freezing the object at whatever value it had when it was assigned. - Properties that represent values (opposed to connections or relationships) are good candidates for __ (ex NSString)

Back

@property (atomic)

Front

- Locks the underlying object to prevent the setter and the getter of being called at the same time - Guarantees that the get or set operation is working with a complete value. @property are __ by default

Back

Class Implementation

Front

- is often used to contain the implementation code for the method(s) of a class. - This file is also referred to as a source file. - You don't need to include the super class. - Private instance variables can be stored between curly braces after the class name: -------------- Example: // Car.m #import "Car.h" @___ Car { // Private instance variables double _odometer; } @synthesize model = _model; // Optional for Xcode 4.4+ - (void)drive { NSLog(@"Driving a %@. Vrooooom!", self.model); } @end

Back

primitive C data types

Front

int, float, char, double

Back

Class Interface

Front

- The header file - After the @__ directive, comes the class and the superclass name, separated by a colon. - (Protected variables can be defined inside of the curly braces, but most developers treat instance variables as implementation details and prefer to store them in the .m file instead of the __). -------------- Example: // Car.h #import <Foundation/Foundation.h> @___ Car : NSObject { // Protected instance variables (not recommended) } @property (copy) NSString *model; - (void)drive; @end

Back

void pointer

Front

- Can store a reference to any type of object.

Back

Static Functions

Front

- Private - Lets you limit the function's scope to the current file, which is useful for creating "private" functions and avoiding naming conflicts. - Note that the __ keyword should be used on both the function declaration and implementation. (By default, all functions have a global scope. This means that as soon as you define a function in one file, it's immediately available everywhere else. )

Back

Frame

Front

- How the view relates to the superView. - Its more about the superview knowing how big a view is, and is related to where the view lies within the superviews coordinate grid.

Back

@property (nonnull)

Front

- non-optional - pointer may NOT have a NULL or nil value - For Xcode 7+ (Like ! in Swift)

Back

static

Front

- Lets you alter the availability of a function or variable. Unfortunately, it has different effects depending on where you use it: __ Functions: By default, all functions have a global scope. The __ specifier lets you limit the function's scope to the current file. __ Local Variables: Variables retain their assigned values over repeated calls to the function.

Back

Bounds

Front

- The drawable area inside the view itself. - The view's coordinate system. - __ origin can be moved from (0,0) which is useful in placing scrollview's view to highlight a different area.

Back

Class methods

Front

- Declarations AND implementation are prefixed with a plus sign instead of a minus sign. - These are commonly called "static" __/properties in other programming languages (not to be confused with the static keyword). - Use the same square-bracket syntax as __, but they must be called directly on the class, as shown below. -------------- Example: + (void) setDefaultModel: (NSString *) aModel { _defaultModel = [aModel copy]; } --------------- // main.m [Car setDefaultModel:@"Nissan Versa"];

Back

custom initialization method

Front

- Own versions definition to accept configuration parameters. - Like normal instance methods, except the method name should always begin with __. - Should always return a reference to the object itself, and if it cannot be initialized, it should return nil. - We need to check if self exists before trying to use it. ( There should typically only be one initialization method that needs to do this, and the rest should forward calls to this designated initializer. ) -------------- Example: // Car.m - (id) initWithModel: (NSString *) aModel { self = [super init]; if (self) { // Any custom setup work goes here _model = [aModel copy]; _odometer = 0; } return self; }

Back

super | keyword

Front

The __ keyword refers to the parent class.

Back

Parameterless Blocks

Front

- If a __ doesn't take any parameters, you can omit the argument list in its entirety. - Specifying the return type of a block literal is always optional, so you can shorten the notation to ^ { ... }: -------------- Example: double (^randomPercent)(void) = ^ { return (double)arc4random() / 4294967295; }; NSLog(@"Gas tank is %.1f%% full", randomPercent() * 100);

Back

Class initialization

Front

- Allocate some memory for the object by calling the alloc method - Then you need to __ it so it's ready to use. You should never use an uninitialized object. -------------- Example: Car *toyota = [[Car alloc] init];

Back

Function declaration

Front

- Tells the compiler what the __'s inputs and outputs look like. - Provides the data types for the return value and the parameters - So that the __ can be used in main() without knowing what it actually does. - Notice that the __ only needs the data types of the parameters—their names can be omitted (if desired).. -------------- Example: NSString getRandomMake(NSArray );

Back

initialize method

Front

- The class-level equivalent of init - It gives you a chance to set up the class before anyone uses it. - Before the first time the class is used, [Car __] is called automatically! (it's good practice to use the self == [Car class] conditional to ensure that the __ code is only run once) . -------------- Example: // Car.m + (void) __ { if (self == [Car class]) { // Makes sure this isn't executed more than once _defaultModel = @"Nissan Versa"; } }

Back

@property (nonatomic)

Front

- Don't guarantee the integrity of accessors in a multi-threaded environment. This is more efficient than the default __ behavior. - For a NON multi-threaded environment or when you are implementing your own thread-safety - Can't guarantees that the get or set operation is working with a complete value... - Let you mix-and-match synthesized accessors with custom ones

Back

@property (strong)

Front

- Create an owning relationship between the property and the assigned value. - This is the default for object properties. - This ensures that it will be valid as long as another class needs it. - By convention, the parent object should maintain a __ reference with it's children.

Back

Blocks

Front

- Anonymous functions. - Let you pass arbitrary statements between objects as you would data, which is often more intuitive than referencing functions defined elsewhere. - Implemented as closures, making it trivial to capture the surrounding state. - Non-local variables are copied and stored with the __ as const variables, which means they are read-only. -------------- Example: // Declare double (^distanceFromRateAndTime)(double rate, double time); // Create and assign distanceFromRateAndTime = ^double (double rate, double time) { return rate * time; }; // Call double dx = distanceFromRateAndTime(35, 1.5);

Back

@dynamic

Front

- just tells the compiler that the getter and setter methods are implemented not by the class itself but somewhere else (like the superclass or will be provided at runtime). - tells the compiler "don't worry about it, a method is on the way." Uses for__ are e.g. with subclasses of NSManagedObject (CoreData) or when you want to create an outlet for a property defined by a superclass that was not defined as an outlet.

Back

pointer notation

Front

- - Recall that all Objective-C objects are referenced as pointers, so when they are statically typed, they must be declared with __. -------------- Example: NSString *mysteryObject

Back

nil

Front

- empty/zero/nothing - is an object value - is an id - should be used, if we are dealing with an object.

Back

Method

Front

- Represent the actions that an object knows how to perform. - Attached to class / instance (object) and you have to tell the class / object to perform them. -------------- Example: - (RETURN_TYPE) NAME (TYPE PARM-NAME, TYPE PARM-NAME...) {} // declaration - (int) foo { return 0; } // call int a; a = [someObjectOfThisClass foo]; [porsche initWithModel:@"Porsche" mileage:42000.0];

Back

@property | Properties

Front

- Represent an object's data. - An attribute of your object that can be accessed - Lets other objects inspect or change its state (with accessor methods) - Automatically generates these accessor methods - Is set in the .h file

Back

typedef | keyword

Front

- Used to give a type a new name. - limited to giving symbolic names to types -------------- Example: __ struct Books { NSString *title; NSString *author; NSString *subject; int book_id; } Book; __ unsigned char byte; // byte is the new name

Back

Method Naming Conventions

Front

- Don't abbreviate anything. - Explicitly state parameter names in the method itself. - Explicitly describe the return value of the method.

Back

NULL

Front

- empty/zero/nothing - is a void * (generic pointer value) - should be used, if we are not dealing with an object. (ex: check if struct is empty or not ) - Key-value observing the context should be a C pointer or an object reference. Here for the context we have to use __.

Back

Mutable Non-Local Variables

Front

- Like static local variables in normal functions. - Serves as a "memory" between multiple calls to a block. - You can override the const copy behavior by declaring a non-local variable with the __block storage modifier. - Capture the variable by reference, creating a direct link between the variable outside the block and the one inside the block. - You can now assign a new value to make from outside the block, and it will be reflected in the block, and vice versa. -------------- Example: __block NSString *make = @"Honda";

Back

Static Local Variables

Front

- The function "remembers" its value across invocations. - Uses same value / same spot in the memory every time. - __ variables retain their assigned values over repeated calls to the function. Example: NSLog(@"%d", countByTwo()); // 2 NSLog(@"%d", countByTwo()); // 4 NSLog(@"%d", countByTwo()); // 6

Back

Instance variables | ivars

Front

- A simple pointer to an object or C primitive (float,int) - A storage slot - Private (Only the class and subclasses can access them) - Strong by default in ARC code Declared in either the header (.h) or in the implementation file (.m). Inside the { }.

Back

#define

Front

- Used to define the aliases for various data types - Can be used to define alias for values as well, like you can define 1 as ONE, etc. - __ statements are processed by the pre-processor. -------------- Example: __ TRUE 1 __ FALSE 0

Back

@synthesize

Front

- Optional for Xcode 4.4+ - generate getter and setter methods for your property (at compile time (although as noted in the "Mixing Synthesized and Custom Accessors" section it is flexible and does not generate methods for you if either are implemented) )

Back

self | keyword

Front

- The __ keyword refers to the instance calling the method. - Note that in class methods, the __ keyword refers to the class itself, not an instance.

Back

Function implementation

Front

Attaches a code block to the declared function. -------------- Example: NSString getRandomMake(NSArray makes) { int maximum = (int)[makes count]; int randomIndex = arc4random_uniform(maximum); return makes[randomIndex]; }

Back

class-level method

Front

- The easiest way to get a class object. -------------- Example: // returns an object representing the Car class. [Car class]

Back

Selectors

Front

- Objective-C's internal representation of a method name. - Let you treat a method as an independent entity. - Enabling you to separate an action from the object that needs to perform it. - Part of Objective-C's dynamic typing system. - Can be executed on an arbitrary object via performSelector: and related methods.

Back

Class

Front

- Made of two files: .h (heder) | Interface | Public Properties + Method declarations .m | Implementation of Methods

Back

Accessor methods

Front

- Getters or Setters - Lets other objects inspect or change its state

Back

Instance method

Front

- Declarations AND implementation are prefixed with a minus sign instead of a plus sign.

Back

Section 2

(23 cards)

NSNotifications

Front

- Objects that encapsulate information so that it can be broadcast to other objects by an __Center object. - Contains a name, an object, and an optional dictionary. The name is a tag identifying the __. - Are identified by NSString objects whose names are composed in this way: [Name of associated class] + [Did | Will] + [UniquePartOfName] + __

Back

Inactive | iOS State

Front

The app is running in the foreground, but not receiving events. An iOS app can be placed into an __ state, for example, when a call or SMS message is received.

Back

View | MVC

Front

- Renders model - Requests model updates - Sends user events to controller

Back

BOOL

Front

- default in Objective-C to define/ encode a truth value. (the iOS SDK generally uses __ on its interface definitions.) - signed char (=> can be assigned another value than a truth value) - True/False Value -> YES / NO

Back

NSSet

Front

- Represents a static, unordered collection of distinct objects. - Optimized for membership checking, so if you're asking a lot of "is this object part of this group?" use __. - Uses hash values to find items (like a dictionary) - When the order of the items in the collection is not important, __ offer better performance for finding items in the collection. O(1)

Back

Controller | MVC

Front

- Maps user actions to model updates. - Selects view.

Back

Categories

Front

- Easy way of extending classes / Declaring informal protocols. - A way to split a single class definition into multiple files. - Can be used to emulate "protected" methods. - Useful when you don't have access to the original source code (such as for Cocoa Touch frameworks and classes). - Easily configure a class differently for different applications - Add methods to built-in data types like NSString or NSArray. ----------- Named with the format: ClassYouAreExtending + DescriptorForWhatYouAreAdding -------------- Example: // Car+Maintenance.h #import "Car.h" @interface Car (Maintenance) - (BOOL) needsOilChange; - (void) changeOil; - (void) rotateTires; - (void) jumpBatteryUsingCar: (Car *) anotherCar; @end // the Car+Maintenance.m then has the implementation of those methods.

Back

Background | iOS State

Front

The app is running in the background, and executing code.

Back

Suspended | iOS State

Front

The app is in the background, but no code is being executed.

Back

Active | iOS State

Front

The app is running in the foreground, and receiving events.

Back

Boolean

Front

- unsigned char - True/False Value -> TRUE/FALSE

Back

NSArray

Front

- Represents an ordered collection of objects, and it provides a high-level interface for sorting and otherwise manipulating lists of data. - Reliable record of the order of their elements. - Has to iterate over its entire contents to find a particular object. O(n)

Back

Model | MVC

Front

- Encapsulates application/object states - Notifies view of state changes

Back

Extensions

Front

- Let you add methods to a class outside of the main interface file. - Must be implemented in the main implementation file. - Letting you declare a formal private API. - Can be used to make properties internally behave as read-write properties while remaining read-only to other objects. -------------- Example: // Car.m #import "Car.h" // The class __ @interface Car () @property (readwrite) double odometer; - (BOOL)engineIsWorking; @end // The main implementation @implementation Car - (BOOL) engineIsWorking { return YES; } ... @end

Back

Swizzling

Front

- Allows you to replace a method in an existing class with one of your own making. - This approach can lead to a lot of unexpected behavior, so it should be used very sparingly.

Back

Subclassing

Front

- Essentially the same as inheritance, but you would typically create the __ to either: - Override a method or property implementation in the superclass - Create specialized behavior for the subclass - Used if you need to add methods and properties to an existing class or if you want to inherit behavior from an existing class. Some classes are not designed to be __.

Back

NSDictionary

Front

- Represents an unordered collection of objects. - Associate each value with a key, which acts like a label for the value. - Useful for modeling relationships between pairs of objects.

Back

Mocks

Front

- objects that imitate a class, or look like they conform to a protocol. - They let you focus on interaction behavior between objects before full implementations exist. Test example: an object that returns a prepared answer for method calls.

Back

bool

Front

- _Bool (int) - True/False Value -> true / false (if you really want a boolean it is better to use a __.)

Back

A stub method

Front

- a method that just returns a simple but valid (though not necessarily correct) result. - Typically made when building the infrastructure. Save time by implementing mock methods. - Are also often used when testing, (returns a fixed result and then test that the rest of the method handels the result the right way)

Back

Not running | iOS State

Front

The app has not been launched or was running but was terminated by the system.

Back

Inheritance

Front

- Allows you to create concrete subclasses, which typically have specialized behavior, while __ all methods and properties from a superclass which are specified as @public or @protected within the superclass' header file. - Used if all you want to do is inherit behavior from another class, such as NSObject

Back

Protocols

Front

- A group of related properties and methods that can be implemented by any class. - Any objects that adopt the __ are guaranteed to implement all of the definied methods. ( "Make sure this object has this particular set of functionality." ) - More flexible than a normal class interface, since they let you reuse a single API declaration in completely unrelated classes. - Makes it possible to represent horizontal relationships on top of an existing class hierarchy. -------------- Example: // Definition #import <Foundation/Foundation.h> @__ StreetLegal <NSObject> - (void)signalStop; - (void)signalLeftTurn; - (void)signalRightTurn; @end // Adopting @interface Bicycle : NSObject <StreetLegal> // Usage id <StreetLegal> mysteryVehicle = [[Car alloc] init]; [mysteryVehicle signalLeftTurn]; mysteryVehicle = [[Bicycle alloc] init]; [mysteryVehicle signalLeftTurn]; if ([mysteryVehicle conformsTo__:@__(StreetLegal)]) { [mysteryVehicle signalStop]; [mysteryVehicle signalLeftTurn]; [mysteryVehicle signalRightTurn]; }

Back