Changes between Version 14 and Version 15 of AppleCurrencyConverterWritingLisp


Ignore:
Timestamp:
Jan 19, 2008, 4:04:35 PM (12 years ago)
Author:
mikel
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AppleCurrencyConverterWritingLisp

    v14 v15  
    8484Once again we use the Objective-C bridge to define an Objective-C class. This time, we provide several instance-variable definitions in the class. We also explicitly define the names of accessor functions for each of them. The :FOREIGN-TYPE initargs enable us to specify the types of the fields in the foreign (Objective-C) class.
    8585
     86Each field in the definition of the !ConverterController class is an outlet that will be used to store a reference to one of the UI fields that you created in !InterfaceBuilder. For example, amount-field will be connected to the "Amount" text field.
     87
     88Why did we spell the name "amount-field" in Lisp code, and "amountField" when creating the outlet in !InterfaceBuilder? The Objective-C bridge automatically converts Lisp-style field names (like "amount-field") to Objective C-style field names (like "amountField"), when handling class definitions.
     89
     90The converter field at launch time contains a reference to the Converter object, whose class definition is in the previous section.
     91
     92The final piece of the implementation is a definition of the "convert:" method. This is the method that is called when a user clicks the "Convert" button in the user interface.
     93
     94{{{
     95(objc:defmethod #/convert: ((self converter-controller) sender)
     96  (let* ((conv (converter self))
     97         (dollar-field (dollar-field self))
     98         (rate-field (rate-field self))
     99         (amount-field (amount-field self))
     100         (dollars (#/floatValue dollar-field))
     101         (rate (#/floatValue rate-field))
     102         (amount (#/convertCurrency:atRate: conv dollars rate)))
     103    (#/setFloatValue: amount-field amount)
     104    (#/selectText: rate-field self)))
     105}}}
     106
     107
     108
    86109[AppleCurrencyConverter Start] [AppleCurrencyConverterCreatingaLispFile Previous]