草庐IT

lazy-init

全部标签

objective-c - UIViewController: [super init] 调用 [self initWithNibName bundle:]

我的UIViewController子类中有两个初始化函数:-(id)init{self=[superinit];if(self){//Customstuffreturnself;}returnnil;}和-(id)initWithNibName:(NSString*)nibNameOrNilbundle:(NSBundle*)nibBundleOrNil{self=[superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];if(self){//Customstuff}returnself;}我将init函数放入以避免调用init

properties - 使用 "by lazy"与 "lateinit"进行属性初始化

在Kotlin中,如果您不想在构造函数内或类体顶部初始化类属性,则基本上有以下两种选择(来自语言引用):LazyInitializationlazy()isafunctionthattakesalambdaandreturnsaninstanceofLazywhichcanserveasadelegateforimplementingalazyproperty:thefirstcalltoget()executesthelambdapassedtolazy()andrememberstheresult,subsequentcallstoget()simplyreturntheremem

properties - 使用 "by lazy"与 "lateinit"进行属性初始化

在Kotlin中,如果您不想在构造函数内或类体顶部初始化类属性,则基本上有以下两种选择(来自语言引用):LazyInitializationlazy()isafunctionthattakesalambdaandreturnsaninstanceofLazywhichcanserveasadelegateforimplementingalazyproperty:thefirstcalltoget()executesthelambdapassedtolazy()andrememberstheresult,subsequentcallstoget()simplyreturntheremem

ios - 在 UIView init 中添加一个 CALayer 子层

我试图在UIView子类中添加一个CALayer作为子层,但是当我在init方法中添加子层时,当我将View添加到另一个View或窗口时,我得到EXC_BAD_ACCESS。初始化方法:-(id)initWithTitle:(NSString*)titlemessage:(NSString*)message{if((self=[superinit])){self.title=title;self.message=message;self.alertLayer=[[CALayeralloc]init];self.layer.cornerRadius=kCORNER_RADIUS;self

iphone - NSMutableArray alloc init 与 NSMutableArray 数组

有什么区别:[[NSMutableArrayalloc]init]和[NSMutableArrayarray] 最佳答案 在[NSMutableArrayarray]中,您不必释放array,它会自动释放。&如果你要写[NSMutableArrayalloc]init]你将不得不释放array所以[[NSMutableArrayarray]将等同于[[[NSArrayalloc]init]autorelease]; 关于iphone-NSMutableArrayallocinit与NSM

ios - 使用参数创建自定义 UIView init 方法

我正在寻找如何使用传入参数的自定义init方法正确子类化UIView。我已阅读此处的UIView类引用文档:https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/uiview/uiview.html目前UIView是在UIViewController中创建的,可以移动/重构到它自己的子类中。此外,目前View完全在代码中创建,框架由添加到View本身的约束计算。文档说明如下initWithFrame:-Itisrecommendedthatyouimplementthisme

ios - 将 NSString 转换为 NSAttributedString 无需 alloc init

我想将NSString转换成NSAttributedString。但我总是要做NSAttributedString*useDict1=[[NSAttributedStringalloc]initWithString:@"String"];有没有其他方法可以让我不必每次都分配Dictionary,而只需提供字符串? 最佳答案 我建议在NSString上创建一个类别,使用一种将其转换为NSAttributedString的方法,然后在您的项目中使用该辅助方法。像这样:@interfaceNSString(AttributedString

iphone - 当我初始化自定义单元格时返回 'self' 而它没有设置为 '[(super or self) init...]' 的结果

在CustomCell.m中,我定义了我想从IB加载单元格的init方法:-(id)init{self=[superinit];if(self){NSArray*nib=[[NSBundlemainBundle]loadNibNamed:@"CustomCell"owner:selfoptions:nil];self=[nibobjectAtIndex:0];}returnself;}在MyTableViewController.m的cellForRowAtIndexPath方法中,我初始化了我的自定义单元格-(UITableViewCell*)tableView:(UITableVi

ios - 调用 alloc init 时 UIImagePickerController 真的很慢

我有一个ViewController,它在按下tabBarController中的一个选项卡时显示。在这个ViewController中,我在viewDidLoad方法中初始化了一个UIImagePickerController:-(void)viewDidLoad{[superviewDidLoad];//SetimagePicker//-------------------------//_imagePicker=[[UIImagePickerControlleralloc]init];_imagePicker.delegate=self;_imagePicker.videoMax

ios - Xcode 8,iOS 8 模拟器崩溃 : "dyld: lazy symbol binding failed: Symbol not found: _objc_unsafeClaimAutoreleasedReturnValue"

更新到Xcode8,在iOS8模拟器中运行我的应用程序并崩溃,尽管iOS9和iOS10没问题。"dyld:lazysymbolbindingfailed:Symbolnotfound:_objc_unsafeClaimAutoreleasedReturnValueReferencedfrom:**Expectedin:/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS8.1.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libobjc.A.dylibdyld:Symbolno