|
|
#1 |
|
Objective-C / Java Question
Hey
So I'm learning Objective-C with a Java background. It turns out quite good atm. I'm dutch and learning it with a English book. Sometimes I'm not understanding things, but that's why i'm asking it here! In Java you have a Default Constructor, and you can edit the constructor like in the example. Code:
public Date (int day, int month, int year){
setYear(day);
setMonth(month);
setDay(year);
}
Further I know you can't really use get in your Getter methods because Cocoa would argue sometimes. Code:
public class Date {
private int year;
private int month;
private int day;
public Date (){
}
public Date (int day, int month, int year){
setYear(day);
setMonth(month);
setDay(year);
}
public void setYear(int year){
}
public void setMonth(int month){
}
public void setDay(int day){
}
public int getYear(){
}
public int getMonth(){
}
public int getDay(){
}
}
|
|
|
|
0
|
|
|
#2 | ||
|
Quote:
Code:
-(void)initWithDay:(int)day withMonth:(int)month withYear:(int)year; Date *d = [[Date alloc] initWithDay:1 withMonth:1 withYear:2013]; Quote:
|
|||
|
|
0
|
|
|
#3 |
|
You can also create custom getters and setters if you'd like:
Code:
@property(getter=getFoo, setter=setFoo:) NSData *foo; |
|
|
|
0
|
|
|
#4 |
|
Or just skip properties altogether... There's no reason you can't just use setters and getters (but there's less boilerplate code involved if you use properties.)
|
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 06:11 AM.







Linear Mode
