Creating Empty Applications for iOS in XCode6
Helpful resource:
http://stackoverflow.com/questions/25783282/how-to-create-an-empty-application-in-xcode-6-without-storyboard
Sade Olutola

Product Placement

Kiana Khansmith

Kaledo Art
Claire Keane

❣ Chile in a Photography ❣
No title available
DEAR READER

Andulka
Cosimo Galluzzi

Discoholic 🪩

JBB: An Artblog!
cherry valley forever
ojovivo
I'd rather be in outer space 🛸
we're not kids anymore.
AnasAbdin
Cosmic Funnies
Lint Roller? I Barely Know Her
KIROKAZE
seen from Finland

seen from United Kingdom

seen from Malaysia

seen from United Kingdom
seen from United States

seen from Türkiye

seen from United Kingdom
seen from United States

seen from United States

seen from Malaysia

seen from United States

seen from United Kingdom
seen from United States
seen from United States

seen from Uzbekistan

seen from United States
seen from Malaysia
seen from China
seen from United States

seen from South Korea
@beginner-ios-development
Creating Empty Applications for iOS in XCode6
Helpful resource:
http://stackoverflow.com/questions/25783282/how-to-create-an-empty-application-in-xcode-6-without-storyboard
OAuth 2
Good resource on how OAuth 2 works:
http://www.quora.com/How-does-OAuth-2-0-work
Summary of best answer:
In order for Site A to access User X’s information on Site B, the following steps occur:
1. Site A registers User X with Site B. Site A obtains a Secret and an ID.
2. User X tells Site A to access Site B. User X is sent to Site B; Site B is informed to give Site A permission to specific information.
3. Site B redirects User X to Site A. Site B also provides User X an Authorization Code.
4. Site A sends its Authorization Code and Secret to Site B in return for a Security Token.
5. On behalf of User X, Site A makes requests to Site B. Requests bundle the Security Token along with requests.
Separation of Concerns
Model-View-Controller is a great example of separation of concerns. Within computer science, separation of concerns is a design principle that advocates separating a program into distinct sections; each section then addresses one concern, which is information that affects the code of a computer program. You achieve separation of concerns – i.e., modularity – by encapsulating information inside a section of code. By achieving separation of concerns, you simplify development and maintenance; you can also re-use individual sections of code, and independently update sections without contagion issues; the details of one section can be opaque to another.
Clearing Instagram Cookies
The code below would clear Instagram cookies:
-(void) clearInstagramCookies { for (NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookie Storage] cookies]) { NSRange domainRange = [cookie.domain rangeOfString:@"instagram.com"]; if(domainRange.location != NSNotFound) { [[NSHTTPCookieStorage shared HTTPCookie Storage] deleteCookie:cookie]; } } }
Note that NSHTTPCookieStorage (the so-called "cookie jar") stores and manages web site cookies, which are represented as NSHTTPCookie objects.
Encapsulation
In object-oriented programming, objects interact with one another by sending messages to each other. All an object knows about another object is the object’s interface; i.e., all object A knows about object B its interface. Object A’s data and logic is hidden from other objects, as is Object B’s. The interface “encapsulates” the object’s code and data. A user’s object is then isolated from any implementation changes; that is, a user of Object B would be isolated from any implementation changes in Object B, as long as the interface remains the same. As another example, if we send the explode message to Object B, it doesn’t matter to us as a user how the developer implemented the code to handle the explode message. All we need to know is the correct protocol for interacting with Object B.
Basic Swift Functions
Basic functions in Swift are also fairly intuitive. As an example:
func favoriteSaramagoNovel() {
println(“The last days of Ricardo Reis”)
}
//Output would look like:
// The last days of Ricardo Reis
Now let’s try it by passing a parameter with no default value
func favoriteSaramagoNovel(novel: String) {
println("My favorite Saramago novel is \(novel).")
}
favoriteSaramagoNovel("Blindness")
//Output would look like this assuming favoriteSaramagoNovel(“Blindness”):
//My favorite Saramago novel is Blindness
We can leverage tuples to compound multiple values and return more than one piece of data. As an example:
func favoriteMovies(name: String = “Blade 2”) -> (Int, String) {
let rottenTomatoRating = 99
let movieTitle = “My favorite vampire movie is “ + name
return (rottenTomatoesRating, movieTitle)
}
Putting this to use:
func favoriteMovieName(name: String = "Blade 2") -> (Int, String) {
let rottenTomatoRating = 99
let movieTitle = "My favorite vampire movie is " + name
return (rottenTomatoRating, movieTitle)
}
let (ratingFromTomato, movieName) = favoriteMovieName()
println("My favorite vampire movie is \("movieName") and its Rotten Tomatoes rating is \("ratingFromTomato"). I hope they show it at Doc Films!")
Arrays, Dictionaries, & Iteration in Swift vs. Objective-C
Dictionaries and arrays are very easy to specify in Swift. For example, vs. Objective-C
Objective C (Arrays)
NSMutableArray *favoriteDrinks = [NSMutableArray arrayWithArray:@[@”Gunpowder tea”, @”Coconut water”]];
Swift:
var *favoriteDrinks = [“Gunpowder tea”, “Coconut water”]
Note that arrays in Objective-C can include all types of objects; arrays in Swift usually include like-type items.
Objective C (Dictionaries):
NSMutableDictionary *quantifiedSelf = [NSMutableDictionary dictionaryWithDictionary:@{@”Wristband”: @”Fitbit”, @”Alarm”: @”Lightbox”}];
Swift (Dictionaries):
let quantifiedSelf = [“Wristband”: “Fitbit”, “Alarm” : “Lightbox”]
If we were to iterate over the above array in Objective-C, it would look like:
NSMutableDictionary *quantifiedSelf = [NSMutableDictionary
for (NSString *key in quantifiedSelf) {
NSLog(@The quantified self item %@ is %@.”, key, quantifiedSelf[key]);
Output from above would be:
// The quantified self item Wristband is Fitbit.
// The quantified self item Alarm is Lightbox.
In Swift, it would like:
let quantifiedSelf = [“Wristband”: “Fitbit”, “Alarm” : “Lightbox”]
for (item, nameOfItem) in quantifiedSelf {
println(“The quantified self item \(item) is \(nameOfItem).”)
}
// The output is:
// The quantified self item Wristband is Fitbit.
// The quantified self item Alarm is Lightbox.
Swift Variables & String Interpolation
In Swift, creating properties and setting default values for them is very easy. For example:
let excellentBreakfast = “Corned beef hash”
var myFavoriteChicagoHotel = “The Peninsula”
Note that let is used for immutable variables; var is used for variables that could change (though I’m not sure the above is a great example). The type of each variable is inferred by Swift based on the specified default values. Classes do not need to be specified. That said, if you choose not to specify a default value, you do need to declare what class the variable belongs to, for example:
let whitStillmanMovieTitle : String
String interpolation in Swift is also fairly straightforward. For example
let googleShares = 1000
let restaurant = “Hot Dougs”
let sentence = “I cashed in all \(googleShares) shares of Google stock to build up a huge inventory of pickled meats from \(restaurant).”
If we wanted to spend some of the money from our share redemption on Bubble tea, we might change things slightly:
let googleShares = 1000
var restaurant = “Hot Dougs”
restaurant += “ and Joy Yee.”
let sentence = “I cashed in all \(googleShares) shares of Google stock to build up a huge inventory of pickled meats and bubble tea from \(restaurant).”
Swift Functions and Tuples
Functions in swift resemble methods in Objective-C. However, they can also do the following:
A function’s parameters can have default values
Functions can return more than one value using Tuples. As an example, in Objective-C, you can only return one variable from a method, i.e.:
-(NSString *) scifiWriterFirstName
In Swift, you can create a Tuple, and group multiple values into one variable:
let fullScifiWriterName = (“Neal”, “Stephenson”)
The above tuple – fullScifiWriterName – could be returned from a method, but would contain two separate values. Note that tuples aren’t restricted by type, and could contain a variety of types. For example:
let goodRestaurants = (“Masa”, 1847, “Don’s Bogam”)
Functions are objects, and they can be passed along to other functions
Note that functions are not required to be part of a specific class.
Further Notes on KVO
Setting up an observer of a property is a three-step process:
1. Determine whether your problem is one where key-value observing could be beneficial; a good example is a situation where an object needs to be notified when there are changes to a specific property in another object. An example from the Apple Docs is a PersonObject wanting to know when the @property int accountBalance changes on BankObject.
2. In order for KVO to work, the PersonObject has to register as an observer of the BankObject’s accountBalance property. It does so by sending an addObserver:forKeyPath:options:context message, in code:
[bankInstance addObserver:personInstance forKeyPath:@”accountbalance” options:NSKeyValueObservingOptionNew context:NULL];
The code above generates a connection between the two objects – not between the two closes.
3. In order to respond to change notifications, the observer has to implement the observeValueForKeyPath:ofObject:change:context: method. In code:
-(void) observeValueForKeyPath:(NSString *)keyPathofObject:(id)object change:(NSDictionary *)change context:(void *)context {
//custom implementation; call the superclass’s implementation if the superclass implements it
}
The above method is invoked when the value of an observed property is changed in a KVO-compliant manner, or if a key upon which it depends is changed. For instance:
[bankInstance setAccountBalance:50]; would result in BankObject automatically notifying PersonObject of a chance in the Account Balance property. The PersonObject would then react accordingly based on the custom method defined above.
A Brief Primer on Auto Layout (Part I)
A Brief Primer on Auto Layout (Part I)
Auto Layout is based on the Cassowary constraint-solving toolkit. Per the Cassowary SourceForge project page:
“The Cassowary incremental constraint solving toolkit efficiently solves systems of linear equations and inequalities. Constraints may be either requirements or preferences. Re-solving the system happens rapidly, supporting UI applications.”
User interfaces naturally generate inequality and equality relationships; the Cassowary allows for a rules-based system that lets developers describe relationships between views using constraints. The constraints are rules that define how one view’s layouts are set and/or limited in relation to another view’s layouts.
By defining these relationships, AutoLayout can, for example:
- Match one view’s size to another view’s size; for example, they will always remain the same height or width
- Center a view in a superview; even if the superview reshapes, the view remains centered within it
- Offset a pair of items by a constant padding
You use constraints to describe the view layout. Constraints define how things relate to one another, and how they can be laid out. For example, you might say, “always line up this series of items in a vertical row”, or, “this item will resize itself to match the width of that item”.
Constraints belong to the NSLayoutConstraint class. The class specifies relationships between view attributes – items like height, width, positions, and centers – using both equalities and greater or less than equal relations. It is required that constraints be both satisfiable and sufficient. In order for constraint satisfaction to occur, the rule must make sense individually and as part of a whole – i.e., a valid rule that plays part of a larger whole. As an example, a view can’t be both above another view and below it. Rules need to be consistent. In addition, rules also need to be specific enough and/or sufficient; for example, you want to provide a well-defined size and position for a view so they aren’t scattered all over the user interface.
Constraints themselves use a constrained geometric vocabulary. There are attributes – which are the “nouns” that describe the position within a view’s alignment rectangle, and there are “verbs”, which describe how the attributes compare to each other. In a simple view rectangle, the attributes would include: 1) left (minimum X), 2) right (maximum X), 3) top (minimum Y), 4) bottom (maximum Y), 5) width, 6) height, 7) CenterX (the X-axis center of the view’s alignment rectangle), 8) CenterY (the Y-axis center of the view’s alignment rectangle), and 9) baseline, which is the alignment rectangle’s baseline, which is typically specified as a fixed offset above its bottom attribute. Relations, on the other hand, compare values. There are three relations that set equality or set lower and upper bounds for comparison: 1) NSLayoutRelationLessThanOrEqual (for less-than-or-equal inequality), 2) NSLayoutRelationalEquality (test for equality), and 3) NSLayoutRelationGreaterThanOrEqual (for greater-than-or-equal-to-inequality).
Table Views
Table views are user interface objects that present data in a scrollable list of multiple rows that may be divided into specific sections. Generally, table views are used for the following purposes:
1. Navigate hierarchically structured data
2. Present an indexed list of items
3. Display detailed information and controls clustered by group
4. Present a list of options for user selection
Table views consist of only one column that allows for vertical scrolling. The table view has rows in each section. Each section can have a header or a footer that will display text or an image. UIKit framework identifies rows and sections through an index number. The index numbers for sections range from 0 to n-1 from the top of a table view to the bottom element; rows are numbered from 0 to n-1 within a section. Table views can themselves have their own headers and footer, distinct from a section header and footer. Table headers show up above the first row of the first section; table footers show up after the last row of the last section.
A table view itself is an instance of the UITableViewClass. It is set as one of two styles – plain or grouped. Plain table views are unbroken lists; grouped tables have distinct sections. Table views have a datasource and might have delegates. Data sources provide – you guessed it, the data that is used to fill in the sections and rows of the table view. The data source mediates between the app’s data model (i.e., the model objects) and the table view. Delegate objects are used to further customize appearance and behavior. The data source and delegate are often the same object, which is usually a custom subclass of UITableViewController. The data source adopts the UITableViewDataSource protocol. UITableViewDataSource has two required methods, the tableView:numberOfRowsInSection: method that tells the table view how many rows to display in each section, and the tableView:cellForRowAtIndexPath: method, which provides the cell to display for each row in the table. The delegate adopts the UITableViewDelegate protocol, which has no required methods. The protocol declares methods that allow the delegate to modify visual elements of the table view, manage selections within the table view, and support editing of individual rows in the table view.
Visible rows within a table view are drawn using cells, which are UITableViewCell objects. Cells are views that can display text, images, or other content. They can also have background views for normal and selected states. UIKit defiens four standard cell styles – each with its own layout of the three default content elements: main label, detail label, and image.
When a user taps on a row, the delegate of the table view is made aware via message. The delegate is passed the index of the row and the section that the row is located in; it then uses this information to locate the corresponding item in the app’s model. The item will be either an intermediate level in a hierarchy of data or a “leaf node” in a hierarchy.
In addition, you can enter editing mode in a table view in which a user can insert or delete rows, or relocate them in a table. When users try to insert, delete, or reorder rows, the table view will send a sequence of messages to its data source and delegate so it can manage these operations.
Visual Formatting Strings
Visual formatting strings let you draw an outline of your views by utilizing keyboard characters. Take a look at this sample code:
```
[self.contentView addconstraints:[NSLayoutConstraint constraintsWithVisualFormat:@”H:|[_someImageView]|” options:kNilOptions metrics:nil views:viewDictionary]];
```
Visual format strings should begin with H: (horizontal) or V: (vertical). | represents the superview, and [oneView] represents one view. By setting the above to H:|[_someImageView]| we are stating that _someImageView should exactly match the width of its superview.
Introspection
Introspection is a feature of the Objective C runtime. Introspection allows an object to answer questions about itself. As an example, NSObject has a method named respondsToSelector:. It looks like the following:
-(BOOL)respondsToSelector:(SEL)aSelector;
It takes as an argument a selector (the name of a method). It returns a value of YES if the object implements the method; it returns the value NO if the object does not implement the method. Thus, using respondsToSelector: provides an example of introspection as a feature of the Objective C runtime.
Key-Value Observing
Key-Value Observing allows you to receive a notification when a particular property of an object is adjusted or changed. As an example, you might tell a Thomas Pink shirt object, "I want you to watch your pattern property. When that property changes, send me a notification". So, when a setPattern: method gets called, we will get a message from the Thomas Pink shirt object saying, "My pattern has a new value."
When we add ourselves as an object's observer, we specify that property we are observing - in this case, the pattern property. We can also specify some options - for example, we might want the Thomas Pink shirt object to tell us the old and/or new value of the property when we get notified that a change has been made.
Designated Initializers
A class has only one designated initializer method. If the class contains other initializers, then the implementation of the other initializers has to either directly or indirectly call the designated initializer.
When you set up a class and the designated initializer has a different name than the designated initializer of its superclass, you should note this in the header file.
UITableViewCell
Quick fix for Chapter 31 iTahDoodle App in Big Nerd Ranch Objective C Programming Guide:
In the code, you enter:
[self.taskTable registerClass:[UITableViewCell class] forCellReuseIdentifier:@"Cell"];
Later in the app in the table view management section, make sure that when you call the UITableViewCell method you use capital "C" in cell:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// To improve performance, this method first checks for an existing cell object that we can reuse; if there isn't one, then a new cell is created
UITableViewCell *c = [self.taskTable dequeueReusableCellWithIdentifier:@"Cell"];
This will fix any SIGABRT errors you may encounter when adding a task.