前提・実現したいこと
swift勉強中にエラーコードが出て困っています。
発生している問題・エラーメッセージ
Argument type 'String' does not conform to expected type 'NSCopying' Insert ' as NSCopying'
該当のソースコード
swift
1// 2// ViewController.swift 3// UIKit075 4// 5// Created by Misato Morino on 2016/08/15. 6// Copyright © 2016年 Misato Morino. All rights reserved. 7// 8 9import UIKit 10 11class ViewController: UIViewController { 12 13 //UIDynamicAnimatorはインスタンスを保存しなければアニメーションが実行されない 14 var animator : UIDynamicAnimator! 15 16 var gravity : UIGravityBehavior! 17 18 override func viewDidLoad() { 19 20 super.viewDidLoad() 21 22 self.view.backgroundColor = UIColor.cyan 23 24 // Labelを作成. 25 let myLabel: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 200, height: 40)) 26 myLabel.backgroundColor = UIColor.orange 27 myLabel.layer.masksToBounds = true 28 myLabel.layer.cornerRadius = 20.0 29 myLabel.text = "Hello Swift!!" 30 myLabel.textColor = UIColor.white 31 myLabel.shadowColor = UIColor.gray 32 myLabel.textAlignment = NSTextAlignment.center 33 myLabel.layer.position = CGPoint(x: self.view.bounds.width/2,y: -200) 34 self.view.addSubview(myLabel) 35 36 // Buttonを作成. 37 let myButton = UIButton(frame: CGRect(x: 0, y: 0, width: 200, height: 50)) 38 myButton.layer.position = CGPoint(x: self.view.frame.midX, y: 500) 39 myButton.layer.masksToBounds = true 40 myButton.layer.cornerRadius = 20.0 41 myButton.setTitleColor(UIColor.white, for: UIControl.State.normal) 42 myButton.setTitleColor(UIColor.black, for: UIControl.State.highlighted) 43 myButton.backgroundColor = UIColor.red 44 myButton.setTitle("Dropped!", for: UIControl.State.normal) 45 myButton.addTarget(self, action: #selector(ViewController.onClickMyButton(sender:)), for: UIControl.Event.touchUpInside) 46 self.view.addSubview(myButton) 47 48 // UIDynamiAnimatorの生成とインスタンスの保存. 49 animator = UIDynamicAnimator(referenceView: self.view) 50 51 // 重量を作り、Viewに適用させる. 52 gravity = UIGravityBehavior(items: [myLabel]) 53 54 // Collisionを作成、Viewに適用させる. 55 let collision = UICollisionBehavior(items: [myLabel]) 56 57 // 透明な四角形の当たり判定を作る. 58 collision.addBoundary( 59 60 // Identifier. 61 withIdentifier: "barrier", // エラーメッセージがこの行に出ます。 62 63 // ベジエで四角形の図形を作る. 64 for: UIBezierPath(rect: 65 CGRect(x: self.view.frame.midX, y: self.view.frame.midY, width: self.view.frame.maxX, height: 10) 66 ) 67 ) 68 69 // Collisionのアニメーションを実行. 70 animator.addBehavior(collision) 71 } 72 73 @objc func onClickMyButton(sender : UIButton){ 74 75 // Gravityのアニメーションを実行. 76 animator.addBehavior(gravity) 77 } 78} 79
試したこと
エラーメッセージ:61行目
withIdentifier: "barrier",
この箇所に出ます。色々調べてみたのですが、わかりませんでした。
教えていただけたら幸いです。
補足情報(FW/ツールのバージョンなど)
回答1件
あなたの回答
tips
プレビュー