objective c - new to ios - not sure how property is being used -
i have been going through following tutorial , came across line dont understand how works:
nsarray *upcomingweather = [self.weather upcomingweather];
i have tried understand how works, , spent long hours. here know. upcomingweather method extracts json portion , returns array. however, have no idea purpose for: self.weather <-- no clue how being used. can explain significance of self.weather ?
[self.weather upcomingweather];
there no functions in objective-c, there messages. self.weather
object send message upcomingweather
. these messages similar function 1 big difference : if object nil, exception silenced , no error when sending message.
furthermore, in given case first part in [%@ %@] object, , second 1 message sending. in case have more 1 parameter use :
[self.weather upcomingweather:parameterone andwithparametertwo:parametertwo];
the important thing mention here that, when declaring funtions, have 2 parts : private , public. send message accessing public part , use private part in function. better understand take @ example:
-(void) test:(nsstring*)po andwithparametertwo(nsstring*)pw{}
po
, pw
private parts - use them in method, while andwithparameterstwo
public part , access them when send message.
edit:
“wait minute!”, might thinking. [self.weather upcomingweather]? if self.weather plain old nsdictionary, how know “upcomingweather” is? make easier display data, added couple of helper categories on nsdictionary in starter project: nsdictionary+weather nsdictionary+weather_package these categories add handy methods make little easier access data elements. want focus on networking part , not on navigating nsdictionary keys, right?
you right, self.weather
dictionary, guy created helper categories, nsdictionary extended(among others) method:
- (nsarray *)upcomingweather { nsdictionary *dict = self[@"data"]; return dict[@"weather"]; }
so when send upcomingweather
message, method called.
Comments
Post a Comment