April 24, 2018, 11:05:54 AM
Welcome,
Guest
. Please
login
or
register
.
Did you miss your
activation email?
1 Hour
1 Day
1 Week
1 Month
Forever
Login with username, password and session length
Read this please.
♦
The Great Kangaroo Escape
♦
Looking for reviews of the 4th ed on Amazon!
♦
Twitter:
@skochan
Home
Help
Search
Login
Register
Chat
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
« previous
next »
Print
Author
Topic: Instantiate with a string value (Read 1536 times)
crlogic
Newbie
Posts: 1
Instantiate with a string value
«
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
Re: Instantiate with a string value
«
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
Re: Instantiate with a string value
«
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
« previous
next »
Jump to:
Please select a destination:
-----------------------------
Programming in Objective-C, 5th edition
-----------------------------
=> General Discussions
=> Exercises
-----------------------------
Programming in Objective-C, 4th edition
-----------------------------
=> General Discussion
=> Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 14
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 20
===> Chapter 21
=> Chapter 2
=> Chapter 3
=> Chapter 4
=> Chapter 5
=> Chapter 6
=> Chapter 7
=> Chapter 8
=> Chapter 9
=> Chapter 10
=> Chapter 11
=> Chapter 12
=> Chapter 13
=> Chapter 14
=> Chapter 15
=> Chapter 16
=> Chapter 17
=> Chapter 18
=> Chapter 19
=> Chapter 20
=> Chapter 21
=> Errata
===> 1st Printing
===> 2nd Printing
-----------------------------
Members' Corner
-----------------------------
=> Look What I'm Doing...
-----------------------------
Study Group
-----------------------------
=> Objective-C Quizzes
===>
Comprehensive Quiz
===> Chapter 1 - Introduction
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 15 - Numbers, Strings & Collections
===> Chapter 17 - Memory Management
-----------------------------
iOS Programming
-----------------------------
=> General Questions
-----------------------------
Programming in C, 3rd ed. (Stephen Kochan)
-----------------------------
=> Programming in C webcasts?
=> Answers to Odd-Numbered Exercises
=> Questions and Help
-----------------------------
Old Stuff
-----------------------------
=> Errata, Answers to Exercises, Code, etc.
=> Shared Code Library
=> Welcome
=>
News
=> Errata
===> 1st Printing
===> 2nd printing
=> Newbie Corner
=> Chapter Study
===> Chapter 2 - Programming in Objective-C
===> Chapter 3 - Classes, Objects, and Methods
===> Chapter 4 - Data Types and Expressions
===> Chapter 5 - Program Looping
===> Chapter 6 - Making Decisions
===> Chapter 7 - More on Classes
===> Chapter 8 - Inheritance
===> Chapter 9 - Polymorphism, Dynamic Typing, and Dynamic Binding
===> Chapter 10 - More on Variables and Data Types
===> Chapter 11 - Categories and Protocols
===> Chapter 12 - The Preprocessor
===> Chapter 13 - Underlying C Language Features
===> Chapter 15 - Numbers, Strings, and Collections
===> Chapter 16 - Working with Files
===> Chapter 17 - Memory Management
===> Chapter 18 - Copying Objects
===> Chapter 19 - Archiving
===> Chapter 21 - Writing iPhone Applications
=> Answers to Exercises
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> General Discussion
=> Program Examples
===> Chapter 2
===> Chapter 3
===> Chapter 4
===> Chapter 5
===> Chapter 6
===> Chapter 7
===> Chapter 8
===> Chapter 9
===> Chapter 10
===> Chapter 11
===> Chapter 12
===> Chapter 13
===> Chapter 15
===> Chapter 16
===> Chapter 17
===> Chapter 18
===> Chapter 19
===> Chapter 21
=> XCode 4 Help
=> Suggestions
=> Help!!!
=> Fraction Calculator Available from the App Store
=> Resources
=> Errata
===> 1st & 2nd printings
===> 3rd & 4th printings
===> 5th printing
===> Current Errata
=> Suggestion Box
=> Tips & Tricks
=> Part 3
===> Welcome to the Class
===>
Special Announcements
===> Assignments
=> Parts 1 and 2
===> Welcome to the Class
===> Questions and Discussion
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Suggestions
=> Webcast Series Part I, Sept. 1 - 24
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Oct. 1 - 27
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Questions and Discussion
===> Assignments
===> Example using hasPrefix: and hasSufix:
===> Suggestions
=> Objective-C Workshop Aug 11 - 13
=> Webcast Series Part I, Oct. 29 - Dec. 1
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Chapter 4, Exercise 7
===> Chapter 6, Exercise 4
===> Suggestions
=> Webcast Series Part II, Jan 5 - 28
===> Welcome
===>
SPECIAL ANNOUNCEMENTS
===> Assignments
===> Jan 7th Solutions
Loading...