繁体   English   中英

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

[英]Q:how to declare a property of Byte[] in iOS?

我有一个需要接收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[] 谢谢。

你可以像这样使用Pointer

@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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM