|
|
Directly from GHUnit, a small note about which environment variables to set while developing for the iPhone.
Environment Variable: Default: Set to:
NSDebugEnabled NO YES
NSZombieEnabled NO YES
NSDeallocateZombies NO NO (or YES)
NSHangOnUncaughtException NO YES
NSAutoreleaseFreedObjectCheckEnabled NO YES
Actually, I keep forgetting them, so I hope this will be useful to me.
Here an example that shows how to set those environment variables.
 Setting iPhone development variables in XCode
To configure a Rails application in order to use SQLite3 please follow the following steps:
sudo apt-get install sqlite3 swig libsqlite3-ruby libsqlite3-dev
sudo gem install sqlite3-ruby
Then create a Rails application as usual and update the environment.rb file in the following way
Rails::Initializer.run do |config|
...
config.gem 'sqlite3-ruby', :lib => "sqlite3"
...
end
If you work with subversion, for sure you had the problem to tell to subversion to ignore a folder inside your working copy. This happens for example if your IDE builds the sources in a folder inside your working copy. From the very first commit you’ll start noticing that subversion wants to add that “build” folder to your repository. But, obviously, this is not a good practice.
So you can tell subversion to ignore a folder. Just move in the folder that contains the folder you want to be ignored by subversion and type the following command.
svn propset svn:ignore <dir_you_want_to_be_ignored> .
The “dot” at the end is important! It means you’re specifying which folders of the current folder you want to be ignored.
Please note that <dir_you_want_to_be_ignored> should be written without trailing slashes. So for example if you want the build directory not to be managed by subversion, type…
svn propset svn:ignore build .
And not…
svn propset svn:ignore build/ .
This is a quick tip. I always forget how to do it, so I wrote that little note.
This picture can be useful to those of you that develop graphics targeted to the iPhone platform. Here you see the dimensions in pixel of an iPhone windows in some of the most common configurations. Click on the image to enlarge it.

This is a small snippet, useful whenever you want to convert a floating point number in a string with a fixed number of decimal digits.
NSNumberFormatter *format = [NSNumberFormatter new];
[format setMaximumFractionDigits:1];
NSNumber *aNumber = [[NSNumber alloc ] initWithDouble:54.4235264];
NSString label = [[NSString alloc] initWithFormat:@"The number is %@", [format stringForObjectValue:aNumber]];
[distance release];
[format release];
Obviously the NSNumberFormatter class offers plenty of other method you can use to customize the way your numbers should be rendered.
I’m working to an iPhone application with a TabBar on the footer area. Among the others there are a “Home” button and an “Account” button. The first allows the user to see a view that gives an overview of the application. The latter shows the view that the user uses to manage his/her account.
If the user is not currently logged in, in the “Home” view a warning message is displayed. There is also a button that is supposed to show the “Account” view. In that way it’s more clear for the user that he/she should log in.
How can you accomplish that task ? That post shows you the way I followed.
The big idea is to retrieve the TabBarController from the “Home” controller, and programmatically change the current view. To do that, the “Home” controller should get a reference to the TabBarController. But you can easily set that dependency in Interface Builder. You only need to provide a suited IBOutlet to the Home controller.
That is the tree structure of the controllers and views, as built in the interface builder.

So, that’s an excerpt of the HomeController showing you only what is really needed to reach our goal. The goToRegistrationPage method will execute programmatically the switch to the account page.
@interface HomeViewController : UIViewController {
UITabBarController *mainTabBarController;
}
@property(nonatomic, retain) IBOutlet UITabBarController *mainTabBarController;
-(IBAction) goToRegistrationPage;
Now, we only need to set in Interface Builder the link between the the IBOutlet we just created and the Tab Bar Controller. Here’s the result.
As you can see the mainTabBarController outlet is linked to the Tab Bar Controller we want to manage programmatically. That’s not difficult at all. Let’s give a look to the goToRegistrationPage method.
-(IBAction) goToRegistrationPage {
mainTabBarController.selectedIndex=3;
}
Quite easy, isn’t it ?
Now the user click on the button on the Home view and he/she get exactly the same result of touching the tab bar button in the footer.
Hope you can find it useful.
E’ arrivata oggi conferma della mia iscrizione all’elenco certificatori CENED, con numero 11810. Date un’occhiata su http://www.cened.it/elenco_certificatori.
Do you need to provide your Objective-C class with a read-only computed property ? Not a big task… just define the property in the .h file as usually, remembering to specify “readonly” among the attributes. In the .m implementation file you won’t use the @synthesize keyword to automatically generate the getter and the setter methods of the property as you probably usually do. Instead you’ll write the getter method. This allows you to write the code to compute the property.
Here’s an example, don’t take it as an example of good programming, it’s only to demonstrate the use of read-only computed properties.
The Booking class has a date property. This is awkwardly not a NSDate, but a NSString. This is because the date is actually loaded from an XML service and the original programmer choose to store it as a NSString. Thus, we’d like to have a nice NSDate property, standing by the NSString property. Here the fact is that we cannot add another NSDate property in the standard way, to avoid the two dates be unrelated. What we really need is that the NSDate property would be computed from the string version of the date. Thus, we need a property whose value is computed starting from the value of another property and not stored in an instance variable as we’re used to do.
So, here’s the code… first of all the .h file
#import <Foundation/Foundation.h>
@interface Booking : NSObject {
NSString *date;
}
@property(nonatomic,retain) NSString *date;
@property(nonatomic,readonly) NSDate *nsDate;
@end
As you can see, we declared the read-only property “nsDate” but there is no any instance variable to store it. Let’s go ahead with the .m implementation file.
#import "Booking.h"
#import "Conversion.h"
@implementation Booking
@synthesize date;
-(NSDate*)nsDate{
//Here an utility method is used to convert the date from NSString to NSDate.
return [Conversion toNSDate:date];
}
@end
So, here’s the trick. Just write the code that computes the value of the property in the getter method.
Stavo lavorando in una banca ad un porting verso tecnologie attuali di un sistema esistente da qualche anno. Nell’ambito di tale progetto dovevo realizzare un modulo del sistema il cui compito era sostanzialmente quello di estrarre da DB dei record con un campo data maggiore o uguale alla data di odierna, eseguire alcune elaborazioni e scriverli in un file da inviare ad un sistema a valle per una successiva elaborazione.
Il campo che conteneva la data era un campo CHAR di 8 caratteri e ci era stato assicurato che tutte le date erano nel formato YYYYMMDD. In questo modo per selezionare i record con una data maggiore di quella odierna si poteva sruttare l’ordinamento alfabetico e ad esempio scrivere una condizione del tipo
data >= '20052310'
Facendo qualche test mi sono però accorto che in realtà nel db c’erano record con date nel formato DD/MM/YY. La condizione restituiva perciò anche record con valori pari ad esempio a “23/12/98″, “20/10/89″ ed in generale qualsiasi data il cui giorno fosse maggiore o uguale a 20. Questo perchè, in ordine strettamente alfabetico, “23/12/98″ segue “20052310″. I record che avrebbero dovuto essere stati estratti erano qualche decina, invece la presenza delle date nel formato inatteso, ne faceva salire il numero a qualche centinaio.
Dopo un consulto con un programmatore che lavorava alla manutenzione del sistema decidemmo di lasciare i dati scorretti sul DB ma eliminarli nella query di selezione. E quindi in dettaglio la condizione diventò…
data >= '20052310' AND data not like '__/__/__'
Tutto sembrava andare per il meglio, il file contenente i risultati divenne molto più corto e l’elaborazione successiva ne avrebbe certamente giovato.
Mi pareva comunque strano come per i sette o otto anni precedenti il sistema a valle avesse elaborato ogni giorno centinaia di record inutili senza che sollevare il minimo problema.
In fase di test un file campione genenrato dal nuovo sistema doveva essere caricato dal sistema successivo. Il giorno del test ricevetti una telefonata ed il tecnico all’altro capo del filo mi disse che il test era fallito poichè alcuni record contenuti nel file non trovano riscontro nei dati di altre tabelle. Pronto ad affrontare una noiosissima sessione di debug mi accorsi che nel file prodotto non trovavo minimamente traccia dei record errati a cui si era riferito il tecnico.
Dopo una ricerca trovai i record incriminati nel file che era stato prodotto non dal nostro nuovo sistema ma dal vecchio sistema correntemente in produzione. Insomma, per una svista, il tecnico aveva sottoposto a test non il file prodotto dal nuovo sistema, ma quello prodotto quotidianamente, ormai da anni, dal sistema in produzione. E ci aveva trovato pure degli errori!
In Lombardia è ormai d’obbligo che qualsiasi appartamento acquistato sia accompagnato dall’attestazione di certificazione energetica. Questo documento riporta alcuni indicatori riferiti all’appartamento in vendita, tra i quali uno dei più importanti è il fabbisogno energetico dell’appartamento. Tale parametro è un’indice di quanta energia è necessaria per ogni metro quadrato di superficie allo scopo di garantire durante il periodo invernale una temperatura interna costante di 20°C. Tale parametro è il risultato di una simulazione che tiene conto delle dimensioni e delle caratteristiche costruttive dell’appartamento e degli impianti di riscaldamento presenti.
A questo punto è lecito aspettarsi che i proprietari di casa che stanno vendendo potranno variare il prezzo di vendita in base alla classe energetica dell’edificio: più la classe è buona, minori sono i consumi previsti, più economico sarà il mantenimento della casa e maggiore potrebbe dunque essere il prezzo di vendita.
Tuttavia possono sorgere nell’acquirente delle lecite domande:
- Mi viene chiesto un esborso maggiore rispetto ad un equivalente appartamento di classe G poichè l’appartamento è in classe B. Questo sovrapprezzo è giustificato oppure no?
- Quanto pagherò ogni anno per il riscaldamento dell’appartamento in classe D ?
- Se compro o affitto un appartamento in classe C, quant’è il risparmio ogni anno rispetto ad un appartamento di vecchia costruzione, tipicamente in classe G ?
Il seguente specchietto aiuta a rispondere a queste domande. Le prime colonne indicano le classi energetiche utilizzate in Lombardia con i rispettivi intervalli di fabbisogno energetico per metro quadro.
Le colonne più a destra mostrano rispettivamente il fabbisogno totale per un appartamento di 40 metri quadri in una determinata classe, il costo previsto per il riscaldamento ed infine il risparmio che si ha rispetto ad un equivalente appartamento di classe G, espresso sia in moneta sonante, che in valore percentuale.
| Classe |
Fabbisogno energetico |
|
Superficie di riferimento in m² |
40 |
|
| min |
max |
medio |
|
Fabbisogno |
Spesa |
Risparmio su classe G |
| kWh/m²yr |
kWh/m²yr |
kWh/m²yr |
|
kWh/yr |
€/yr |
€/yr |
% |
| A+ |
0 |
14 |
12,6 |
|
504 |
47,24 |
740 |
0,94 |
| A |
14 |
29 |
26,1 |
|
1044 |
97,85 |
689 |
0,88 |
| B |
29 |
58 |
52,2 |
|
2088 |
195,69 |
592 |
0,75 |
| C |
58 |
87 |
78,3 |
|
3132 |
293,54 |
494 |
0,63 |
| D |
87 |
116 |
101,5 |
|
4060 |
380,51 |
407 |
0,52 |
| E |
116 |
145 |
130,5 |
|
5220 |
489,23 |
298 |
0,38 |
| F |
145 |
175 |
160 |
|
6400 |
599,82 |
187 |
0,24 |
| G |
175 |
|
210 |
|
8400 |
787,27 |
0 |
0 |
Quindi nel caso stiate per acquistare un monolocale in classe sappiate che ragionevolmente il risparmio energetico rispetto ad un monolocale trentennale non può che aggirarsi sui 1000 euro all’anno. Buon acquisto.
|
|