作为一名初级iPhone程序员,编写iOS 5或更早版本的应用程序的最佳做法是什么?具体来说,我应该继续使用数据的发布/保留,还是应该忽略它?有关系吗?
@interface Article : NSObject
@property (nonatomic, strong) NSString *imageURLString;
@end
@implementation Class
@synthesize imageURLString = _imageURLString;
- (void)setImageURLString:(NSString *)imageURLString {
_imageURLString = imageURLString;
//do something else
}
Run Code Online (Sandbox Code Playgroud)
启用ARC时,我是否正确覆盖了设置器?
Objective-C中弱属性和强属性setter属性有什么区别?
@property(retain, [weak/strong]) __attribute__((NSObject)) CFDictionaryRef myDictionary;
Run Code Online (Sandbox Code Playgroud)
有什么影响和好处?
我听说iOS 4上没有弱点,我们需要使用assign.
弱者类似于分配吗?
我正在阅读关于"调度队列的内存管理"的苹果文档:
即使您实现了垃圾收集的应用程序,您仍必须保留并释放调度队列和其他调度对象.Grand Central Dispatch不支持回收内存的垃圾收集模型.
我知道ARC不是垃圾收集器,但我想确定我不需要dispatch_retain和dispatch_release我的dispatch_queue_t
我已经开始使用Xcode 4.2开发我的第一个iOS应用程序,并且使用"实用程序应用程序"模板(FlipsideViewController附带的模板)定位iOS 5.0.
我读到,因为ARC是一个编译时功能,它也应该与iOS 4兼容,所以我试图将我的应用程序定位到4.3,并尝试编译它.当我这样做时,我收到此错误:
FlipsideViewController.m:错误:自动引用计数问题:当前部署目标不支持自动__weak引用
它引用了这一行:
@synthesize delegate = _delegate;
Run Code Online (Sandbox Code Playgroud)
该变量声明为:
@property (weak, nonatomic) IBOutlet id <FlipsideViewControllerDelegate> delegate;
Run Code Online (Sandbox Code Playgroud)
我知道iOS 4中不支持"弱引用",但我真的不明白为什么我想要使用弱引用开始,也不能弄清楚如何重写以避免使用它,同时仍然利用ARC(毕竟,它应该适用于iOS 4和5吗?)
如何从ARC下的对象中删除观察者?我们只是添加观察者并忘记删除它吗?如果我们不再手动管理内存,我们会从观察中退出吗?
例如,在视图控制器上:
[self.view addObserver:self
forKeyPath:@"self.frame"
options:NSKeyValueObservingOptionNew
context:nil];
Run Code Online (Sandbox Code Playgroud)
以前,我会调用removeObserver:视图控制器的dealloc方法.
ARC禁止在结构或联合中使用Objective-C对象,尽管标记了文件-fno-objc-arc?为什么会这样?
我假设如果你标记它-fno-objc-arc你没有这个限制.
当我respondsToSelector在ARC环境中调用时,收到以下错误消息Automatic Reference Counting Issue No known instance method for selector respondsToSelector:
这是标题
#import <AppKit/AppKit.h>
@class MTScrollView;
@protocol MTScrollViewDelegate
-(void)scrollViewDidScroll:(MTScrollView *)scrollView;
@end
@interface MTScrollView : NSScrollView
{
}
@property(nonatomic, weak) id<MTScrollViewDelegate>delegate;
@end
Run Code Online (Sandbox Code Playgroud)
这是实现文件
#import "MTScrollView.h"
@implementation MTScrollView
@synthesize delegate;
- (void)reflectScrolledClipView:(NSClipView *)aClipView
{
[super reflectScrolledClipView:aClipView];
if([delegate respondsToSelector:@selector(scrollViewDidScroll:)])
{
[delegate scrollViewDidScroll:self];
}
}
@end
Run Code Online (Sandbox Code Playgroud)
有关我为什么会收到此错误的任何建议?
我正在尝试使用我正在开发的iOS应用程序发送HTTP Post但是推送从未到达服务器,尽管我确实获得了代码200作为响应(来自urlconnection).我从来没有得到服务器的响应,也没有服务器检测到我的帖子(服务器检测到来自android的帖子)
我确实使用ARC,但将pd和urlConnection设置为强.
这是我发送请求的代码
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]
initWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",dk.baseURL,@"daantest"]]];
[request setHTTPMethod:@"POST"];
[request setValue:@"text/xml"
forHTTPHeaderField:@"Content-type"];
NSString *sendString = @"<data><item>Item 1</item><item>Item 2</item></data>";
[request setValue:[NSString stringWithFormat:@"%d", [sendString length]] forHTTPHeaderField:@"Content-length"];
[request setHTTPBody:[sendString dataUsingEncoding:NSUTF8StringEncoding]];
PushDelegate *pushd = [[PushDelegate alloc] init];
pd = pushd;
urlConnection = [[NSURLConnection alloc] initWithRequest:request delegate:pd];
[urlConnection start];
Run Code Online (Sandbox Code Playgroud)
这是我代表的代码
#import "PushDelegate.h"
@implementation PushDelegate
@synthesize data;
-(id) init
{
if(self = [super init])
{
data = [[NSMutableData alloc]init];
[data setLength:0];
}
return self;
}
- (void)connection:(NSURLConnection *)connection didWriteData:(long long)bytesWritten totalBytesWritten:(long …Run Code Online (Sandbox Code Playgroud) objective-c http-post nsurlconnection ios automatic-ref-counting
我试图了解NSString从CFStringRefARC 获得一个正确的方法?同为去相反的方向,CFStringRef以NSString在ARC?
在不造成内存泄漏的情况下执行此操作的正确方法是什么?
objective-c nsstring automatic-ref-counting toll-free-bridging
objective-c ×6
ios ×5
iphone ×5
ios5 ×3
cocoa-touch ×1
http-post ×1
ipad ×1
macos ×1
nsstring ×1
struct ×1