HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Interview Coding Challeng for iOS Part 1 - the Static Objective-C Library

Submitted by: @import:stackexchange-codereview··
0
Viewed 0 times
challengtheiospartinterviewforobjectivelibrarycodingstatic

Problem

I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side
of the products. The job description indicated they needed someone with 4 years of Objective-C
and iOS programming and I was surprised that they wanted to interview me.

Prior to this coding challenge I have never worked in Xcode, or programmed in iOS, Objective-c
or swift. I am an absolute beginner in these areas. I still don't think I know these programming
environments but I am learning.

Environtment

  • OSX - El Capitan



  • Xcode - Version 8.2 (8C38) // swift 3



  • Running in the iPhone 7 simulator.



  • Late 2010 17 inch MacBook Pro



The following section is the extraction of the email the hiring manager sent me:

Programming Challenge:

Create a static library or iOS Framework using Objective-C that performs the following 3 functions:

  • Collects the GPS location (latitude and longitude) of the user at a point in time



  • Collects the battery state and returns whether or not the device is plugged in and what percentage of life is left.



  • Accesses any publicly available, free API to collect the data of your choice and returns it (this should be a network call)



Build a simple application with 3 buttons and a label where text can be displayed. Each button should
call into the three functions of the library described above and output the response to the label.
Your application should consist of two tabs, one written in Objective-C and one written in Swift.
Both tabs should call into the same Objective-C library and perform the same function.

Only use Apple frameworks to complete this task. Fully comment your code explaining your logic and choices
where multiple choices are available. For example, Apple provides numerous ways to retrieve a network
resource, document why you choose the solution you did.

Please send me the full SINGLE Xcode project.

End of Challenge

This question has been divided into 2 parts based on the size of the code to be reviewed. One part
conta

Solution

For having never done Objective-C before, this looks pretty good! Here are some things I would do differently.
Library Name

What is PCI7? For an acronym used in every class in your example, it would have been nice to have an explanation somewhere of what it means!
Data Model

In the header, I would not #import for just 1 member function. I would forward declare UIAlertController and then do the #import in the source file. The reason I'd do it that way is that any file that imports this header will then also import UIKit.h which is a fairly large header to import.

I would also use more Objective-C style naming. This is something you'll see more of as you use Objective-C more often. I'd make IsGpsAvailable have a lowercase first letter and capitalize all of GPS like in the other method names. I'd probably also make most of those methods into properties. But those are minor decisions.

More importantly, I'd have the library return something more useful than strings. Strings are pain to work with for stuff that's not textual. For the GPS location data, I'd return a CLLocation*, since that's what most other methods that deal with locations take, or at least a CLLocationCoordinate2D if that would be more appropriate. The caller can decide if they want to display it as a string or do a calculation with it, or pass it to another method. Likewise with the battery state and the stock price.

Lastly, I'd advise you to make your BOOLs positive rather than negative. It becomes confusing to understand otherwise. Was it not able to establish the connection? Yes it was not able to do that. Wait… what?

I'd make it look like this:

#import 

@class UIAlertController;

@interface PCI7DataModelLibrary : NSObject
    @property (readonly) BOOL isGPSAvailable;
    @property (readonly) CLLocation* GPSLocationData;
    @property (readonly) UIDeviceBatteryState* batteryLevelAndState;
    @property (readonly) NSString* networkAccessData;
    @property (readonly) BOOL connectionEstablished;

    -(id)init;
    -(UIAlertController*)GPSAlerters;
@end


That's all I have time for tonight.

Code Snippets

#import <Foundation/Foundation.h>

@class UIAlertController;

@interface PCI7DataModelLibrary : NSObject
    @property (readonly) BOOL isGPSAvailable;
    @property (readonly) CLLocation* GPSLocationData;
    @property (readonly) UIDeviceBatteryState* batteryLevelAndState;
    @property (readonly) NSString* networkAccessData;
    @property (readonly) BOOL connectionEstablished;

    -(id)init;
    -(UIAlertController*)GPSAlerters;
@end

Context

StackExchange Code Review Q#162694, answer score: 4

Revisions (0)

No revisions yet.