非常快速的问题正在推动我的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:应该返回一个自动释放的对象.显然事实并非如此.它有效,但泄漏.有任何想法吗??
在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)
但我真的不知道.谁知道这是怎么做到的?
我一直在寻找常量,除了不能以编程方式进行更改之外,我并不了解它们的不同之处.
extern NSString * const MyConstant;
Run Code Online (Sandbox Code Playgroud)
有了这条线,究竟extern是什么意思,究竟是什么const意思?
我希望在我的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:我的边框不可见
在std::queue与默认情况下,双端队列来实现.std::deque有下标运算符,operator[]并且可能用数组实现.那么,为什么std::queue有operator[]?
我意识到你可以有一个列表作为底层容器.(std::queue<int, std::list<int>>.)但即使这会使下标操作符变慢,这真的是一个不包含它的理由吗?这是我能想到它不包括在内的唯一原因.
我有一个实例变量被定义并合成为一个属性,如下所示:
@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)
但是,我无法弄清楚应用程序崩溃的原因.有没有人知道这笔交易是什么?
是否NSProxy真正落实-autorelease和-release?如果没有,我是否需要手动dealloc NSProxy实例?(请假设我没有使用GC).
谢谢你为我解决这个问题.
当我只是声明一个变量时,我不明白为什么我告诉我有一个无效的函数声明.另外,我不知道为什么我的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) 我正在做最后一点内存管理整理,有些事我不明白.我已经检查了所有文档,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) 据我所知,迭代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++,虽然).
objective-c ×6
c++ ×3
iphone ×3
c ×1
constants ×1
declaration ×1
function ×1
idioms ×1
ios ×1
ipad ×1
nsproxy ×1
private ×1
queue ×1
uitextview ×1