在大约100,000次setDelegate调用之后,我的iOS应用程序在setDelegate上停顿了大约15秒.将委托属性从弱更改为分配可以解决问题.知道为什么弱的财产有这么多的开销并拖延应用程序?
我怀疑弱引用是在数组中维护的,因此运行时可以通过它们循环,并在委托对象被释放时将指针设置为nil.阵列是否有最大尺寸?当n接近100,000时,失速变得更长.
示例代码如下:
头文件:
#import <Foundation/Foundation.h>
@protocol GraphDataPointDelegate <NSObject>
- (BOOL)drawGraphByDistance;
@end
@interface GraphDataPoint : NSObject
- (id)initWithYValue:(NSNumber *)yValue withTime:(NSNumber *)time withDistance:(NSNumber *)distance withDelegate:(id <GraphDataPointDelegate> )delegate;
@end
@interface Graph : NSObject <GraphDataPointDelegate>
@end
Run Code Online (Sandbox Code Playgroud)
M文件
#import "Graph.h"
@interface GraphDataPoint ()
@property (nonatomic, weak, readwrite) id <GraphDataPointDelegate> delegate;
@property (nonatomic, strong, readwrite) NSNumber *yValue;
@property (nonatomic, strong, readwrite) NSNumber *time;
@property (nonatomic, strong, readwrite) NSNumber *distance;
@end
@implementation GraphDataPoint
- (id)initWithYValue:(NSNumber *)yValue withTime:(NSNumber *)time withDistance:(NSNumber *)distance withDelegate:(id<GraphDataPointDelegate>)delegate {
self = [super init]; …Run Code Online (Sandbox Code Playgroud) 血压值在iOS 8.2中的Health中添加:https://support.apple.com/en-us/HT203113
如何构建一个HealthKit HKUnit,以获得毫克/升(毫升/升)的血糖值?
以下两个抛出异常:由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'无法解析分解字符串...
HKUnit *mmolPerL = [HKUnit unitFromString:@"mmol<molar mass>/L"];
HKUnit *mmolPerL = [HKUnit unitFromString:@"mmol/L"];
Run Code Online (Sandbox Code Playgroud)