iPhone workshop
Transcript of iPhone workshop
-
8/6/2019 iPhone workshop
1/40
-
8/6/2019 iPhone workshop
2/40
Objectives
Learn Debug Mode and Release ModeLearn Debug Mode and Release Mode
Learn LogLearn Log
Learn DebugLearn Debug iPhoneiPhone ApplicationApplication
-
8/6/2019 iPhone workshop
3/40
Outcome
Understand how to debuggingUnderstand how to debugging iPhoneiPhone
application.application.
-
8/6/2019 iPhone workshop
4/40
Debugging for iPhone
application
In the development ofIn the development of applications,applications, youyou
oftenoften encounterencounter the followingthe following problems: Syntaxproblems: Syntax
Error, Execution Error (e.g. unexpected resultsError, Execution Error (e.g. unexpected results
came out, system stopped execution, etc.).came out, system stopped execution, etc.).
WeWe explainexplain howhow to outputto output the log informationthe log information andand
debuggingdebugging iPhoneiPhone application.application.
-
8/6/2019 iPhone workshop
5/40
Debug Mode and
Release Mode
YouYou cancan select the format of the Buildselect the format of the Build code:code:
iPhoneiPhone DeviceDevice oror Simulator.Simulator.
iPhoneiPhone // iPadiPad cancan connectconnect via USBvia USB to theto the MacMac
machine.machine.
YouYou cancan testtest your application onyour application on youryour iPhoneiPhone
devicedevice
-
8/6/2019 iPhone workshop
6/40
Debug Mode and
Release Mode
Figure 5Figure 5--1,1, in thein the development process,development process,
youyou cancan select the format of the Buildselect the format of the Build code:code:
-
8/6/2019 iPhone workshop
7/40
Debug Mode and
Release Mode
In selectingIn selecting iPhoneiPhone or Simulator, theor Simulator, the
mainmain difference is thatdifference is that the resources onthe resources on iPhoneiPhone
are less than the Simulator (such as the CPU isare less than the Simulator (such as the CPU is
not so fast and the memory is not sufficient).not so fast and the memory is not sufficient).
You must eventually test the application onYou must eventually test the application on
iPhoneiPhone device to see if the speed is acceptable.device to see if the speed is acceptable.
-
8/6/2019 iPhone workshop
8/40
Build mode
Choose between two output modes, i.e. Debug andChoose between two output modes, i.e. Debug andRelease.Release.
Debug modeDebug mode -- moremore debugging information.debugging information.
Release modeRelease mode -- faster andfaster and more optimized.more optimized.
When you deploy your application to theWhen you deploy your application to theusers,users, youyou need to select Release mode.need to select Release mode.
Developers are generally using Debug mode.Developers are generally using Debug mode.
-
8/6/2019 iPhone workshop
9/40
Build mode
FigureFigure 55--2, after build, the build contents are put2, after build, the build contents are put
under the build folder.under the build folder.
-
8/6/2019 iPhone workshop
10/40
Log
WeWe often need tooften need to outputoutput aa loglog message.message.
LogLog is oftenis often divided intodivided into multiple levels, e.g.:multiple levels, e.g.:
onlyonly outputoutput error messageserror messages
output debug informationoutput debug information
UseUse NSLogNSLog method tomethod to loglog information.information.
-
8/6/2019 iPhone workshop
11/40
Log
IfIf you do not knowyou do not know NSLogNSLog method,method, then you canthen you can
highlighthighlight NSLogNSLog and rightand right--clickclick
In theIn the popup menu, selectspopup menu, selects "Find Text in"Find Text in
Documentation (see Figure 5Documentation (see Figure 5--3)3)
You will get the usage information of thatYou will get the usage information of that
method.method.
-
8/6/2019 iPhone workshop
12/40
Log
Find Text in Documentation (Figure 5Find Text in Documentation (Figure 5--3)3)
-
8/6/2019 iPhone workshop
13/40
Log
As shownAs shown in Figurein Figure 55--4,4, wewe will demonstratewill demonstrate howhow
to addto add and view the log.and view the log.
-
8/6/2019 iPhone workshop
14/40
Log
FigureFigure 55--44 -- Definition ofDefinition of NSLogNSLog
-
8/6/2019 iPhone workshop
15/40
Log
UnderUnder changeNumberchangeNumber method, add anmethod, add an NSLogNSLog
method to output some remind messages.method to output some remind messages.
- (IBAction) changeNumber: (id) sender
{int sliderValue = slider.value;
number.text = [NSString stringWithFormat: @ "% d", sliderValue];NSLog (@ "This is changeNumber method");
}
-
8/6/2019 iPhone workshop
16/40
Log
Save andSave and run the program,run the program, movemove the sliderthe slider
several times.several times.
SingleSingle--click "gab"click "gab" buttonbutton (the(the
rightmostrightmost blackblack button) tobutton) to open theopen the DebuggerDebugger
Console.Console.
Log messageLog message is displayed in theis displayed in the debuggerdebugger
consoleconsole
-
8/6/2019 iPhone workshop
17/40
Log
[5[5--5] Open Debugger Console5] Open Debugger Console
-
8/6/2019 iPhone workshop
18/40
Log
[5[5--6] Debugger Console6] Debugger Console
-
8/6/2019 iPhone workshop
19/40
Log
Debugger ConsoleDebugger Console also showsalso shows system message.system message.
For example, if your application stoppedFor example, if your application stopped
execution due to some exceptions, then you mayexecution due to some exceptions, then you may
want to check the information here.want to check the information here.
-
8/6/2019 iPhone workshop
20/40
Debug iPhone Application
SupposeSuppose the followingthe following program,program, sliderValuesliderValue waswas
written wrongly as written wrongly as slideValueslideValue
- (IBAction) changeNumber: (id) sender
{
int sliderValue = slider.value;number.text = [NSString stringWithFormat: @ "% d", slideValue];/ / Originally sliderValue at the end
NSLog (@ "This is changeNumber method");
}
-
8/6/2019 iPhone workshop
21/40
Debug iPhone Application
when youwhen you click "Build and Run", youclick "Build and Run", you will seewill see
thethe error message:error message:
"" ''slideValueslideValue' undeclared' undeclared ""
-
8/6/2019 iPhone workshop
22/40
Debug iPhone Application
[5[5--7] Build error7] Build error
-
8/6/2019 iPhone workshop
23/40
Debug iPhone Application
Under the window, on the left, it shows an error and aUnder the window, on the left, it shows an error and awarning.warning.
The right also shows the same message.The right also shows the same message.
DoubleDouble--click the small red icon, it will open Buildclick the small red icon, it will open BuildResult windowResult window
The window displays the error and warning message.The window displays the error and warning message.
-
8/6/2019 iPhone workshop
24/40
Debug iPhone Application
[5[5--8] Build Result Windows8] Build Result Windows
-
8/6/2019 iPhone workshop
25/40
Breakpoint Debug
Set a breakpoint on a line of the program.Set a breakpoint on a line of the program.
When you debug a program, the system will pause onWhen you debug a program, the system will pause on
this line.this line.
At this point, you can check a lot of information, suchAt this point, you can check a lot of information, suchas whether the value of the variable is as expected.as whether the value of the variable is as expected.
You can always set a breakpoint in any line that youYou can always set a breakpoint in any line that you
suspect it may contain error.suspect it may contain error.
-
8/6/2019 iPhone workshop
26/40
Breakpoint Debug
You can set a breakpoint in the first line of yourYou can set a breakpoint in the first line of your
program and select line by line executionprogram and select line by line execution
The program will be executed line by line.The program will be executed line by line.
Here, we demonstrate how to use breakpointHere, we demonstrate how to use breakpointdebugging function.debugging function.
-
8/6/2019 iPhone workshop
27/40
Breakpoint Debug Set
Breakpoint
On the left side of the code, click the line whereOn the left side of the code, click the line where
you want to set a breakpoint.you want to set a breakpoint.
Then, you will see a small blue arrow is added.Then, you will see a small blue arrow is added.
At the same time, the button in the tool bar,At the same time, the button in the tool bar,Build and Run becomes Build and Debug.Build and Run becomes Build and Debug.
-
8/6/2019 iPhone workshop
28/40
Breakpoint Debug Set
Breakpoint
[5[5--9] Set Breakpoint9] Set Breakpoint
-
8/6/2019 iPhone workshop
29/40
Breakpoint Debug Set
Breakpoint
SingleSingle--click "Build and Debug" button to debug.click "Build and Debug" button to debug.
Firstly, the system will display a normalFirstly, the system will display a normal iPhoneiPhone
window.window.
Moving the slider, the system jumps to the lineMoving the slider, the system jumps to the linewhere you set the breakpoint.where you set the breakpoint.
-
8/6/2019 iPhone workshop
30/40
Breakpoint Debug Set
Breakpoint
[5[5--10] application startup10] application startup
-
8/6/2019 iPhone workshop
31/40
Breakpoint Debug Set
Breakpoint
[5[5--11] to the Breakpoint execution11] to the Breakpoint execution
-
8/6/2019 iPhone workshop
32/40
Breakpoint Debug
On the left side of gab button, singleOn the left side of gab button, single--click Showclick ShowDebugger button (yellow button).Debugger button (yellow button).
Then, it will open a debugger windowThen, it will open a debugger window
You can also click Run from the menu to startYou can also click Run from the menu to startdebugger windows.debugger windows.
-
8/6/2019 iPhone workshop
33/40
-
8/6/2019 iPhone workshop
34/40
Breakpoint Debug -
Debugger windows
When you move the mouse to each variable, the codeWhen you move the mouse to each variable, the codebelow will display the current value of the variablebelow will display the current value of the variable
In column of the "Build and Debug" button, you willIn column of the "Build and Debug" button, you will
see all debug buttons which are similar to most ofsee all debug buttons which are similar to most of
the debugging tools.the debugging tools.
-
8/6/2019 iPhone workshop
35/40
Breakpoint Debug -
Debugger windows
Step Over: Executes the next line of code, if theStep Over: Executes the next line of code, if thecurrent line is a method call, it will not enter thecurrent line is a method call, it will not enter theinternal methods.internal methods.
Step Into: Enter the methodStep Into: Enter the method
Step Out: Skip the current method and executes toStep Out: Skip the current method and executes tothe end of the current methodthe end of the current method
Continue: Continue executing the current code. IfContinue: Continue executing the current code. Ifthere is the next breakpoint, then it will stop at thethere is the next breakpoint, then it will stop at thenext breakpoint.next breakpoint.
-
8/6/2019 iPhone workshop
36/40
Breakpoint Debug -
Debugger windows
[5[5--13] Display values of variable13] Display values of variable
-
8/6/2019 iPhone workshop
37/40
Breakpoint Debug -
Debugger windows
Finally, you singleFinally, you single--click "Continue" button toclick "Continue" button tocontinue executing the application.continue executing the application.
If you want to get rid of breakpoint, you canIf you want to get rid of breakpoint, you can
rightright--click the breakpoint, from the popclick the breakpoint, from the pop--upup
menu, select "Remove Breakpoint".menu, select "Remove Breakpoint".
-
8/6/2019 iPhone workshop
38/40
Breakpoint Debug -
Debugger windows
[5[5--14] Remove breakpoint14] Remove breakpoint
-
8/6/2019 iPhone workshop
39/40
Try it out now
Please also finish the exercisePlease also finish the exercise
-
8/6/2019 iPhone workshop
40/40
End