Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Following along in chapter 20.

  • Loading branch information...
commit 809ee920a0a0271748bb85237f00c504cb97d33d 1 parent a8d70d3
Nick authored
View
268 Chapter20/BMITime/BMITime.xcodeproj/project.pbxproj
@@ -0,0 +1,268 @@
+// !$*UTF8*$!
+{
+ archiveVersion = 1;
+ classes = {
+ };
+ objectVersion = 46;
+ objects = {
+
+/* Begin PBXBuildFile section */
+ 0131739D17CD3BC300F51EF8 /* Asset.m in Sources */ = {isa = PBXBuildFile; fileRef = 0131739C17CD3BC300F51EF8 /* Asset.m */; };
+ 0132610B17CAAFEB0027FCBC /* Employee.m in Sources */ = {isa = PBXBuildFile; fileRef = 0132610A17CAAFEB0027FCBC /* Employee.m */; };
+ 01EEC7DE17C9101300DD2B39 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 01EEC7DD17C9101300DD2B39 /* Foundation.framework */; };
+ 01EEC7E117C9101300DD2B39 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 01EEC7E017C9101300DD2B39 /* main.m */; };
+ 01EEC7E517C9101300DD2B39 /* BMITime.1 in CopyFiles */ = {isa = PBXBuildFile; fileRef = 01EEC7E417C9101300DD2B39 /* BMITime.1 */; };
+ 01EEC7ED17C9105300DD2B39 /* Person.m in Sources */ = {isa = PBXBuildFile; fileRef = 01EEC7EC17C9105300DD2B39 /* Person.m */; };
+/* End PBXBuildFile section */
+
+/* Begin PBXCopyFilesBuildPhase section */
+ 01EEC7D817C9101300DD2B39 /* CopyFiles */ = {
+ isa = PBXCopyFilesBuildPhase;
+ buildActionMask = 2147483647;
+ dstPath = /usr/share/man/man1/;
+ dstSubfolderSpec = 0;
+ files = (
+ 01EEC7E517C9101300DD2B39 /* BMITime.1 in CopyFiles */,
+ );
+ runOnlyForDeploymentPostprocessing = 1;
+ };
+/* End PBXCopyFilesBuildPhase section */
+
+/* Begin PBXFileReference section */
+ 0131739B17CD3BC300F51EF8 /* Asset.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Asset.h; sourceTree = "<group>"; };
+ 0131739C17CD3BC300F51EF8 /* Asset.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Asset.m; sourceTree = "<group>"; };
+ 0132610917CAAFEB0027FCBC /* Employee.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Employee.h; sourceTree = "<group>"; };
+ 0132610A17CAAFEB0027FCBC /* Employee.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Employee.m; sourceTree = "<group>"; };
+ 01EEC7DA17C9101300DD2B39 /* BMITime */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = BMITime; sourceTree = BUILT_PRODUCTS_DIR; };
+ 01EEC7DD17C9101300DD2B39 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
+ 01EEC7E017C9101300DD2B39 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
+ 01EEC7E317C9101300DD2B39 /* BMITime-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "BMITime-Prefix.pch"; sourceTree = "<group>"; };
+ 01EEC7E417C9101300DD2B39 /* BMITime.1 */ = {isa = PBXFileReference; lastKnownFileType = text.man; path = BMITime.1; sourceTree = "<group>"; };
+ 01EEC7EB17C9105300DD2B39 /* Person.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Person.h; sourceTree = "<group>"; };
+ 01EEC7EC17C9105300DD2B39 /* Person.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Person.m; sourceTree = "<group>"; };
+/* End PBXFileReference section */
+
+/* Begin PBXFrameworksBuildPhase section */
+ 01EEC7D717C9101300DD2B39 /* Frameworks */ = {
+ isa = PBXFrameworksBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 01EEC7DE17C9101300DD2B39 /* Foundation.framework in Frameworks */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXFrameworksBuildPhase section */
+
+/* Begin PBXGroup section */
+ 01EEC7D117C9101300DD2B39 = {
+ isa = PBXGroup;
+ children = (
+ 01EEC7DF17C9101300DD2B39 /* BMITime */,
+ 01EEC7DC17C9101300DD2B39 /* Frameworks */,
+ 01EEC7DB17C9101300DD2B39 /* Products */,
+ );
+ sourceTree = "<group>";
+ };
+ 01EEC7DB17C9101300DD2B39 /* Products */ = {
+ isa = PBXGroup;
+ children = (
+ 01EEC7DA17C9101300DD2B39 /* BMITime */,
+ );
+ name = Products;
+ sourceTree = "<group>";
+ };
+ 01EEC7DC17C9101300DD2B39 /* Frameworks */ = {
+ isa = PBXGroup;
+ children = (
+ 01EEC7DD17C9101300DD2B39 /* Foundation.framework */,
+ );
+ name = Frameworks;
+ sourceTree = "<group>";
+ };
+ 01EEC7DF17C9101300DD2B39 /* BMITime */ = {
+ isa = PBXGroup;
+ children = (
+ 01EEC7E417C9101300DD2B39 /* BMITime.1 */,
+ 01EEC7E017C9101300DD2B39 /* main.m */,
+ 0131739B17CD3BC300F51EF8 /* Asset.h */,
+ 0131739C17CD3BC300F51EF8 /* Asset.m */,
+ 0132610917CAAFEB0027FCBC /* Employee.h */,
+ 0132610A17CAAFEB0027FCBC /* Employee.m */,
+ 01EEC7EB17C9105300DD2B39 /* Person.h */,
+ 01EEC7EC17C9105300DD2B39 /* Person.m */,
+ 01EEC7E217C9101300DD2B39 /* Supporting Files */,
+ );
+ path = BMITime;
+ sourceTree = "<group>";
+ };
+ 01EEC7E217C9101300DD2B39 /* Supporting Files */ = {
+ isa = PBXGroup;
+ children = (
+ 01EEC7E317C9101300DD2B39 /* BMITime-Prefix.pch */,
+ );
+ name = "Supporting Files";
+ sourceTree = "<group>";
+ };
+/* End PBXGroup section */
+
+/* Begin PBXNativeTarget section */
+ 01EEC7D917C9101300DD2B39 /* BMITime */ = {
+ isa = PBXNativeTarget;
+ buildConfigurationList = 01EEC7E817C9101300DD2B39 /* Build configuration list for PBXNativeTarget "BMITime" */;
+ buildPhases = (
+ 01EEC7D617C9101300DD2B39 /* Sources */,
+ 01EEC7D717C9101300DD2B39 /* Frameworks */,
+ 01EEC7D817C9101300DD2B39 /* CopyFiles */,
+ );
+ buildRules = (
+ );
+ dependencies = (
+ );
+ name = BMITime;
+ productName = BMITime;
+ productReference = 01EEC7DA17C9101300DD2B39 /* BMITime */;
+ productType = "com.apple.product-type.tool";
+ };
+/* End PBXNativeTarget section */
+
+/* Begin PBXProject section */
+ 01EEC7D217C9101300DD2B39 /* Project object */ = {
+ isa = PBXProject;
+ attributes = {
+ LastUpgradeCheck = 0460;
+ ORGANIZATIONNAME = "Nicholas Squire";
+ };
+ buildConfigurationList = 01EEC7D517C9101300DD2B39 /* Build configuration list for PBXProject "BMITime" */;
+ compatibilityVersion = "Xcode 3.2";
+ developmentRegion = English;
+ hasScannedForEncodings = 0;
+ knownRegions = (
+ en,
+ );
+ mainGroup = 01EEC7D117C9101300DD2B39;
+ productRefGroup = 01EEC7DB17C9101300DD2B39 /* Products */;
+ projectDirPath = "";
+ projectRoot = "";
+ targets = (
+ 01EEC7D917C9101300DD2B39 /* BMITime */,
+ );
+ };
+/* End PBXProject section */
+
+/* Begin PBXSourcesBuildPhase section */
+ 01EEC7D617C9101300DD2B39 /* Sources */ = {
+ isa = PBXSourcesBuildPhase;
+ buildActionMask = 2147483647;
+ files = (
+ 01EEC7E117C9101300DD2B39 /* main.m in Sources */,
+ 01EEC7ED17C9105300DD2B39 /* Person.m in Sources */,
+ 0132610B17CAAFEB0027FCBC /* Employee.m in Sources */,
+ 0131739D17CD3BC300F51EF8 /* Asset.m in Sources */,
+ );
+ runOnlyForDeploymentPostprocessing = 0;
+ };
+/* End PBXSourcesBuildPhase section */
+
+/* Begin XCBuildConfiguration section */
+ 01EEC7E617C9101300DD2B39 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = NO;
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_DYNAMIC_NO_PIC = NO;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_OPTIMIZATION_LEVEL = 0;
+ GCC_PREPROCESSOR_DEFINITIONS = (
+ "DEBUG=1",
+ "$(inherited)",
+ );
+ GCC_SYMBOLS_PRIVATE_EXTERN = NO;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.8;
+ ONLY_ACTIVE_ARCH = YES;
+ SDKROOT = macosx;
+ };
+ name = Debug;
+ };
+ 01EEC7E717C9101300DD2B39 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ ALWAYS_SEARCH_USER_PATHS = NO;
+ ARCHS = "$(ARCHS_STANDARD_64_BIT)";
+ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
+ CLANG_CXX_LIBRARY = "libc++";
+ CLANG_ENABLE_OBJC_ARC = YES;
+ CLANG_WARN_CONSTANT_CONVERSION = YES;
+ CLANG_WARN_EMPTY_BODY = YES;
+ CLANG_WARN_ENUM_CONVERSION = YES;
+ CLANG_WARN_INT_CONVERSION = YES;
+ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
+ COPY_PHASE_STRIP = YES;
+ DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
+ GCC_C_LANGUAGE_STANDARD = gnu99;
+ GCC_ENABLE_OBJC_EXCEPTIONS = YES;
+ GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
+ GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNINITIALIZED_AUTOS = YES;
+ GCC_WARN_UNUSED_VARIABLE = YES;
+ MACOSX_DEPLOYMENT_TARGET = 10.8;
+ SDKROOT = macosx;
+ };
+ name = Release;
+ };
+ 01EEC7E917C9101300DD2B39 /* Debug */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "BMITime/BMITime-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Debug;
+ };
+ 01EEC7EA17C9101300DD2B39 /* Release */ = {
+ isa = XCBuildConfiguration;
+ buildSettings = {
+ GCC_PRECOMPILE_PREFIX_HEADER = YES;
+ GCC_PREFIX_HEADER = "BMITime/BMITime-Prefix.pch";
+ PRODUCT_NAME = "$(TARGET_NAME)";
+ };
+ name = Release;
+ };
+/* End XCBuildConfiguration section */
+
+/* Begin XCConfigurationList section */
+ 01EEC7D517C9101300DD2B39 /* Build configuration list for PBXProject "BMITime" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 01EEC7E617C9101300DD2B39 /* Debug */,
+ 01EEC7E717C9101300DD2B39 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+ 01EEC7E817C9101300DD2B39 /* Build configuration list for PBXNativeTarget "BMITime" */ = {
+ isa = XCConfigurationList;
+ buildConfigurations = (
+ 01EEC7E917C9101300DD2B39 /* Debug */,
+ 01EEC7EA17C9101300DD2B39 /* Release */,
+ );
+ defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
+ };
+/* End XCConfigurationList section */
+ };
+ rootObject = 01EEC7D217C9101300DD2B39 /* Project object */;
+}
View
23 Chapter20/BMITime/BMITime/Asset.h
@@ -0,0 +1,23 @@
+//
+// Asset.h
+// BMITime
+//
+// Created by Nicholas Squire on 8/27/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+@class Employee;
+
+@interface Asset : NSObject
+{
+ NSString *label;
+ __weak Employee *holder;
+ unsigned int resaleValue;
+}
+
+@property (strong) NSString *label;
+@property (weak) Employee *holder;
+@property unsigned int resaleValue;
+
+@end
View
37 Chapter20/BMITime/BMITime/Asset.m
@@ -0,0 +1,37 @@
+//
+// Asset.m
+// BMITime
+//
+// Created by Nicholas Squire on 8/27/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import "Asset.h"
+
+@implementation Asset
+
+@synthesize label;
+@synthesize holder;
+@synthesize resaleValue;
+
+- (NSString *)description
+{
+ // Is holder non-nil?
+ if ([self holder]) {
+ return [NSString stringWithFormat:@"<%@: $%d, assigned to %@",
+ [self label],
+ [self resaleValue],
+ [self holder]];
+ } else {
+ return [NSString stringWithFormat:@"<%@: $%d, unassigned>",
+ [self label],
+ [self resaleValue]];
+ }
+}
+
+- (void)dealloc
+{
+ NSLog(@"deallocating %@", self);
+}
+
+@end
View
7 Chapter20/BMITime/BMITime/BMITime-Prefix.pch
@@ -0,0 +1,7 @@
+//
+// Prefix header for all source files of the 'BMITime' target in the 'BMITime' project
+//
+
+#ifdef __OBJC__
+ #import <Foundation/Foundation.h>
+#endif
View
79 Chapter20/BMITime/BMITime/BMITime.1
@@ -0,0 +1,79 @@
+.\"Modified from man(1) of FreeBSD, the NetBSD mdoc.template, and mdoc.samples.
+.\"See Also:
+.\"man mdoc.samples for a complete listing of options
+.\"man mdoc for the short list of editing options
+.\"/usr/share/misc/mdoc.template
+.Dd 8/24/13 \" DATE
+.Dt BMITime 1 \" Program name and manual section number
+.Os Darwin
+.Sh NAME \" Section Header - required - don't modify
+.Nm BMITime,
+.\" The following lines are read in generating the apropos(man -k) database. Use only key
+.\" words here as the database is built based on the words here and in the .ND line.
+.Nm Other_name_for_same_program(),
+.Nm Yet another name for the same program.
+.\" Use .Nm macro to designate other names for the documented program.
+.Nd This line parsed for whatis database.
+.Sh SYNOPSIS \" Section Header - required - don't modify
+.Nm
+.Op Fl abcd \" [-abcd]
+.Op Fl a Ar path \" [-a path]
+.Op Ar file \" [file]
+.Op Ar \" [file ...]
+.Ar arg0 \" Underlined argument - use .Ar anywhere to underline
+arg2 ... \" Arguments
+.Sh DESCRIPTION \" Section Header - required - don't modify
+Use the .Nm macro to refer to your program throughout the man page like such:
+.Nm
+Underlining is accomplished with the .Ar macro like this:
+.Ar underlined text .
+.Pp \" Inserts a space
+A list of items with descriptions:
+.Bl -tag -width -indent \" Begins a tagged list
+.It item a \" Each item preceded by .It macro
+Description of item a
+.It item b
+Description of item b
+.El \" Ends the list
+.Pp
+A list of flags and their descriptions:
+.Bl -tag -width -indent \" Differs from above in tag removed
+.It Fl a \"-a flag as a list item
+Description of -a flag
+.It Fl b
+Description of -b flag
+.El \" Ends the list
+.Pp
+.\" .Sh ENVIRONMENT \" May not be needed
+.\" .Bl -tag -width "ENV_VAR_1" -indent \" ENV_VAR_1 is width of the string ENV_VAR_1
+.\" .It Ev ENV_VAR_1
+.\" Description of ENV_VAR_1
+.\" .It Ev ENV_VAR_2
+.\" Description of ENV_VAR_2
+.\" .El
+.Sh FILES \" File used or created by the topic of the man page
+.Bl -tag -width "/Users/joeuser/Library/really_long_file_name" -compact
+.It Pa /usr/share/file_name
+FILE_1 description
+.It Pa /Users/joeuser/Library/really_long_file_name
+FILE_2 description
+.El \" Ends the list
+.\" .Sh DIAGNOSTICS \" May not be needed
+.\" .Bl -diag
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .It Diagnostic Tag
+.\" Diagnostic informtion here.
+.\" .El
+.Sh SEE ALSO
+.\" List links in ascending order by section, alphabetically within a section.
+.\" Please do not reference files that do not exist without filing a bug report
+.Xr a 1 ,
+.Xr b 1 ,
+.Xr c 1 ,
+.Xr a 2 ,
+.Xr b 2 ,
+.Xr a 3 ,
+.Xr b 3
+.\" .Sh BUGS \" Document known, unremedied bugs
+.\" .Sh HISTORY \" Document history if command behaves in a unique manner
View
24 Chapter20/BMITime/BMITime/Employee.h
@@ -0,0 +1,24 @@
+//
+// Employee.h
+// BMITime
+//
+// Created by Nicholas Squire on 8/25/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+#import "Person.h"
+@class Asset;
+
+@interface Employee : Person
+{
+ int employeeID;
+ NSMutableArray *assets;
+}
+
+@property int employeeID;
+
+- (void)addAssetsObject:(Asset *)a;
+- (unsigned int)valueOfAssets;
+
+@end
View
57 Chapter20/BMITime/BMITime/Employee.m
@@ -0,0 +1,57 @@
+//
+// Employee.m
+// BMITime
+//
+// Created by Nicholas Squire on 8/25/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import "Employee.h"
+#import "Asset.h"
+
+@implementation Employee
+
+@synthesize employeeID;
+
+- (float)bodyMassIndex
+{
+ float normalBMI = [super bodyMassIndex];
+ return normalBMI * 0.9;
+}
+
+- (void)addAssetsObject:(Asset *)a
+{
+ // Is assets nil?
+ if (!assets) {
+ // Create the array
+ assets = [[NSMutableArray alloc] init];
+ }
+
+ [assets addObject:a];
+ [a setHolder:self];
+}
+
+- (unsigned int)valueOfAssets
+{
+ // Sum up the resale value of the assets
+ unsigned int sum = 0;
+ for (Asset *a in assets) {
+ sum += [a resaleValue];
+ }
+
+ return sum;
+}
+
+- (NSString *)description
+{
+ return [NSString stringWithFormat:@"<Employee %d: $%d in assets>",
+ [self employeeID],
+ [self valueOfAssets]];
+}
+
+- (void)dealloc
+{
+ NSLog(@"deallocating %@", self);
+}
+
+@end
View
29 Chapter20/BMITime/BMITime/Person.h
@@ -0,0 +1,29 @@
+//
+// Person.h
+// BMITime
+//
+// Created by Nicholas Squire on 8/24/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+
+@interface Person : NSObject
+{
+ float heightInMeters;
+ int weightInKilos;
+}
+
+//- (float)heightInMeters;
+//- (void)setHeightInMeters:(float)h;
+//- (int)weightInKilos;
+//- (void)setWeightInKilos:(int)w;
+//
+
+// This method calculates the Body Mass Index
+- (float)bodyMassIndex;
+
+@property float heightInMeters;
+@property int weightInKilos;
+
+@end
View
43 Chapter20/BMITime/BMITime/Person.m
@@ -0,0 +1,43 @@
+//
+// Person.m
+// BMITime
+//
+// Created by Nicholas Squire on 8/24/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import "Person.h"
+
+@implementation Person
+
+//- (float)heightInMeters
+//{
+// return heightInMeters;
+//}
+//
+//- (void)setHeightInMeters:(float)h
+//{
+// heightInMeters = h;
+//}
+//
+//- (int)weightInKilos
+//{
+// return weightInKilos;
+//}
+//
+//- (void)setWeightInKilos:(int)w
+//{
+// weightInKilos = w;
+//}
+
+@synthesize heightInMeters;
+@synthesize weightInKilos;
+
+// This method calculates the Body Mass Index
+- (float)bodyMassIndex
+{
+ float h = [self heightInMeters];
+ return [self weightInKilos] / (h * h);
+}
+
+@end
View
76 Chapter20/BMITime/BMITime/main.m
@@ -0,0 +1,76 @@
+//
+// main.m
+// BMITime
+//
+// Created by Nicholas Squire on 8/24/13.
+// Copyright (c) 2013 Nicholas Squire. All rights reserved.
+//
+
+#import <Foundation/Foundation.h>
+//#import "Person.h"
+#import "Employee.h"
+#import "Asset.h"
+
+int main(int argc, const char * argv[])
+{
+ @autoreleasepool {
+ // Create an array of Employee objects
+ NSMutableArray *employees = [[NSMutableArray alloc] init];
+
+ for (int i = 0; i < 10; i++) {
+
+ // Create an instance of Employee
+ Employee *person = [[Employee alloc] init];
+
+ // Give the instance variables interesting values
+ [person setWeightInKilos:90 + i];
+ [person setHeightInMeters:1.8 - i/10.0];
+ [person setEmployeeID:i];
+
+ // Put the employee in the employees array
+ [employees addObject:person];
+ }
+
+ NSMutableArray *allAssets = [[NSMutableArray alloc] init];
+
+ // Create 10 assets
+ for (int i = 0; i < 10; i++) {
+
+ // Create an asset
+ Asset *asset = [[Asset alloc] init];
+
+ // Give it an interesting label
+ NSString *currentLabel = [NSString stringWithFormat:@"Laptop %d", i];
+ [asset setLabel:currentLabel];
+ [asset setResaleValue:i * 17];
+
+ // Get a random number between 0 and 9 inclusive
+ NSUInteger randomIndex = random() % [employees count];
+
+ // Find that employee
+ Employee *randomEmployee = [employees objectAtIndex:randomIndex];
+
+ // Assign the asset to the employee
+ [randomEmployee addAssetsObject:asset];
+
+ [allAssets addObject:asset];
+ }
+
+ NSLog(@"Employees: %@", employees);
+
+ NSLog(@"Giving up ownership of one employee");
+
+ [employees removeObjectAtIndex:5];
+
+ NSLog(@"allAssets: %@", allAssets);
+
+ NSLog(@"Giving up ownership of arrays");
+
+ allAssets = nil;
+ employees = nil;
+ }
+
+ //sleep(100);
+ return 0;
+}
+
Please sign in to comment.
Something went wrong with that request. Please try again.