Amazon.com Widgets Instantiate with a string value
Welcome, Guest. Please login or register.
Did you miss your activation email?
August 22, 2014, 06:33:19 PM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ iOS Programming
| |-+ General Questions
| | |-+ Instantiate with a string value
Pages: [1] Go Down
Print
Author Topic: Instantiate with a string value (Read 578 times)
crlogic
Newbie
*
Posts: 1






on: November 17, 2011, 05:57:29 PM

A beginner explanation of a class is often something simple like:
-- Class is Person
-- Instances of Person might be:  Jim, Joe, Bob, etc.
In this scenario the names are known.

Suppose I have an app that is getting names from user input.  I want to create an array of Person objects.  I won't know the names until they are provided by the user.

How do I create instances of Person using the names that are provided dynamically?

My requirement will actually be dosimeter serial data I am reading from a socket (which I have no idea how to do yet either).  Each dosimeter has a unique ID.  ID's are usually 6 digits but can vary.  By the ID, I can tell what type of dosimeter it is and therefor what data it is providing.  There will actually be variations in the class based on the dosimeter mode.  My thought is to create an array of dosimeter objects.  I will be using the array as the active dataset.  Each dosimeter object will have thresholds, etc that will trigger alarms/alerts.  Data will be display various ways based on dosimeter data combined with other inputted data such a job id's.

I would welcome any input ... thanks
Logged
fujilla
Global Moderator
Sr. Member
*****
Posts: 276


WWW




Reply #1 on: November 18, 2011, 12:25:24 PM

In basic terms you would need say a UITextField and/or a UIButton to accept the data has been entered.

Then when the data has been entered either by the tapping of the UIButton or tapping the Return key on the keyboard the data is sent in to an instance of your Person class.

Something you have not mentioned is whether or not the data entered would need to be stored permanently.  If so then you would save it one of a few different ways (plist, sqlite DB, core data).

Not knowing your knowledge in Objective-C/iOS Programming I would say begin by reading something like Steve's book, then move on to an iOS/OSX programming book.

Nick
http://myfirstiphoneapp.co.uk
http://easyintervalsapp.co.uk
http://heatingoilmobile.co.uk
Last Edit: November 18, 2011, 12:28:32 PM by fujilla Logged
Fred
Newbie
*
Posts: 46






Reply #2 on: November 28, 2011, 01:26:48 PM

I have to second the recommendation to read Steve's book which has examples of instantiating objects.  Basically you need to set properties for the object that includes a name and other identifying information.  You need an initWith (or similar) method that will assign the input name and other information to the new instance of the object.  As long as you create a new object with each new input, they will all be unique and contain their own information.  They can be stored in an array or other structure of your choosing depending on your access need.

Fred
Logged

Fred
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.