• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: convert string to object?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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.

  • Follow-Ups:
    • Re: convert string to object?
      • From: "Janice M. Cheung" <email@hidden>
References: 
 >RE: Missing WOExceptionPage (From: "Erlandsson Martin" <email@hidden>)
 >convert string to object? (From: "Janice M. Cheung" <email@hidden>)
 >Re: convert string to object? (From: arturo <email@hidden>)
 >Re: convert string to object? (From: "Janice M. Cheung" <email@hidden>)

  • Prev by Date: Migration from windows to Mac
  • Next by Date: Number formatters, validateValueForKey & dirty editing contexts
  • Previous by thread: Re: convert string to object?
  • Next by thread: Re: convert string to object?
  • Index(es):
    • Date
    • Thread