2016-10-11 19 views
0

我有需要接受Byte[]的方法:問:如何在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[]?謝謝。

+1

使用字節*,一切都是指針。 –

回答

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 
+0

怎麼能這樣,這裏面貌似中國人還不少哦,先前還看見了另外一個也是特麼註釋還是中文的 –

+0

以後問題分時間,特麼中國人多的時候就全問,省的老想用啥單詞,特麼本來英文就特差 –

+0

加我QQ撒,我已經加你了或者429801517 –