Skip to content

Data types

In this tutorial we cover the following topics

  • Data types sources of informations
  • Excercise 1
  • Excercise 2
  • Hint 1 for the exercises
  • Hint 2 for the exercises


Data types sources of informations



Excercise 1: class for multidimensional (2D) array

    Assumptions

  • Class should allow to store objects in a dynamic 2D array.


Excercise 2: runners log application

    Assumptions

  • Application should read data from a text file.
  • Each line describes one training.
  • Training data are expressed in the form
  • Not all training data are obligatory - some of them may be missing.
  • The following data are defined
    • Training date
    • Training time
    • Distance
    • Time
    • Equipment (for example shoes)
    • You may also add your own data types
  • The user should have a menu with options like
    • Print total distance
    • Print total training time
    • Print an average speed
    • Print total distence per week
    • etc


Hint 1 for the exercises

Simple application which reads some data from a file, creates an array and puts this data into array. Note that the following code is just a hint so it doesn't work as 2D array but as 1D array. Anyway some names and comments related to 2D array were used to help implement desired solution.

Tested with a file

should return something similar to


2016-03-18 16:55:34.635 ReadFileTest[14412:1484597] Use path: /Users/fulmanp/Desktop/iOS/tutorials/ReadFileTest/data.txt
2016-03-18 16:55:34.643 ReadFileTest[14412:1484597] At index 0 we have: foo_0
2016-03-18 16:55:34.643 ReadFileTest[14412:1484597] At index 1 we have: ---
2016-03-18 16:55:34.643 ReadFileTest[14412:1484597] At index 2 we have: foo_2
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 3 we have: ---
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 4 we have: ---
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 5 we have: ---
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 6 we have: ---
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 7 we have: foo_7
2016-03-18 16:55:34.644 ReadFileTest[14412:1484597] At index 8 we have: ---
2016-03-18 16:55:34.645 ReadFileTest[14412:1484597] At index 9 we have: ---
Program ended with exit code: 0


Hint 2 for the exercises
    Assumptions

  • Application should read data from a text file.
  • Each line describes one training.
  • Training data are expressed in the form
  • One training data should be represented in application as an object.
  • All training data (object) should be collected in an array.


2016-03-31 18:48:21.108 projekcik[1428:104176] 2016-03-13 1000 5
2016-03-31 18:48:21.109 projekcik[1428:104176] 2016-03-15 1500 7
2016-03-31 18:48:21.109 projekcik[1428:104176] 2016-03-22 2000 9
Program ended with exit code: 0

If you want you can use argc and argv arguments to pass file name to the application. To test it in Xcode please visit Scheme Editor settings page (you can use command + shift + <)

  1. From the Scheme toolbar menu, choose a scheme.
  2. From the same menu, choose Edit Scheme to display the scheme dialog.
  3. In the left column, select Run.
  4. To specify runtime arguments, click Arguments and then click the Add button.
  5. Click Close.
  6. Click the Run button or choose Product > Run.