标签: swift3

如何将阴影添加到导航栏而不是默认边框

我想UINavigationBar用阴影替换默认边框.有没有办法实现这个目标?我尝试使用与向UIView添加阴影相同的方法,但它增加了我的NavigationBar的高度.

ios swift swift3

8
推荐指数
1
解决办法
1万
查看次数

Swift 3和NumberFormatter(.currency)==¤?

Xcode 8.0(8A218a)GM
目标:iOS 10(Swift 3)

请考虑以下代码:

let number = NSDecimalNumber(decimal: 22.4)

let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .currency
numberFormatter.locale = Locale.current

let result = numberFormatter.string(from: number)
print(result!)
Run Code Online (Sandbox Code Playgroud)

结果是:

¤22.40
Run Code Online (Sandbox Code Playgroud)

(我不知道是什么¤意思.)

但是,如果我初始化语言环境,例如:

numberFormatter.locale = Locale(identifier: "en_US")
Run Code Online (Sandbox Code Playgroud)

结果将是:

$22.40
Run Code Online (Sandbox Code Playgroud)

......这首先是我所期待的.

请注意,这适用于Playground:

在此输入图像描述

问题似乎只发生在通过Xcode启动的设备/模拟器上.
(我在两个不同的macOS上测试 - 在我的工作场所和家中.)

关于发生了什么的任何想法?

locale nsnumberformatter ios swift3 ios10

8
推荐指数
3
解决办法
2万
查看次数

Swift 3'Any'类型的值 没有会员'对象'

我更新了swift 3,发现了很多错误.这是其中之一:

"任何?"类型的值 没有会员'对象'

这是我的代码:

jsonmanager.post( "http://myapi.com",
                      parameters: nil,
                      success: { (operation: AFHTTPRequestOperation?,responseObject: Any?) in
                        if(((responseObject? as AnyObject).object(forKey: "meta") as AnyObject).object(forKey: "status")?.intValue == 200 && responseObject?.object(forKey: "total_data")?.intValue > 0){
                            let aa: Any? = (responseObject? as AnyObject).object(forKey: "response")

                            self.data = (aa as AnyObject).mutableCopy() 
                        }
Run Code Online (Sandbox Code Playgroud)

新错误更新:

可选链没有效果,表达式已经产生'Any?'

不能调用非函数类型的值'Any?!'

它在以前的版本7.3.1 swift 2中运行良好.

这是json的回应:

{
 "meta":{"status":200,"msg":"OK"},
        "response":[""],
        "total_data":0
}
Run Code Online (Sandbox Code Playgroud)

ios swift swift3

8
推荐指数
1
解决办法
2万
查看次数

使用Swift 3在Xcode 8中寻找关于修订的NSPersistentContainer的清晰教程

我查看了Apple的:

Xcode 8发行说明:https:
//developer.apple.com/library/content/releasenotes/DeveloperTools/RN-Xcode/Introduction.html

从Swift 2.2迁移到Swift 2.3或Swift 3
https://swift.org/migration-guide/

在macOS 10.12,iOS 10.0,tvOS 10.0和watchOS 3.0中的核心数据有什么新功能
https://developer.apple.com/library/content/releasenotes/General/WhatNewCoreData2016/ReleaseNotes.html#//apple_ref/doc/uid/ TP40017342-CH1-DontLinkElementID_1

还有很多其他......但是,应该从Apple的核心数据编程指南中获得的一个文档尚未从Swift 2更新
.https://developer.apple.com/library/content/documentation/Cocoa/概念/ CoreData/FetchingObjects.html#// apple_ref/DOC/UID/TP40001075-CH6-SW1

理想情况下,我正在寻找类似这样的东西,但对于Swift 3.
https://www.raywenderlich.com/115695/getting-started-with-core-data-tutorial

任何线索都会非常感激.

每个汤姆的评论(下面)我错过了什么步骤?

1)创建一个新项目"测试"

2)选择使用CoreDate(这会创建Test.xcdatamodeld)

这将使用以下内容自动填充AppDelegate(删除默认注释):

func applicationWillTerminate(_ application: UIApplication) {
self.saveContext()
}
lazy var persistentContainer: NSPersistentContainer = {
    let container = NSPersistentContainer(name: "Test")
    container.loadPersistentStores(completionHandler: { (storeDescription, error) in
        if let error = error as NSError? {
            fatalError("Unresolved error \(error), \(error.userInfo)")
        }
    })
    return container
}()
func saveContext () {
    let context = persistentContainer.viewContext
    if …
Run Code Online (Sandbox Code Playgroud)

core-data ios swift3 xcode8

8
推荐指数
2
解决办法
5474
查看次数

在Alamofire.upload swift 3中没有更多上下文的表达类型是模糊的

更新的Alamofire 4.0.0没有提到如何使用multipartFormData上传Httpmethod和Httpheaders.这就是我google并在stackoverflow问题中找到解决方案的原因.但问题是我做了同样的回答然后得到以下错误消息和构建失败.请帮我解决一下.

如果没有更多的上下文,表达的类型是不明确的

这是我的编码:

let URL = try! URLRequest(url: Config.imageUploadURL, method: .post, headers: headers)

Alamofire.upload(
    multipartFormData: { multipartFormData in
        multipartFormData.append(self.imageData, withName: "image", fileName: "file.png", mimeType: "image/png")
    },
    to: URL,
    encodingCompletion: { encodingResult in
        switch encodingResult {
        case .success(let upload, _, _):
            upload.responseJSON { response in
                if((response.result.value) != nil) {

                } else {

                }
            }
        case .failure( _):

        }
    }
)
Run Code Online (Sandbox Code Playgroud)

swift alamofire swift3 xcode8

8
推荐指数
1
解决办法
3万
查看次数

带闭包的默认属性值使编译器重新编译所有文件

这个有一个段落设置一个带有闭包或函数的默认属性值,我们可以在其中找到一个例子

这是一个关于如何使用闭包来提供默认属性值的骨架轮廓:

class SomeClass {

    let someProperty: SomeType = {
         // create a default value for someProperty inside this closure
         // someValue must be of the same type as SomeType
         return someValue
    }() 
}
Run Code Online (Sandbox Code Playgroud)

好吧,我经常使用它...而且,经常在更改一个符号后等待整个项目重新编译.而今天我发现这两件事彼此联系在一起.

让我们假设我们有一些类,我们使用闭包和函数设置一些默认属性

class Class1 {

    let value: Int

    init(_ value: Int) {
        self.value = value
    }

    private lazy var lazyValueWithClosure: Int = {
        return 1111
    }()

    private lazy var lazyValueWithFunction: Int = self.getValue()

    private func getValue() -> Int {
        return 2222
    } …
Run Code Online (Sandbox Code Playgroud)

terminal xcode xcodebuild swift swift3

8
推荐指数
1
解决办法
969
查看次数

创建日历,即使关闭iCloud也没有本地来源

我正在尝试创建日历,而不是日历事件而是日历.我无法获取本地来源,我的应用程序崩溃了.

这是我的代码:

let newCalendar = EKCalendar(for: .event, eventStore: eventStore)

newCalendar.title = "Some Calendar Name"

let sourcesInEventStore = eventStore.sources

newCalendar.source = sourcesInEventStore.filter{
            (source: EKSource) -> Bool in
            source.sourceType.rawValue == EKSourceType.local.rawValue
            }.first!
Run Code Online (Sandbox Code Playgroud)

我完全关闭了我的iCloud,仍然无法获得本地资源.

我也试图让这个与iCloud打开工作,我想出了这个代码,但它不起作用

for let source in eventStore.sources
        {
            if(source.sourceType == EKSourceType.calDAV && source.title == "iCloud")
            {
                newCalendar.source = source
            }
        }

        if(newCalendar.source == nil)
        {
            for let source2 in eventStore.sources
            {
                if(source2.sourceType == EKSourceType.local)
                {
                    newCalendar.source = source2
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

ios eventkit ekevent swift swift3

8
推荐指数
1
解决办法
1099
查看次数

UI测试 - isSelected始终返回false

我们最近使用Xcode 8.2.1(8C1002)将Swift 2.3项目更新到Swift 3,现在我们与tableViews和isSelected属性相关的大多数UI测试都不起作用.它总是返回false,即使选择了对象(我们可以在iOS模拟器中看到它).

有没有人遇到类似的问题?我们的代码曾经在转换之前在Swift 2.3中正常工作.以下是我们检索tableView单元格的方法:

let cell = app.tables.cells.element(at: 4)
Run Code Online (Sandbox Code Playgroud)

注意: app是XCUIApplication.

这是我们检查它是否被选中的方式:

XCTAssert(cell.isSelected)
Run Code Online (Sandbox Code Playgroud)

另一个观察是我们确定该对象存在,因为waitForExpectations它返回true:

let existsPredicate = NSPredicate(format: "exists = 1")
expectation(for: existsPredicate, evaluatedWith: cell, handler: nil)
waitForExpectations(timeout: 20, handler: nil)
Run Code Online (Sandbox Code Playgroud)

编辑:为了替换isSelected,我尝试使用NSPredicate selected = 1isSelected = 1.没有用.我也尝试使用acessibilityValue基于其他问题的答案,但它并不那么简单,因为有时我的表视图中的项目是以编程方式选择/取消选择的.此外,该方法涉及向应用程序添加测试代码,这不是一个好习惯.

在BOUNTY END之后编辑:由于没有人能找到解决该问题的解决方案,这显然是Xcode中的一个错误,我已向Apple提交了错误报告.当他们发布带有修复的Xcode版本时,我会在这里发表评论.

ios swift xcode-ui-testing swift3

8
推荐指数
1
解决办法
1329
查看次数

在swift SceneKit中使用顶点绘制自定义节点的示例是什么?

这个区域很难在线记录,很高兴看到一个有效的Swift 3示例,比如一个带有手动SCNvector3s的自定义绘制多维数据集.在Objective-C中有这个但不是Swift.这可能不是一个常见的问题形式,但我知道这会对很多人有所帮助.如果我错过了某个地方,请提及.

文档不是很有帮助

scngeometrysource等

谢谢

vector vector-graphics scenekit swift swift3

8
推荐指数
1
解决办法
2847
查看次数

AVPlayer无法在iOS 11中播放

我在iOS 11中面临AVPlayer的问题.相同的代码在iOS 10上完美运行.我使用DRM播放视频.

我收到以下警告:

  2017-11-22 20:48:09.237095+0530 AppName[9113:3782887] [] <<<< 
  AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -
  [AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl 
  outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device 
  discovery mode to DiscoveryMode_None (client: AppName)
  2017-11-22 20:48:09.266561+0530 AppName[9113:3782887] Presenting view 
  controllers on detached view controllers is discouraged 
  <Nettkino.PlayerViewController: 0x103f0a4b0>.
  2017-11-22 20:48:09.272713+0530 AppName[9113:3782887] [framework] 
  CUICatalog: Invalid asset name supplied: '(null)'
  2017-11-22 20:48:09.272730+0530 AppName[9113:3782887] [framework] 
  CUICatalog: Invalid asset name supplied: '(null)'
  2017-11-22 20:48:09.285772+0530 AppName[9113:3782887] [] <<<< 
  AVOutputDeviceDiscoverySession (FigRouteDiscoverer) >>>> -
  [AVFigRouteDiscovererOutputDeviceDiscoverySessionImpl 
  outputDeviceDiscoverySessionDidChangeDiscoveryMode:]: Setting device 
  discovery mode to DiscoveryMode_Presence (client: AppName)
Run Code Online (Sandbox Code Playgroud)

请指导我.我在过去3天内无法解决此问题.如果您需要有关我使用的应用程序的更多信息,请告诉我,我会更新我的问题.

avfoundation ios avplayer swift3

8
推荐指数
1
解决办法
1636
查看次数