Re: convert string to object?
Re: convert string to object?
- Subject: Re: convert string to object?
- From: Chris Hanson <email@hidden>
- Date: Mon, 1 Dec 2003 16:41:15 -0600
On Dec 1, 2003, at 12:17 PM, Janice M. Cheung wrote:
values = (NSDictionary)array.objectAtIndex(i);
obj = values.objectForKey("DEPARTMENT_NAME");
strDeptName=obj.toString();
allDeptName.addObject(strDeptName);
A few tips from the Coding Style Police.
WebObjects builds heavily on Key-Value Coding, which relies on certain
naming conventions being followed. Specifically it relies on
smalltalkStyleNaming, where identifiers are mixed-case using internal
capitalization and start with a lower-case letter (possibly with a
leading underscore).
So for the above, I'd try to avoid using dictionaries with keys like
"DEPARTMENT_NAME" because it makes it harder to switch to using real
objects and accessing them via Key-Value Coding. So instead of
values.objectForKey("DEPARTMENT_NAME") I'd use
values.valueForKey("departmentName") and adjust the rest of my code to
match.
String qualifier;
qualifier = "institution.institutionLabel = ' " +
m_InstSelected + " ' and departmentName = ' " +m_strDvDeptSelected + "
' ";
EOQualifier qual =
EOQualifier.qualifierWithQualifierFormat(qualifier, null);
I'd write the above as
EOQualifier = EOQualifier.qualifierWithQualifierFormat(
"institution.institutionLabel = '%@' and departmentName = '%@'",
selectedInstitutionLabel, selectedDepartmentName);
In particular, I strongly recommend *avoiding* the use of MFC-style
"m_blah" names when doing WebObjects and Cocoa development because they
won't work with Key-Value Coding.
I also strongly recommend spelling out words rather than abbreviating
them; a small amount of additional typing can save you *lots* of
maintenance effort in the future. Which is easier to understand at a
glance, "setM_dvDepts" or "setDepartments"?
-- Chris
--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.