草庐IT

swift-block

全部标签

ios - 使用 CoreData 和 Swift 2.0 保存问题

问题我试图简单地保存一条记录然后获取它,但我认为我在这里做错了,因为我的记录没有保存。输出窗口只显示一个空数组。我在Xcode7beta5中使用boiler-plateAppDelegateCoreData堆栈。[SeeGistHere]尝试实体型号importFoundationimportCoreData//@func(Person)edit:removedclassPerson:NSManagedObject{@NSManagedvarfirstName:String?@NSManagedvarlastName:String?}ViewControllerimportUIKiti

ios - swift Playground : get ViewController to call presentViewController

我想在Playground中使用UIAlertController。是否可以从XCPlaygroundPage获取ViewController-以便能够调用presentViewController? 最佳答案 您可以在呈现后将liveView设置为您的窗口,以避免出现警告。importUIKitimportPlaygroundSupportPlaygroundPage.current.needsIndefiniteExecution=trueletwindow=UIWindow()letviewController=UIViewC

ios - 文本阴影 - iOS,swift 3.0

我正在尝试使阴影尺寸变大一点,但我做不到。到目前为止:findAPlace.titleLabel?.layer.shadowOffset=CGSize(width:-1,height:1)findAPlace.titleLabel?.layer.shouldRasterize=truefindAPlace.titleLabel?.layer.shadowRadius=1findAPlace.titleLabel?.layer.shadowOpacity=1findAPlace.titleLabel?.layer.shadowColor=UIColor(red:0.07,green:0.

iphone - 用 block 简化委托(delegate)方案——在这种情况下是否可能?

我已经阅读了很多关于使用block的正面信息-特别是它通过消除委托(delegate)调用来简化代码。我找到了在动画结束时使用block而不是委托(delegate)调用的示例-我了解如何完成。但我真的很想知道在呈现和关闭ViewController时必须使用委托(delegate)的繁琐方案是否也可以用block来简化。显示和关闭方案的标准推荐方式如下所示,其中在VC1中呈现了一个新的VC2,它在VC1中再次被代表关闭。VC2*vc2=[[VC2alloc]initWithNibName:@"VC2"bundle:nil];vc2.delegate=self;[selfpresent

Maven无法下载依赖之 maven-default-http-blocker (http://0.0.0.0/): Blocked mirror for repositories

问题:maven-default-http-blocker(http://0.0.0.0/):Blockedmirrorforrepositories:这个错误的意思是:名称为maven-default-http-blocker的拦截器拦截了库的镜像。发生场景:在企业内部架设了一个Nexus的私有库,库的地址是:http://hostname:8081/repository/maven-public/,于是在项目中需要从这个库中获取依赖的配置方式是:在项目的pom.xml增加了这个库的配置,配置如下: my-nexus MyNexusRepository http://hos

iphone - 如何创建包装器以将 block 用于使用回调的类?

我正在深入研究iOS编程,并且正在学习如何使用block。我在我的项目中使用了一个糟糕的、过度设计的库,它使用一个回调方法来处理所有数据请求...@protocolSuckyClassDelegate-(void)returnedSuckyData:(NSMutableDictionary*)data;@end@interfaceSuckyClass:NSObject@property(nonatomic,weak)iddelegate;-(void)getSuckyData;@end@interfaceMyViewController:UIViewController-(void)r

ios - viewWillTransitionToSize 协调器忽略 block

尝试了新的旋转方法,我需要知道设备是否正在旋转,以便推迟和取消旋转时不需要的操作。-(void)viewWillTransitionToSize:(CGSize)sizewithTransitionCoordinator:(id)coordinator{[superviewWillTransitionToSize:sizewithTransitionCoordinator:coordinator];_rotating=YES;[coordinatornotifyWhenInteractionEndsUsingBlock:^(idcontext){_rotating=NO;}];}看起来

ios - 如何使用 Swift 2.0 动态转换为在字符串中命名的类型?

我需要将返回值转换为我需要保持动态的特定类型,例如letcellType="CellTypeToBeResolved"cell=(tableView.dequeueReusableCellWithIdentifier("myID")as?CellTypeToBeResolved)!这在Swift2.0中如何实现?谢谢! 最佳答案 你做不到,因为Swift(故意)遗漏了两block拼图:你不能把一个字符串变成一个类。更重要的是,您不能转换为表示为变量的类。要转换到的类必须是文字类,即它必须在编译时已知。编译器需要知道这个转换是合法的,

ios - 如何在 SDwebimage 中使用成功和失败 block

我有最新版本的SDWebimage但它没有成功和失败我尝试了以下方法,但SDwebimage没有方法[self.imageViewsetImageWithURL:[NSURLURLWithString:self.imageURL]placeholderImage:[UIImageimageNamed:@"YourPlaceholder.png"]success:^(UIImage*image){//removeanimation}failure:^(NSError*error){NSLog(@"thumbnailerror:%@",error);//handlefaileddownlo

ios - UIView.animateWithDuration swift 3

当按下按钮时,它会起作用。单击此功能后显示另一个View@IBActionfunccharSetPressed(_button:UIButton){ifbutton.titleLabel!.text=="1/2"{charSet1.isHidden=truecharSet2.isHidden=falsebutton.setTitle("2/2",for:.normal)}elseifbutton.titleLabel!.text=="2/2"{charSet1.isHidden=falsecharSet2.isHidden=truebutton.setTitle("1/2",for:.