谁能帮我?我通过使用GCDAsyncSocket在TCP协议上密集交换两个设备之间的数据.我发送这样的数据:
NSMutableDictionary *packet = [[[NSMutableDictionary alloc] init] autorelease];
[packet setObject:[NSNumber numberWithInt:MultiPlayerTypeInfoNextRoundConfirm] forKey:@"type_info"];
[packet setObject:[NSNumber numberWithBool:YES] forKey:@"connection_confirmation"];
NSMutableData *data = [[NSMutableData alloc] initWithData:[NSKeyedArchiver archivedDataWithRootObject:packet]]; //[NSKeyedArchiver archivedDataWithRootObject:packet];
if (currentGameMode == GameModeServer)
[(ServerMultiplayerManager *)multiplayerManager sendNetworkPacket:data withTag:MultiPlayerTypeInfoNextRoundConfirm];
- (void)sendNetworkPacket:(NSData *)data withTag:(long)tag
{
[asyncSocket writeData:data withTimeout:-1 tag:tag];
}
- (void)socket:(GCDAsyncSocket *)sock didWriteDataWithTag:(long)tag
{
NSLog(@"DID WRITE DATA tag is %ld", tag);
[sock readDataWithTimeout:-1 tag:0];
}
Run Code Online (Sandbox Code Playgroud)
我读了这样的数据:
- (void)socket:(GCDAsyncSocket *)sender didReadData:(NSData *)data withTag:(long)tag
{
NSString *receivedInfo = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
[info_data setData:data];
NSLog(@"DID READ DATA …Run Code Online (Sandbox Code Playgroud) 请看一下这个简单的程序:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<int> a;
std::cout << "vector size " << a.size() << std::endl;
int b = -1;
if (b < a.size())
std::cout << "Less";
else
std::cout << "Greater";
return 0;
Run Code Online (Sandbox Code Playgroud)
}
尽管很明显-1小于0,但它仍输出“ Greater”,这让我感到困惑size。谁能解释一下?
我在这里看到了一些关于相同错误的问答,但没有一个有帮助。我仍然遇到同样的错误。我需要改变什么?这就是我现在所拥有的。
错误与这一行有关: imageIndex = (imageIndex < 0) ? ([图像数] -1):
感谢您的帮助!
#import "Photogallery.h"
@interface Photogallery ()
@end
@implementation Photogallery
@synthesize imageView;
int imageIndex = 10;
- (void)viewDidLoad {
[super viewDidLoad];
}
- (IBAction)handleSwipe:(UIGestureRecognizer *)sender {
NSArray *images=[[NSArray alloc]initWithObjects:@"1.jpg",@"2.jpg",@"3.jpg",@"4.jpg",@"5.jpg",@"6.jpg",@"7.jpg",@"8.jpg",@"9.jpg",@"10.jpg", nil];
UISwipeGestureRecognizerDirection direction = [(UISwipeGestureRecognizer *)sender direction];
switch (direction) {
case UISwipeGestureRecognizerDirectionLeft:
imageIndex++;
break;
case UISwipeGestureRecognizerDirectionRight:
imageIndex--;
break;
default:
break;
}
imageIndex = (imageIndex < 0) ? ([images count] -1):
imageIndex % [images count];
imageView.image = [UIImage imageNamed:[images objectAtIndex:imageIndex]];
}
@end
Run Code Online (Sandbox Code Playgroud) 请注意,如果a是数组名称,sizeof(a)则将生成整个数组a的大小,而不是指向其中一个元素的指针的大小.
那么,例如,如何sizeof区分数组a和指针b?
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int a[4] = {1, 2, 3, 4};
int *b = a;
printf("sizeof\(a) = %ld\n", sizeof(a));
printf("sizeof\(b) = %ld\n", sizeof(b));
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
它打印如下:
sizeof(a) = 16
sizeof(b) = 8
Run Code Online (Sandbox Code Playgroud) 实际上这个问题很简单.我不知道在我的问题标题中添加什么.我需要有按钮,边框和标题,没有别的.其余的是透明的,通过按钮可以看到我的视图背景.我已经google了很多,没有发现任何东西.提前致谢
如果我这样做
Object * myObject = [[Object alloc]init];
[myObject release];
Run Code Online (Sandbox Code Playgroud)
在下一行分配我的对象有什么不对
myObject = [[Object alloc]init];
Run Code Online (Sandbox Code Playgroud)
再次?
我知道我的问题已经在StackOverflow上讨论过,但我发现答案不能完全满足我的需求.所以问题是:
NSMutableArray *firstArray = [[NSMutableArray alloc] initWithObjects: obj1,obj2,nil];
NSMutableArray *secondArray = [[NSMutableArray alloc] init];
secondArray = [firstArray mutableCopy];
Run Code Online (Sandbox Code Playgroud)
现在,secondArray的保留计数是多少?2还是1?我应该发布两次还是只发一次?copy或mutableCopy是否会增加COPYING(此事件中为secondArray)对象的保留计数?
如何在First Name和中拆分全名Last Name.
NSString *fullName = @"John Luke Morite";
NSString *firstName = [[fullName componentsSeparatedByString:@" "] objectAtIndex:0]; //John
NSString *lastName = ?? // Luke Morite
Run Code Online (Sandbox Code Playgroud) 我无可救药地试图打电话Amazon MWS Products API.特别是我正在尝试请求此功能
它需要使用签名构建一个非常复杂的请求:
POST /Products/2011-10-01 HTTP/1.1
Content-Type: x-www-form-urlencoded
Host: mws.amazonservices.com
User-Agent: <Your User Agent Header>
AWSAccessKeyId=AKIAEXAMPLEFWR4TJ7ZQ
&Action=ListMatchingProducts
&MWSAuthToken=amzn.mws.4ea38b7b-f563-7709-4bae-87aeaEXAMPLE
&MarketplaceId=ATVPDKIKX0DER
&Query=0439708184
&SellerId=A1IMEXAMPLEWRC
&SignatureMethod=HmacSHA256
&SignatureVersion=2
&Timestamp=2012-12-12T22%3A23%3A50Z
&Version=2011-10-01
&Signature=V%2BEXAMPLERT%2Baj%2Fxwqo7y3PIifMFHeqFlNYW0EXAMPLEA%3D
Run Code Online (Sandbox Code Playgroud)
我在这个小库的帮助下构建了这个查询:
所以我的最终url字符串看起来像这样:
https://mws.amazonservices.com/Products/2011-10-01?AWSAccessKeyId=<MY_ACCESS_KEY>&Action=ListMatchingProducts&MarketplaceId=A1PA6795UKMFR9&Query=0439708184&SellerId=<SELLER_ID>&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2016-04-19T16%3A50%3A13Z&Version=2011-10-01&Signature=mZt3OhM14gwLdsQ%2Bhxz5UFMzr7m2U36DvZ7RG3dcsTI%3D
Run Code Online (Sandbox Code Playgroud)
似乎url字符串是正确构建的.我想是的,因为如果参数丢失或不正确,API会返回400错误,并说明此参数无效.这同样适用于签名.如果签名不正确,则API返回错误,该错误明确指出签名无效.所以,再次,我认为网址必须是好的.然而,API返回401错误和一个看起来像这样的html页面:
<?xml version="1.0"?>
<ErrorResponse xmlns="http://mws.amazonservices.com/schema/Products/2011-10-01">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>Access denied</Message>
</Error>
<RequestID>7b12e3c8-7b1a-4b6e-b7ba-15ec8c4e0968</RequestID>
</ErrorResponse>
Run Code Online (Sandbox Code Playgroud)
拒绝访问.我不明白为什么.我已经花了几个小时试图弄清楚什么是错的.谁能帮我?
http objective-c amazon-web-services http-status-code-401 ios
我正在使用带有以下代码的 createDirectory 创建新文件夹。
*let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
// Get documents folder
let documentsDirectory: String = paths.first ?? ""
// Get your folder path
let dataPath = documentsDirectory + "/MyNewFolder"
print("Path\(dataPath)")
if !FileManager.default.fileExists(atPath: dataPath) {
// Creates that folder if no exists
try? FileManager.default.createDirectory(atPath: dataPath, withIntermediateDirectories: false, attributes: nil)
}*
Run Code Online (Sandbox Code Playgroud)
现在我想在“MyNewFolder”下存储像 log.text 这样的新文件。任何人都可以建议我如何在“MyNewFolder”文件夹下保存新文件
提前致谢。
objective-c ×6
ios ×4
alloc ×1
c ×1
c++ ×1
cocoa-touch ×1
comparison ×1
copy ×1
http ×1
iphone ×1
retaincount ×1
sizeof ×1
swift ×1
tcp ×1
uibutton ×1
uikit ×1
unsigned ×1
vector ×1
xcode ×1