If you come up with any better solution please write that in the comment section to help others developers. Here I wanted to change the image of diceImageViewOne to DiceSix. The format is like who.what = UIImage ( named : “ImageName” ) I was trying to do something from a tutorial and in my case, I had to write the below code: diceImageViewOne. For information on using playground literals in Xcode, see Add a color, file, or image literal in Xcode Help. Playground literals in plain text outside of Xcode are represented using a special literal syntax. You can find the image names also in the Assets. A playground literal is used by Xcode to create an interactive representation of a color, file, or image within the program editor. The image name should be given as a string thus it is necessary to use double quotes around your Image Name. Where you were intending to type ImageLiteral, just don’t do that, and instead of that type the above code. I hope this will be much easier for you.įor me it worked: UIImage(named: "YourImageName" ) I will only show you the one which I followed. But I will not give you multiple solutions. Also, I came to know that we can do a similar thing using some other methods. Thus, I search over the internet and found that Apple has removed that option from Xcode. But when I started typing Image Literal, the Xcode was not bringing any option like that. I was trying to do the same after following an Xcode tutorial. In previous versions of Xcode, there was an option like Image Literal. I will give you the best alternative way to achieve the same without having the Image Literal pick-up image option. Let fetchRequest: NSFetchRequest = User.fetchRequest()Īnd as mentioned I would also suggest you get the Core Data by Tutorials book.I am pretty much sure that you have reached this page because you are not able to see the Image Literal option anymore in Xcode Swift. NewUser.pic = #imageLiteral(resourceName: "jessica").jpegData(compressionQuality: 0.9) Long story short, here’s the code to make your project run: import UIKit Next, you try to set up the same object twice, then you try to assign a User to a property of type Data. Actually he lives below sea level in the Netherlands and is pretty down-to-earth but he does spend too much time in Xcode. On iPad, it’s difficult to get a name of an image. Always make sure to use the same name everywhere. 1 imageView.image You’ll find at the bottom in autocomplete a small icon with a mountain and sun. #imageLiteral(resourceName: "Jessica") should have been #imageLiteral(resourceName: "jessica"). This allows Xcode to run some optimizations for you and you don’t have to worry about the FileManager which you would have needed to get the image you were referring to. First of all you should add all assets to the asset catalog. Your code was a little hard to follow, but I think I found the issue. Let fetchRequest = NSFetchRequest(entityName: "User") Try context.save() //save object to CoreData Object.pic = newUser //add image to object Let object = User(context: context) //create object of type MyEntity NewUser.pic = #imageLiteral(resourceName: "Jessica").jpegData(compressionQuality: 0.9) as NSObject? as! Data Lazy var context = ( as! AppDelegate).persistentContainer.viewContext This is a link to gitHub GitHub - redrock34/lebron. When the code loads it should just save the image literal to the Xcode project. I am getting a complie error at object.pic = newUser stating Cannot assign value of type ‘User’ to type ‘Data?’. A image litteral is a image located locally within the xcode project. My swift code below is trying to save a image litteral to binary core data pic.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |