小编Gab*_*lla的帖子

使用C中的目标c类型

我有任何方式使用客观的C类型例如NSRange,CGRect等(它们是结构)从C 2

我使用Objective c runtime来访问目标c类,但是一些方法返回并接受作为结构的目标c类型,我的问题是如何使用C中返回的目标c结构?

c objective-c

5
推荐指数
1
解决办法
110
查看次数

clang中的assign-enum警告是什么?

我正在AFNetworking实施,我找到了这个

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wassign-enum"
[request setHTTPBody:[NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error]];
#pragma clang diagnostic pop
Run Code Online (Sandbox Code Playgroud)

(AFHTTPClient:489-492)

assign-enum警告显然被关闭,但我不知道是什么意思.

在这种情况下,clang会发出什么警告?

objective-c clang afnetworking

5
推荐指数
1
解决办法
1087
查看次数

为什么在Objective-C中为每个对象变量声明类型?

由于Objective-C是一种动态类型语言,为什么我们仍然需要类型?是因为它与C代码混合了吗?

objective-c

5
推荐指数
1
解决办法
266
查看次数

将块传递给AFNetworking方法?

-(void )getDataFromServer: (NSMutableDictionary *)dict
 {

 NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/doSomething",MainURL ]];
 [AFJSONRequestOperation addAcceptableContentTypes:[NSSet setWithObject:@"text/html"]];

 AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
 NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:nil parameters:dict];

 AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request
 success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON)
 {
     _myArray = JSON;
     [_myTableView reloadData]; //Or do some other stuff that are related to the current `ViewController`
 }
 failure:^(NSURLRequest *request , NSURLResponse *response , NSError *error , id JSON)
 {
     NSLog(@"request: %@",request);
     NSLog(@"Failed: %@",[error localizedDescription]);
 }];

 [httpClient enqueueHTTPRequestOperation:operation];
 }
Run Code Online (Sandbox Code Playgroud)

我在我的一个应用程序中的7个不同位置使用上面的代码.确切的代码块在我的7个中重复 …

objective-c objective-c-blocks afnetworking

5
推荐指数
1
解决办法
786
查看次数

复制块

有人可以告诉我为什么localComplete块和self.block的内存地址是一样的吗?self.complete的属性设置为copy,并且为了确保我在将localComplete分配给self.complete时也在localComplete上调用copy.

- (void) test {

    CompletionBlock localComplete = ^{

    };

    NSLog(@"localComplete - %p", localComplete);

    self.block = [localComplete copy];

    NSLog(@"self.complete - %p", self.block);

    self.block();
}
Run Code Online (Sandbox Code Playgroud)

这是输出:

2013-10-05 08:39:18.549 TestApp[90703:a0b] localComplete - 0x60b8
2013-10-05 08:39:18.550 TestApp[90703:a0b] self.complete - 0x60b8
Run Code Online (Sandbox Code Playgroud)

另一个例子我创建字符串:

// creating string
self.carType = [[NSString alloc] initWithFormat: @"Good%@", @"year"];
NSLog(@"self.carType - %p", self.carType);

// same memory address???
NSString *carInitString = [[NSString alloc] initWithString: self.carType];
NSLog(@"carInitString - %p", carInitString);

// same memory address???
NSString *carCopy = [self.carType copy];
NSLog(@"carCopy - %p", carCopy); …
Run Code Online (Sandbox Code Playgroud)

objective-c ios objective-c-blocks automatic-ref-counting

5
推荐指数
1
解决办法
764
查看次数

Objective-C中的按位右移>>

我有一个变量(unsigned int)part_1.

如果我这样做:( NSLog(@"%u %08x", part_1, part_1);打印无符号值和十六进制值)它输出:

2063597568 7b000000

(只有前两个会有值).

我想把它转换成

0000007b

所以我尝试过 unsigned int part_1b = part_1 >> 6(和很多变化)

但这输出:

32243712 01ec0000

我哪里错了?

c bit-manipulation objective-c shift ios

5
推荐指数
1
解决办法
3793
查看次数

是什么原因导致此异常被抛出"观察者错误"?

如果它是iOS 7并且我包含spcluster自定义地图(超级引脚映射),我只会收到此错误.为什么会出现此错误,如何解决?

 *** Terminating app due to uncaught exception 'NSRangeException', reason: 'Cannot remove an observer <MKMapAnnotationManager 0xb355a00> for the key path "coordinate" from <Annotation 0x194c1470> because it is not registered as an observer.'
Run Code Online (Sandbox Code Playgroud)

iphone objective-c ios

5
推荐指数
2
解决办法
6971
查看次数

无法在 Swift 中解开 Optional.None 错误

当为 UILabel 传递值时,会出现错误:

无法解开 Optional.None

源代码:

    @IBOutlet var rowLabel : UILabel
var 行:字符串?{ 已设置{ // 更新视图。 打印(行) rowLabel.text = 行 } }
当我采用新的含义时,UITable 模板中的标签中也会出现错误:
    让 myCell : Cell = Cell(style: UITableViewCellStyle.Subtitle, repeatIdentifier: "cell")
            myCell.myLabel.text = "(indexPath.row)"
    

ios swift ios8

5
推荐指数
1
解决办法
2440
查看次数

PartialFunction orElse在其类型边界上是否比它应该更宽松?

让我们定义一个PartialFunction[String, String]和一个PartialFunction[Any, String]

现在,给定定义 orElse

def orElse[A1 <: A, B1 >: B](that: PartialFunction[A1, B1]): PartialFunction[A1, B1] 
Run Code Online (Sandbox Code Playgroud)

我希望不能把这两者组合起来,因为

A→交通String
A1→交通Any

因此,约束A1 <: A(即Any <: String)不成立.

出乎意料的是,我可以编写它们并获得PartialFunction[String, String]整个String域的定义.这是一个例子:

val a: PartialFunction[String, String] = { case "someString" => "some other string" }
// a: PartialFunction[String,String] = <function1>

val b: PartialFunction[Any, String] = { case _ => "default" }
// b: PartialFunction[Any,String] = <function1>

val c = a orElse …
Run Code Online (Sandbox Code Playgroud)

types scala partialfunction

5
推荐指数
1
解决办法
420
查看次数

为什么在使用ARC的快速枚举循环中需要__strong

当我做下面的事情时,我得到一个错误说

for (UIView* att in bottomAttachments) {
    if (i <= [cells count]) {
        att = [[UIView alloc] extraStuff]
    }
}
Run Code Online (Sandbox Code Playgroud)

Fast Enumeration variables cannot be modified in ARC: declare __strong

__strong该做什么以及为什么要添加它?

xcode objective-c ios automatic-ref-counting

4
推荐指数
1
解决办法
2846
查看次数