问:如何在iOS中声明Byte []的属性?

时间:2016-10-11 09:10:10

标签: ios arrays properties byte attr

我有一个方法需要收到Byte[]

.h文件中:

- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;

.m文件中:

我想拥有一个Byte[]属性来保存它。

但是当我宣布这样的财产时:

@property (nonatomic, assign) Byte PC1_APPKEY[];

显示错误:property cannot have array or function type'Byte[]'

所以我把它设置为这样的属性:

{
    Byte PC1_APPKEY[];
}

显示错误:Field has Incomplete type ‘Byte[]’

如何获得Byte[]?感谢。

1 个答案:

答案 0 :(得分:0)

你可以像这样使用指针

@property (nonatomic, assign) Byte *PC1_APPKEY;

所有文件

·H

//
//  ocViewController.h
//  testTableViewHeader
//
//  Created by 刷脸卡 on 10/11/16.
//  Copyright © 2016 曾祥林. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TestViewController : UIViewController
- (void)setPC1_APPKEY:(Byte[] )pC1_APPKEY;
@end

的.m

//
//  ocViewController.m
//  testTableViewHeader
//
//  Created by 刷脸卡 on 10/11/16.
//  Copyright © 2016 曾祥林. All rights reserved.
//

#import "TestViewController.h"

@interface TestViewController ()
@property (nonatomic, assign) Byte *PC1_APPKEY;
@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    NSString *testString = @"1234567890";
    NSData *testData = [testString dataUsingEncoding: NSUTF8StringEncoding];
    self.PC1_APPKEY = (Byte *)[testData bytes];
    for(int i=0;i<[testData length];i++){
        printf("testByte = %d\n",self.PC1_APPKEY[i]);
    }
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)setPC1_APPKEY:(Byte [])pC1_APPKEY{
    self.PC1_APPKEY = pC1_APPKEY;
}

@end