As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Can I make POST or GET requests from an iphone application?
In this article, the second answer mentions 'Assume your class has a responseData instance variable, then.' What does this mean and how would I add one?
Thanks!
In your class's header file, there will be a section along these lines:
#interface YourClass : NSObject {
NSMutableData *responseData;
}
// Soem method declarations here
#end
Inside, the braces, add a declaration for the instance variable you want:
#interface YourClass : NSObject {
}
// Soem method declarations here
#end
I'd recommend reading The Objective-C Programming Language if this is unfamiliar to you, because there are a lot of aspects of the language that are more subtle than this.
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Just a quick question - what is the difference (if any) between:
NSObject* myObj
and
NSObject *myObj
and even
NSObject * myObj
?
From a technical point of view, it doesn't matter.
Personally I use the last option (* in the middle), but it's a matter of personal taste.
A corner case would be the definition of multiple inline declarations, like
NSObject *a, b
as opposed to
NSObject *a, *b
The first case will produce a pointer to NSObject and a NSObject (which of course is forbidden and it wouldn't compile), whereas the second one will produce two pointers.
My understanding is this is totally a style issue, however, a team of developers may wish to match style and certain [open source] projects may have guidelines they enforce. For example, here's Github's Objective-C conventions: https://github.com/github/objective-c-conventions
(they use NSObject *myObj)
There is no difference. Both variations represent a pointer readable by Objective-C.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
The syntax is legal. It'll save you about 2 seconds every time you alloc/init an object. Do you think this could be a new trend?
Again,
NSObject *obj = NSObject.alloc.init;
[NSObject new];
Saves even more and doesn't cause any religious wars.
Yes, it saves a few keystrokes, but I doubt it will catch on. See this blog post for a number of cases where using dot notation on methods rather than properties will not work. I think most people view this as a side effect of ObjC2.
Furthermore, I don't think it enhances readability at all. As soon as you want to send a message with an argument, you have to revert back to the original syntax.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I am trying to understand how the AFNetworking Framework works. But there is little detail I do not understand.
I wrote a subclass of AFHTTPclient than made it a singleton class and added a Initializer that does the following :
- (id)initWithBaseURL:(NSURL *)url {
self = [super initWithBaseURL:url];
if (self) {
[self registerHTTPOperationClass:[AFJSONRequestOperation class]];
}
return self;
}
I got this code from a tutorial I found on the internet, but I do not understand why I have to register my class for JSONRequestOperation if I want to get JSON Data back? What exactly happens under the hood if I am doing so? What does the registerHTTPOperation class exactly do?
PS: Is there a good documentation with examples and in-depth explanations of AFNetworking somewhere on the internet?
The registerHTTPOperationClass: on AFHTTPclient will use the class set to handle you request when using the getPath and postPath methods.
In your given example, the HTTPRequestOperation is set the the AFJSONRequestOperation, which means that all request to the server will be done with an instance of AFJSONRequestOperation. The AFJSONRequestOperation will try and parse the result from the server with the NSJSONSerialization class.
If you server responds with XML you should set the HTTPRequestOperation to AFXMLRequestOperation for example.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
// populate 'project' with contents of key in `gDictRoot`
NSDictionary *project = [gDictRoot valueForKeyPath:#"root.project0"];
// modify 'project' as necessary - actual code omitted for brevity
[project setValue:[someDict valueForKey:#"foo"] forKeyPath:#"parameters.foo"];
// add 'project' to 'gDictRoot' so it isn't lost when the view is dismissed
[gDictRoot setValue:project forKeyPath:#"root.project2"];
Third line, where I add project to gDictRoot – project0 also gets modified. Don't know why.
The behavior that you see is due to the fact that both project0 and project2 point to the same dictionary instance. The change to one of them will always reflect in the other one.
If you do not want this behavior, make a copy of project0 before making it project2:
NSMutableDictionary *project = [NSMutableDictionary
dictionaryWithDictionary:[gDictRoot valueForKeyPath:#"root.project0"]
];
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Imagine an ordinary UIViewController subclass. We want to do "setup stuff" to be preformed before -viewDidWhatever, but the problem is that there are three methods that could possible be called, either -initWithNibName, -initWithCoder or simply -init depending on how it is created.
The solution would be to create -setup to be called from all these three, but I'm a bit unsure about the name. My question to you is: is there any standard naming of this method?
I have commonly named it -setup myself when doing this.
Depending on what you want to do, you could put it in + (void)initialize, which is inherited from NSObject and will automatically be called before the class receives its first message.
Have a look here: Apple Developer Library: NSObject Class Reference