What classes?
I created two classes AviationWeatherStation and AviationWeatherStationCollection.
AviationWeatherStation contains all the data for each airport as listed in stations.txt.
AviationWeatherStationCollection is a simple aggregation of all the AviationWeatherStations, with some utility functions, we'll look at that first.
Class definition.
@interface AviationWeatherStationCollection : NSObject <NSCopying,NSCoding>
{
NSDate *lastUpdated; // this is the date from the stations.txt file this collection was generated from
NSURL *fromURL;
NSInteger numberOfStations;
NSMutableArray *stations;
// these two are optional, be prepared for nil
NSString *stateName;
NSMutableArray *stateByStateCollection;
}
Instance methods with useage.
-(id)copyWithZone:(NSZone *)zone;
Deep copies the current collection.
-(void) createStateCollections:(BOOL)usOnly;
Creates another array of stations, sorted by U.S. state, as a property of this object.
-(AviationWeatherStation *)stationWithICAOID:(NSString *)thisID;
Returns the station that exactly matches the input ICAO code
-(NSArray *)stationArrayWithPartialICAOID:(NSString *)thisID orName:(NSString *)name orState:(NSString *)state;
Partial matching search. Will search for EITHER a partial ICAO code OR a partial airport name OR a partial state. First one hit wins, if there is an ICAO partial code and a partial name, the ICAO code wins for example.
-(NSMutableArray *)stationsWithinDistanceFromStation:(AviationWeatherStation *)station within:(NSInteger)distance;
Pass in a AviationWeatherStation object and a distance (in miles) and an array of stations within that radius will be returned.
@interface AviationWeatherStation : NSObject <NSCopying,NSCoding>
@end
{ NSString *stateName; // optional unless there is no state abreviation
NSString *stateAbbreviation; // might not exist
NSString *stationName;
NSString *ICAO;
NSString *IATA;
NSInteger SYNOPIndex;
double latitude;
double longitude;
NSInteger ELEV;
char METAR;
char NEXRAD;
char aviationFlag;
char upperAirOrWind;
char observationType;
char officeType;
char plottingPriority;
NSString *countryCode;
NSMutableDictionary *refCon; // might not exist. Key-value pairs to provide additional data to
// a station wihtout having to subclass.
// if you generate a AWSPCK key value that you want to share and add things to this dictionary
// please email me the key & value & meaning and I'll include it in this header
// and on the docs page.
// Also, PLEASE maintain any keys that you might find in a file.
// And it's called a refCon becasue I'm old
}
-(id)copyWithZone:(NSZone *)zone;
// my dictionary entry for making a station a favorite
// key CKFavorite as an example. Optional, you can certainly pull this code out if you want
-(BOOL) isFavorite;
-(void) setFavorite:(BOOL) yesOrNo;
-(void)toggleFavoriteStatus;