简单的问题.我得到了对下一个视图控制器执行segue的按钮.我想写UI XCTest告诉我它是否打开了我想要的视图控制器.
用于在PFObject子类上添加属性和方法的Parse文档在其示例代码中方便地跳过Swift语法,列出了Objective-C语法:
https://parse.com/docs/ios_guide#subclasses-properties/iOS
// Armor.h
@interface Armor : PFObject<PFSubclassing>
+ (NSString *)parseClassName;
@property (retain) NSString *displayName;
@end
// Armor.m
@dynamic displayName;
Run Code Online (Sandbox Code Playgroud)
有没有人想出一个解决Swift缺乏动态合成器的工作,以便用PFSubclassing实现属性和方法?我希望能够做到这样的事情:
class Armor : PFObject, PFSubclassing {
class func parseClassName() -> String! {
return "Armor"
}
}
var armor = Armor()
armor.displayName = "Iron Clad"
Run Code Online (Sandbox Code Playgroud) 我知道我们可以通过使用AnyObject以下方式指定我们的泛型是任何引用类型:
class Foo<T: AnyObject> {
// ...
}
Run Code Online (Sandbox Code Playgroud)
但有没有办法指定我们的泛型应该只是值类型,而不允许引用类型?
我是一个全新的解析,找不到任何没有过时的教程,也没有提出更多的问题.我有一个简单的xml文件url我试图解析.xml非常简单:
<xml>
<record>
<EmpName>A Employee</EmpName>
<EmpPhone>111-222-3333</EmpPhone>
<EmpEmail>a@employee.com</EmpEmail>
<EmpAddress>12345 Fake Street</EmpAddress>
<EmpAddress1>MyTown, Mystate ZIP</EmpAddress1>
</record>
</xml>
Run Code Online (Sandbox Code Playgroud)
并且只想将其保存为NSDictionary(标记为键和数据作为值).到目前为止,我能够成功完成的是在控制台中打印xml字符串:
let url = NSURL(string: "http://www.urlexample.com/file.xml")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!) {(data, response, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}
print(task)
task.resume()
Run Code Online (Sandbox Code Playgroud)
我已经浏览过任何我发现的在线教程,这些教程要么过时,要么过于复杂.任何帮助表示赞赏.
到目前为止,我已经看到了这些问题的答案(1,2,3)建议使用GCD是dispatch_once这样的:
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
print("This is printed only on the first call to test()")
}
print("This is printed for each call to test()")
}
test()
Run Code Online (Sandbox Code Playgroud)
输出:
This is printed only on the first call to test()
This is printed for each call to test()
Run Code Online (Sandbox Code Playgroud)
但是等一下.token是一个变量,所以我可以很容易地做到这一点:
var token: dispatch_once_t = 0
func test() {
dispatch_once(&token) {
print("This is printed only on the first call …Run Code Online (Sandbox Code Playgroud) 经典的例子是:
- (void)viewDidLoad {
[super viewDidLoad]; // Subclasses sometimes forget this line
// Subclass's implementation goes here
}
Run Code Online (Sandbox Code Playgroud)
有什么方法可以确保在编译时UIViewController子类总是[super viewDidLoad]在它们覆盖时调用[UIViewController viewDidLoad]?
考虑一下我有以下几点:
FrameworkA,它定义了类 FooFrameworkB,这也定义了类 FooFrameworkA导入的文件FrameworkB如何在Foo不使用命名空间限定符的情况下让Xcode在任何引用的行上生成警告或错误?
例如:
let a = FrameworkA.Foo() // fine, no warning or error
let b = FrameworkB.Foo() // fine, no warning or error
let c = Foo() // at a minimum, a warning
Run Code Online (Sandbox Code Playgroud)
我完全理解,如果我们在FrameworkA,那么第三个例子相当于FrameworkA.Foo(),但我希望Xcode生成警告或错误.
考虑方案时,类Foo已经存在在FrameworkB很长一段时间,有问题的代码行一直打算在类点Foo的定义FrameworkB,但在未来的某个点后,有人添加类Foo到FrameworkA出于某种原因.这将改变文件中行的行为.
我希望Xcode在使用导入文件的多个框架中定义的内容时生成编译时警告或错误,而不显式声明名称空间.
有办法吗?
有没有人知道动画有多长
- (void)setEditing:(BOOL)editing animated:(BOOL)animated;
Run Code Online (Sandbox Code Playgroud)
在UITableViewCell拿?我用0.5秒进行测试,但我更喜欢使用Framework中的常量UITableViewCellEditingAnimationDuration
我有一个collectionView.我想检测滚动方向.我有两种不同的动画风格,可以向下滚动并向上滚动.所以我必须学习滚动方向.
CGPoint scrollVelocity = [self.collectionView.panGestureRecognizer
velocityInView:self.collectionView.superview];
if (scrollVelocity.y > 0.0f)
NSLog(@"scroll up");
else if(scrollVelocity.y < 0.0f)
NSLog(@"scroll down");
Run Code Online (Sandbox Code Playgroud)
这只是触摸手指的工作.不适合我
objective-c uigesturerecognizer ios uipangesturerecognizer uicollectionview
我正在UIActivityViewController用来分享图片.WhatsApp最近的更改允许分享后我能够在共享选项中看到WhatsApp.我正在分享图像和消息,我可以看到短信,但我无法共享图像.相同的代码适用于Viber,FB,Twitter等.不确定WhatsApp我缺少什么.
func shareImage() {
var messageStr:String = "Check out my awesome photo!"
var img: UIImage = currentPhoto!
var shareItems:Array = [img, messageStr]
let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
self.presentViewController(activityViewController, animated: true, completion: nil)
}
Run Code Online (Sandbox Code Playgroud) swift ×7
ios ×6
objective-c ×2
frameworks ×1
generics ×1
namespaces ×1
parsing ×1
subclassing ×1
tableview ×1
uikit ×1
value-type ×1
xcode ×1
xctest ×1
xml ×1