Flatiron School Week 5 – Questions to ask before choosing an API to work on

In the last post, I ended by saying that developer time is valuable and to be selective about which APIs to work with. This post is going to talk about how to choose an API.

Why are you using the API?

If you’re building something for educational purposes or for fun, then the last two questions matter less. The questions are more geared towards people who want to build something that will be a good business or a feature that you want the company to add to their app.

What would be fun to work on?

If I’m into restaurants, Yelp and Foursquare easily come to mind.

Does the API solve your problem?

API limit what functionality they provide, called endpoints. Let’s say that I want to look at photos for restaurants. Do the Yelp and Foursquare APIs give me photos? They both do.

If I was looking for check-in information, Foursquare would have the edge because they were built on the check-in functionality.

What are the rules around API usage?

In their documentation, API typically have rules around how they can be used.

Foursquare’s rules are pretty open and clear on exceptions. I’m not sure if I would be “recreat[ing] the functionality of Yelp’s own website or mobile apps,” with the photo idea, which they say not to do.

Both APIs require attribution.

Foursquare only allows 4 pictures or tips to be shown from any one business.

With Yelp’s API, no data can be stored, while Foursquare requires that you refresh the data.

How easy is it to use? How well is it documented?

Good documentation is super helpful when you’re first starting out. I like that Yelp shows an example of their business response. Clarity around rules is also a must because it reduces hesitation over ambiguity.

How does the company treat it’s developers?

Do they communicate changes early in advance? Who owns the app that you make?

Foursquare seems to remove functionality and gives a few months for developers to adjust.

What is the longevity of the platform?

Deprecation of API features does make you wonder what they will remove next. How long do you think you can continue to use the API? How long before something else comes along that’s more popular?

In my hypothetical example, I have seen that Yelp has better search results though. In the end, I would choose Foursquare because it seems like you are free to do more with it.

Flatiron School Week 5- What are APIs and why do they exist?

Application programming interfaces (APIs) allow you to talk to the API provider.

As iOS programmers, we have interface and implementation files for our objective-c classes. They allow other classes to communicate with our classes’ methods and properties. In fact, we use Apple’s API to build these programs. How does a tableViewController actually work? That’s in Apple’s implementation files. We only get to see the interface to be able to use it. This is the same with other companies’ APIs.

It seems like everyone has an API now, but why are they valuable?

An API provides easy access to data that takes years to build

Let’s take Yelp for example.

What value does the Yelp API have for an independent developer?

An API

  • provides an easy way to use the company’s location data, so that I don’t have to build my own location service.
  • states what the company allows you to do with their information, so that you don’t get in legal trouble with them.
  • gives you an opportunity to show your developer skills and interest in the company in case you want to work for them.

The more people that use a website or service, the better for the company

Since there’s no such thing as a free lunch, why are they allowing you access to their API?

  • Yelp wants you to use their service over Foursquare. If your app uses Yelp, then makes Yelp more popular.
  • If Yelp didn’t have a Windows Phone app, then you could built one for that new platform without hiring you to develop for them. If the Yelp app wasn’t as good as it is, then someone else can come in and build it better, but still drive the traffic to Yelp.
  • The company can see what new third party ideas are working well and adjust to what the market wants.
  • They can collect the data that you generate.
  • APIs are good for their internal developers too, so that developers can focus on their area and not have to learn how everything else works.
  • The reality is that you can set up a computer to access their information without an API. For example, aggregators like Mint can be a real pain to banks. Having the API, allows them to better monitor who is accessing their data.

APIs look like a win-win situation, but be choosy

APIs make possible crazy cool mashups. Just remember that the API owner wants you to work on their platform because they benefit too. As a developer, your time is valuable, so be selective and intentional about which APIs you work on.

Flatiron School Week 5 Questions and Answers

Question: Should I be using frame or constraints to draw views in iOS?

Answer: Constraints. Autolayout will be able to adjust to the four different screen sizes, so you don’t have to. It’s like the CSS of iOS.


Question: I know how to animate the background color of a UIView from black to red with animateWithDuration … What do I use when I want to make it go from black to blue to red?

Answer: I could use two animations with different durations, or key frame animations.


Question: One of the labs this week was making a game with four draggable images. After finishing the lab, I noticed that I could drag multiple images at a time and that they would collapse to one location at the end of the drag, because I had only accounted for one object. How can I make it so that the user can only drag one object at a time?

Answer: One solution I found online used one gesture recognizer in the superview and detected which object was pressed using hitTest:. However, this did not solve my problem. I could still take the two. This question is still open, but I can imagine a solution where I store the locations of a four objects in an array and update it as I change each object’s location.

Flatiron School Week 4- Questions and Answers

Topics: Cocoapods and Core Data

Question: Should I use [array mutablecopy] or [NSMutableArray arrayFromArray:array]  ?

Answer: Both are the same if the array is already made. Stylistically, prefer the latter.


Question: Is order maintained in Core Data?

Answer: No, if you want to maintain order, add an attribute like createdAt and use an NSSortDescriptor to order by created time.

How do I tap the back button when testing a UITableViewController in KIF?

I tried for the longest time to click the back button, but I couldn’t reference it using an accessibilityLabel. I found that you need the navigation controller to pop the top view controller.

In the it block:

[nav popViewControllerAnimated:YES];

To get the navigation controller add these lines

In the beforeAll block:

UIWindow *window = [UIApplication sharedApplication].keyWindow;
nav = ((UINavigationController*)window.rootViewController);

Since the navigation controller needs to be declared throughout the whole test. Declare a navigation controller

Between the first describe statement and the beforeAll block:

__block UINavigationController *nav;

Common tests for KIF automated UI testing for iOS

Example tests for KIF

See if a view is displayed.

it(@"should be able to load a table view controller", ^{
     [tester waitForViewWithAccessibilityLabel:@"Locations Table"];
}

Tap a cell in a table view controller.

it(@"should be able to tap a cell in a table view controller", ^{
     NSIndexPath *thirdLocation = [NSIndexPath indexPathForRow:2 inSection:0];
     [tester tapRowAtIndexPath:thirdLocation inTableViewWithAccessibilityIdentifier:@"Locations Table"];
}

Tap a view (such as a button)

it(@"should be able to tap a cell in a table view controller", ^{
      [tester tapRowAtIndexPath:thirdLocation inTableViewWithAccessibilityIdentifier:@"Locations Table"];
}

Check text of a cell

it(@"should have the correct third element in the table view", ^{
       NSIndexPath *thirdLocation = [NSIndexPath indexPathForRow:2 inSection:0];
       UITableViewCell *cell = (UITableViewCell*)[tester waitForCellAtIndexPath:thirdLocation inTableViewWithAccessibilityIdentifier:@"Locations Table"];
       expect(cell.textLabel.text).to.equal(@"Statue Of Liberty");
       expect(cell.detailTextLabel.text).to.equal(@"1");
});

Accessibility Label

KIF is relying on the accessibility label to find the views on the app. The accessibility label is on the identity inspector or it can be set programmatically.

Accessibility Label
Accessibility Label. Make sure it’s enabled.

Programmatically (in viewDidLoad of a table view controller for example):

self.tableView.accessibilityIdentifier = @"Trivia Table";

Flatiron School Week 3 Questions and Answers (Cool stuff I found this week)

Question: How do I got a progress bar to update on it’s own? 

Answer: Use a NSTimer with a UIProgressView. Stack Overflow


Question: What method is called after a UITableViewCell is tapped?

Answer: didSelectRowAtIndexPath


Question: What’s the thing that allows you to toggle a playlist sort by artist, album and title?

Answer: UISegmentedControl. It’s like a switch that has more than 2 settings.


Question: How should I make a static table view?

Answer: Use a table view with static cells, do not try to make a table view with dynamic cells. It’s a major waste of time.

Week 2 Questions and Answers

Topics

  • “Deprecated”

  • Storyboard or programmatic views

  • Mystery letters next to file names

  • Designated initializer

  • _instanceVariables in inits and setters


Question: When I look at Storyboard segues, there’s the word deprecated next to push segues. What does deprecated mean?

Answer: Apple will not be phasing out that features soon in the next release. It looks like they’re replaced the push segue with a show segue.


Question: Should I be learning to use the storyboard or learning to make views programmatically?

Answer: It depends on the usage. Storyboard is great for building views quickly and with little code. I was told that one major drawback is that it’s almost impossible to merge conflicts on storyboards. This means that when another programming changing the same view, one person’s changes will be lost. This can be mitigated by creating xib files for each classes and one owner per class. Storyboard tutorial for iOS 7.


Question: What are those A, C and M letters next to file names on the project Navigator in Xcode.

Answer: Those are the git version control symbols. A for added. C for conflict. M for modified. More here.


Question: Do I make the base initializer(init) or the custom initializer (initWithName:Birthday:Hometown:) make the designated initializer?

Answer: Use the custom initializer as the dedicated initializer. For the base initializer, use the dedicated initializer and pass in default values. More here. It saves repeated code and makes there one point of failure.


Question: Why should I use _instanceVariable in the init and setter methods instead of self.instanceVariable? I thought that we were supposed to always call methods.

Answer: For one, using self.instanceVariable in the setter will get an infinite loop because it will keep calling setInstanceVariable. There is a thing called key value observing (KVO) (awesome tutorial), which notices whenever the setter method is called for a property. In the init method, we don’t always want other people to know that we’re setting the property value.

Week 1 Questions and Answers

Question: When should I explicitly write strong vs. weak when declaring properties in class interfaces?

In other words, what is the difference between

@property (strong, nonatomic) NSString *name;

and

@property (nonatomic) NSString *name;

?

And when do I use:

@property (weak, nonatomic) NSString *name;

Answer: I found the answer on Ry’s Objective-C Tutorial, which I think is an amazing reference, because it’s very well organized and comprehensive.

In short,

@property (strong, nonatomic) NSString *name;

and

@property (nonatomic) NSString *name;

are equivalent. However, the first version is better, because there is no doubt. (Learning iOS Development by Maurice Sharp et al. p.79)

An example of when to use weak is when two objects have each other in their properties.

A Person may have a

@property Computer *myComputer;

and a computer may have a

@property Person *owner;

but you would not want to have both properties be strong because it would cause a memory leak (the program will use memory and not give up the memory, slowing down the phone).

In this case, I would make the owner weak because the parent object is the Person and not the computer.

@property (weak) Person *owner;

Question: If I clone a branch from Github and the branch that I wanted was not moved to my local machine, what should I do to get that branch from the remote? 

Answer: git checkout -t origin/<branch name>


Question:

//Should I use
[NSMutableArray new];
//or
[[NSMutableArray alloc] init];
//?

Answer: It’s up to you. The latter is more consistent because sometimes you might

[[NSMutableArray alloc] initWithArry:newArray];

Question:

//Should I use
[newString length];
//or 
newString.length;
//?

Answer: Dot notation is more readable, but opinions may differ, sometimes within the same person. Ex.

Dot notation in Objective-C: 100% Pure Evil

In Which I Embrace Dot Notation