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 <UIKit/UIKit.h>
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 BOOL
s 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 <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
That's all I have time for tonight.
- 11.9k
- 1
- 20
- 46