This project is an iPhone app that displays only a blank, white screen
under the iOS status bar.
It will, however,
print a message using the
NSLog
function in the Console window of Xcode.
Xcode.app
on your Mac.
Its icon is a hammer on a blue background.Xcode →
Preferences… →
Text Editing →
Indentation
Prefer indent using: Tabs
Tab width: 4 spaces
Indent width: 4 spaces
Tab key: Inserts tab character
Product Name: Project
Organization Name: John Doe
Company Identifier: edu.nyu.scps
Bundle Identifier: edu.nyu.scps.Project
Class prefix: Project
Devices: iPhone (for the time being)
Do not check Use Core Data; it’s better to talk directly to the SQLite database. Press Next.
Project
,
containing a file named
Project.xcodeproj
.Supporting Files
folder.
In the
Supporting Files
folder,
select the file
main.m
.
In the
main
function in the
main.m
file,
you should see a statement that calls the function
UIApplicationMain
.
return UIApplicationMain(argc, argv, nil, NSStringFromClass([ProjectAppDelegate class]));immediately before this statement, insert statements such as the following.
NSLog(@"This is output produced by NSLog.");
int i = 10; NSLog(@"The value of i is %d.", i);
CGFloat f = 3.14159; NSLog(@"The value of f is %g.", f);
NSString *s = @"How are you?"; NSLog(@"The value of s is %@.", s);
CGPoint p = CGPointMake(10.0, 20.0); NSLog(@"The value of p is (%g, %g).", p.x, p.y);
CGRect r = CGRectMake(0.0, 0.0, 360.0, 480.0); NSLog(@"The value of r is (%g, %g), %g by %g.", r.origin. x, r.origin.y, r.size.width, r.size.height );
//There is only one object of class UIDevice, and it already //exists. Get the address of this object. UIDevice *device = [UIDevice currentDevice]; NSString *version = device.systemVersion; NSLog(@"The version of iOS is %@.", version);
2014-06-08 14:58:51.224 Project[1080:60b] The version of iOS is 7.1.
//There is only one object of class UIScreen, and it already //exists. Get the address of this object. UIScreen *screen = [UIScreen mainScreen]; CGRect bounds = [screen bounds]; NSLog(@"Origin is (%g, %g), dimensions are %g by %g.", bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height );
2014-06-08 15:00:53.834 Project[1104:60b] Origin is (0, 0), dimensions are 320 by 568.The new statement(s) must be inserted before the call to
UIApplicationMain
,
because we never return from this call.
NSLog
.
Don’t worry about the “root
view
controller”
warning: we will create a view controller
later
in the course.
2014-06-08 15:00:53.904 Project[1104:60b] Application windows are expected to have a root view controller at the end of application launchWhen you select
The
Project.zip
file contains 16 files in 15 subdirectories,
starting with the
Project
directory itself.
Shown below are
the one file that we edited
(main.m
)
and another pair of files
(ProjectAppDelegate.h
and
ProjectAppDelegate.m
).
You can save the
Project.zip
file on your disk.
To re-open the project,
double-click on
Project.zip
,
double-click on the
Project
folder,
and double-click on the
Project.xcodeproj
file.
This will open the project in Xcode,
and you can press the Run button.
main.m
.
We added calls to
NSLog
to this file.ProjectAppDelegate
.
We did not edit these two files.
In the current Xcode and iOS, the function
main
in the file
main.m
int main(int argc, char *argv[]) { @autoreleasepool { return UIApplicationMain(argc, argv, nil, NSStringFromClass([ProjectAppDelegate class])); } }In older versions of Xcode and iOS, the function
main
in the file
main.m
int main(int argc, char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; int retVal = UIApplicationMain(argc, argv, nil, nil); [pool release]; return retVal; }
application:didFinishLaunchingWithOptions:
in the file
ProjectAppDelegate.m
,
change the window’s
whiteColor
to
yellowColor
.
Then run the project again.