这是我使用swift的第一个项目.我是alamofire连接API.我有一个本地副本形式我想用于调试的API - 所以我可以设置测试数据 - 因为远程API已经有我无法搞砸的真实数据.
问题是我尝试访问时遇到以下错误 https://localhost:8443/MyProject
可选(错误域= NSURLErrorDomain代码= -1202"此服务器的证书无效.您可能连接到假冒"localhost"的服务器,这可能会使您的机密信息面临风险."UserInfo = 0x7fbeb8c61ff0 {NSURLErrorFailingURLPeerTrustErrorKey = ,NSLocalizedRecoverySuggestion =你想连接到服务器吗?,_kCFStreamErrorCodeKey = -9813,NSUnderlyingError = 0x7fbeb8ea5c00"操作无法完成.(kCFErrorDomainCFNetwork error -1202.)",NSLocalizedDescription =此服务器的证书无效.您可能连接到假冒"localhost"的服务器,这可能会使您的机密信息面临风险.,NSErrorFailingURLKey = https:// localhost:8443/myproject/api/loginUser.pdo,NSErrorFailingURLStringKey = https:// localhost :8443/myproject/api/loginUser.pdo,_kCFStreamErrorDomainKey = 3})
我发现许多解决方案大部分都是针对Objective-c使用setAllowsAnyHTTPSCertificate或使用Connection的委托.但是我无法setAllowsAnyHTTPSCertificate在swift中找到一个有效的方法,我不知道如何在使用alamofire时将委托设置为连接.任何想法我需要做什么?
setAllowsAnyHTTPSCertificate是私人api,会导致该项目被Apple拒绝.我只想在调试时使用它,然后在发布项目之前将其删除.先感谢您.
我遇到了一个问题,我需要动画处理标签垂直翻译textField文本高度的相同距离.在大多数情况下,textField.bounds.heigt但是如果textField的高度大于文本高度,那对我来说就不会有任何好处.所以我需要知道:
如何计算字符串文本的行高UIFont?
关于副本:我需要的东西有点不同.答案(我在答案中引用)得到总高度取决于1)字符串2)宽度3)字体.我需要的是只有字体的一行高度.
我正在使用Realm List/Results作为我的dataSource UITableView.在某些时候,我为它分配一个列表.喜欢:
var dataSource:List<SomeObject>! // Or >> Results<SomeObject>!
let aRealmObject = realm.objectForPrimaryKey(SomeObject.self, key: objectId)
dataSource = aRealmObject.someList // dataSource should be List
Run Code Online (Sandbox Code Playgroud)
然后我在这个列表上有一个过滤器如果用户更改了过滤日期,我喜欢这样:
dataSource = dataSource.filter("FILTER THE DATES",newDates) // dataSource should be Results
Run Code Online (Sandbox Code Playgroud)
但上面的行会导致错误,因为返回类型filter是一个Results对象并且aRealmObject.someList是一个List.
处理这种情况的最佳方法是什么?
List并将Results对象转换为List?怎么样??Results并转换List为Results?怎么样??谢谢,
我正在尝试编写一系列泛型函数,它们将通过传递UIViewController类或子类Type 对视图控制器堆栈进行排序,然后返回"找到"viewController或nil的实例.到目前为止,我甚至无法编译这个简单的代码片段:
extension UINavigationController {
func fhk_find<T: UIViewController>(viewControllerType: T.Type) -> T?
{
if let viewController = viewControllers.first as? viewControllerType {
return viewController
}
else {
return nil
}
}
}
Run Code Online (Sandbox Code Playgroud)
并会打电话给:
navController.fhk_find(fooViewController.self)
Run Code Online (Sandbox Code Playgroud)
但是,编译器告诉我这viewControllerType不是一个类型.
我不确定我在这里缺少什么......
我使用Realm结果对象Result<AnObject>作为数据源uitableview.在不同的视图控制器中有一些后期API调用,可以加载更多AnObject对象.我想要的是在更新数据源以更新表视图时收到通知.我做了一些搜索并且知道我需要使用KVO,但我找不到任何关于如何在realm中使用它的示例.我的代码如下所示:
class myViewController: UIViewController, UITableViewDatasource {
let realm = try! Realm()
override func viewDidLoad() {
super.ViewDidLoad()
var datasource = realm.objects(AnObject.self)
// I need to some how observe the change of datasource
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return datasource.count
}
...
}
Run Code Online (Sandbox Code Playgroud)
更新
我realm.addNotificationBlock在它工作之前尝试使用(在@joern答案中使用相同的方式),但是当任何领域对象不仅更新数据类型时,问题就是块将运行.这个表重新加载了太多无意义的时间.
更新2
我的应用程序有一个CalendarViewController,它包含上半部分的FSCalenar视图和下半部分的一个容器,链接到EventsViewController,它有事件的tableview.我有很多事件需要很长时间才能从API中获取.所以我对API进行了大约20次调用,每个API都会获得一些事件.并添加所有调用操作,NSOperationQueue然后根据我需要首先加载的内容设置操作优先级.因此,每个API调用在完成时都会更新数据源对象.我需要事件tableview然后重新下载.API调用发生在CalendarViewController调用的APIManager类方法中
我是新手,对我遇到的这个问题感到沮丧.
我想要做的非常简单:在屏幕中央画一条直线并为其制作动画.听起来很简单吧?是啊..这就是我现在所拥有的.
import UIKit
class Drawings: UIView {
override func drawRect(rect: CGRect) {
let screensize: CGRect = UIScreen.mainScreen().bounds
let screenWidth = screensize.width
let screenHeight = screensize.height
//context
let context = UIGraphicsGetCurrentContext()
CGContextSetLineWidth(context, 7.0)
CGContextSetStrokeColorWithColor(context, UIColor.whiteColor().CGColor)
//path
CGContextMoveToPoint(context, screenWidth, screenHeight * 0.5)
CGContextAddLineToPoint(context, screenWidth * 0.5, screenHeight * 0.5)
CGContextSetLineCap(context, CGLineCap.Round)
//draw
CGContextStrokePath(context)
}
}
Run Code Online (Sandbox Code Playgroud)
我问的原因是我发现我无法为它设置动画,因为它在drawRect函数中.真的吗?需要你们的一些解释.谢谢!
swift ×6
ios ×3
realm ×2
alamofire ×1
certificate ×1
drawrect ×1
generics ×1
height ×1
realm-cocoa ×1
string ×1
swift2 ×1
uibezierpath ×1
uifont ×1