能否给当地变量分配一个价值,其范围不在一栏之内,并保留其价值? 尤其是,I m coding forOS和我有一个被封锁的区块,我想在区块内分配一个价值,然后(区块外)使用。 我在区块一旦出现坏出入错误之后,就使用__block nut。 我正在利用阿农研中心就是这种情况。 例如:
__block NSString *str;
someBlock ^(id param1)
{
str = @"iPhone";
}
[str getCharAtIndex:1]; //or w/e
是否在概念上是错误的,或不允许什么? 非常感谢帮助。
Edit:
这部法律是实际的法典,它基本上把前eet作为 j子,然后所有我 m头照搬了案文。 在法典中,Int从json中提取案文,即试图证明概念
- (IBAction)getTweet:(id)sender
{
__block NSString *displayStr;
//account instance
ACAccountStore *store = [[ACAccountStore alloc] init];
ACAccountType *twitterAcountType =
[store accountTypeWithAccountTypeIdentifier: ACAccountTypeIdentifierTwitter];
//request access
[store requestAccessToAccountsWithType: twitterAcountType withCompletionHandler:
^(BOOL granted, NSError *error)
{
if (!granted) {
//display error on textView
}
else
{
//get available accounts
NSArray *twitterAccounts = [store accountsWithAccountType: twitterAcountType];
if([twitterAccounts count] > 0)
{
//get first account
ACAccount *account = [twitterAccounts objectAtIndex: 0];
////make authenticated request to twitter
//set-up params
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
[params setObject:@"1" forKey:@"include_entities"];
[params setObject:@"1" forKey:@"count"];
//which REST thing to call
NSURL *url =
[NSURL URLWithString:@"http://api.twitter.com/1/statuses/home_timeline.json"];
//create request
TWRequest *request =
[[TWRequest alloc]
initWithURL:url parameters:params requestMethod:TWRequestMethodGET];
//attach account info
[request setAccount: account];
[request performRequestWithHandler:
^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if(error != nil)
{
//display error
}
else
{
NSError *jsonError;
NSArray *timeline =
[NSJSONSerialization
JSONObjectWithData: responseData
options: NSJSONReadingMutableLeaves
error: &jsonError];
if (jsonError == nil)
{
///////////////////////////
///heres the src of error//
///////////////////////////
//display data
NSLog(@"array: %@", timeline);
displayStr = @"whats the deal with this";
//i tried this but i think ARC takes care of this
[displayStr retain];
}
else
{
//display error
}
}
}];//end block de request
}
else
{
//display error
}
}
}];//end block de store
///////then heres where i get the bad access error
[self.lastTweetText setText:displayStr];
}//end getTweet
also thanks for the help guys