小编Jon*_*ing的帖子

iPhone内存漏水?

非常快速的问题正在推动我的INSANE.我想知道是否有人能告诉我为什么这条线路正在泄漏?

NSString *post = [NSString stringWithFormat:@"<someXML><tagWithVar=%@></tagWithVar></someXML>",var];
post = [NSString stringWithFormat:@"xmlValue=%@",(NSString *)CFURLCreateStringByAddingPercentEscapes(
                                                                               NULL,
                                                                               (CFStringRef)post,
                                                                               NULL,
                                                                               (CFStringRef)@"!*'();:@&=+$,/?%#[]",
                                                                               kCFStringEncodingUTF8 )];
Run Code Online (Sandbox Code Playgroud)

我只是将字符串编码为URL格式.根据我的理解,stringWithFormat:应该返回一个自动释放的对象.显然事实并非如此.它有效,但泄漏.有任何想法吗??

iphone objective-c ipad ios

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

@private是如何实现的?

在Objective-C,我很好奇如何实例变量,如访问控制@private,@protected等来实现.

我曾经考虑过以某种方式生成单独的结构:

@interface Foo {
  int bar;
  @private
  int baz;
  @public
  int qux;
}
Run Code Online (Sandbox Code Playgroud)

=> 一些东西

struct Class_Foo_Protected {
  int bar;
};

struct Class_Foo_Private {
  int baz;
};

struct Class_Foo_Public {
  int qux;
};
Run Code Online (Sandbox Code Playgroud)

但我真的不知道.谁知道这是怎么做到的?

code-generation private language-implementation objective-c

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

常量的解释

我一直在寻找常量,除了不能以编程方式进行更改之外,我并不了解它们的不同之处.

extern NSString * const MyConstant;
Run Code Online (Sandbox Code Playgroud)

有了这条线,究竟extern是什么意思,究竟是什么const意思?

constants objective-c

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

问题 - [CALayer setBorderColor:]

我希望在我的textview周围有边框; 为此,我做了以下事情:

textView.layer.borderWidth = 5.0f;
textView.layer.borderColor = [UIColor grayColor];   
Run Code Online (Sandbox Code Playgroud)

我收到以下警告:

warning: passing argument 1 of 'setBorderColor:' from incompatible pointer type
Run Code Online (Sandbox Code Playgroud)

Update1:​​我的边框不可见

iphone uitextview iphone-sdk-3.0

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

为什么std :: queue没有operator []?

std::queue与默认情况下,双端队列来实现.std::deque有下标运算符,operator[]并且可能用数组实现.那么,为什么std::queueoperator[]

我意识到你可以有一个列表作为底层容器.(std::queue<int, std::list<int>>.)但即使这会使下标操作符变慢,这真的是一个不包含它的理由吗?这是我能想到它不包括在内的唯一原因.

c++ queue subscript-operator

3
推荐指数
1
解决办法
1675
查看次数

释放实例变量会导致崩溃,但为什么呢?

我有一个实例变量被定义并合成为一个属性,如下所示:

@interface CardFrontView : GenericCardView {
    UIImage *_letterImage;
}

@property (nonatomic, retain) UIImage *letterImage;

@end

@implementation CardFrontView
@synthesize letterImage = _letterImage;
...
Run Code Online (Sandbox Code Playgroud)

我将该letterImage属性设置为-init:

- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self != nil) {
        NSString *filename = [[NSBundle mainBundle] pathForResource:@"fehu" ofType:@"png"];
        self.letterImage = [UIImage imageWithContentsOfFile:filename];
    }   return self;
}
Run Code Online (Sandbox Code Playgroud)

然后,我发布它-dealloc,然后应用程序崩溃(EXC_BAD_ACCESS):

- (void)dealloc {
    [super dealloc];
    [_letterImage release];
}
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚应用程序崩溃的原因.有没有人知道这笔交易是什么?

iphone memory-management objective-c

2
推荐指数
1
解决办法
903
查看次数

我可以自动发布NSProxy的实例吗?

是否NSProxy真正落实-autorelease-release?如果没有,我是否需要手动dealloc NSProxy实例?(请假设我没有使用GC).

谢谢你为我解决这个问题.

memory-management objective-c nsproxy

2
推荐指数
1
解决办法
381
查看次数

typedef和函数声明出错

当我只是声明一个变量时,我不明白为什么我告诉我有一个无效的函数声明.另外,我不知道为什么我的typedef不起作用.

Username@Server 388> g++ -Wall -pthread testHashT.cpp -o testHashT
memHashT.h:22: error: invalid function declaration
memHashT.h: In function âvoid memAccessUpdate(void*, unsigned int, pthread_t, bool)â:
memHashT.h:114: error: cannot convert âmList*â to âlinkedMlist*â in assignment
memHashT.h:119: error: cannot convert âlinkedMlist*â to âmList*â in assignment
memHashT.h:128: error: âcountWSâ was not declared in this scope
memHashT.h:133: error: âcountRAâ was not declared in this scope
Username@Server 389> cat memHashT.h
//Basic hash table for memory addresses, recommended size for program running is table indexed by a prime …
Run Code Online (Sandbox Code Playgroud)

c c++ declaration function

2
推荐指数
1
解决办法
2069
查看次数

NSMutableArray实例变量内存管理

我正在做最后一点内存管理整理,有些事我不明白.我已经检查了所有文档,Stack Overflow等,但仍然没有得到它.我怀疑它与数组有关.

我有一个NSMutableArray实例变量,用于保存从另一个数组中的对象创建的对象.

-viewDidLoad 按如下方式初始化数组:

self.photoAlbum = [[NSMutableArray alloc] initWithCapacity:100];
Run Code Online (Sandbox Code Playgroud)

然后它调用一个填充它们的方法.

int i = 0;
for (Gem *gem in self.entityArray) {
    NSString * filePath = [[NSString alloc] initWithFormat: @"%@/%@2.jpg", [sysPaths objectAtIndex: 0], gem.detailsTitle];  
    // there is some stuff in here that means that there isn't a one to one relationship between the objects in gem and those in photo
    Photo *photo = [[Photo alloc] init];
    photo.filePath = filePath;
    photo.title = gem.title;
    photo.index = [NSNumber numberWithInt:i];
    [self.photoAlbum addObject:photo];
    [filePath …
Run Code Online (Sandbox Code Playgroud)

memory-management objective-c nsmutablearray

2
推荐指数
1
解决办法
746
查看次数

为什么总是在std :: for_each中指定迭代器?

据我所知,迭代STL集合的习惯看起来像这样:

int a[] = { 1,2,3 };
std::vector<int> v(a, a+3);

std::for_each(a.begin(), a.end(), some_function);
Run Code Online (Sandbox Code Playgroud)

如果我只想处理集合的某个范围,或者做一些更有创意的事情,那么指定第一个和最后一个迭代器是很有用的,但大多数时候,我怀疑我们实际上是想要使用整个集合.所以,我想知道为什么人们在那种情况下烦恼指定迭代器(因为它们总是相同的),并且不只是沿着这些方向使用便利函数:

namespace easy
{
  template <class T, class F>
  F for_each(T& collection, F function)
  {
    std::for_each(collection.begin(), collection.end(), function);
    return function;
  }
}
Run Code Online (Sandbox Code Playgroud)

(当然,这是可能的,这做事的惯用方式,我从来没有注意到!我是新的C++,虽然).

c++ design-patterns idioms

2
推荐指数
1
解决办法
218
查看次数