我对目标C中声明的变量如何感到困惑.
1:我看到@property并且使用了@synthesize声明.我的问题是,这两个声明是什么?为什么他们总是一起使用?我想@synthesize是创建getter和setter的捷径?
2:说,我想声明一个只能在声明的类中访问的NSMutableArray.我必须myArray = [[NSMutableArray alloc] init]在使用该addObject方法向其写入内容之前执行.我什么时候发布阵列呢?
3:是否有一种不同的方式来声明一个只能在声明可以在所有类中访问的类才能访问的变量?
4:类似于问题2,但现在变量是NSString.为什么我不必分配和初始化它在自己的类中共享相同的变量?请告诉我之间的不同self.myString = @"";来myString = @"";
非常感谢.
嗨,我需要帮助建立到Web服务的HTTP POST连接.我对如何做到完全无能为力.
我只是在制作NSURLConnection方面经验丰富,我将所需的输入参数作为URL的一部分传递.现在它似乎有所不同,因为我只提供了一个网站和请求JSON正文.
{
"lastmodified":"String content",
"passengerId":9223372036854775807,
"password":"String content",
"userId":"String content"
}
Run Code Online (Sandbox Code Playgroud)
谁能对此有所了解?比如网站是www.myURL/operations/AddItem.com
编辑 - 我在这里做错了什么?
NSError *theError = nil;
NSArray *keys = [NSArray arrayWithObjects:@"userId", @"password", nil];
NSArray *objects = [NSArray arrayWithObjects:userNameTextField.text, passwordTextField.text, nil];
NSDictionary *jsonDictionary = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *myJSONString =[jsonDictionary JSONRepresentation];
NSData *myJSONData =[myJSONString dataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"myJSONString :%@", myJSONString);
NSLog(@"myJSONData :%@", myJSONData);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://153.20.32.74/11AprP306/passenger/item"]];
[request setHTTPBody:myJSONData];
[request setHTTPMethod:@"POST"];
NSURLResponse *theResponse =[[NSURLResponse alloc]init];
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&theResponse error:&theError];
NSLog(@"response : %@", theResponse); …Run Code Online (Sandbox Code Playgroud)