March is coming =w=..This month, still updating some tips and tutorials for swift. In this article, I am going to talk about how to use camera in swift. Basically, I will divide that into two categories:
Take a photo
Select a image from album
Get the image we want
In order to us the imagePicker, first, we need to let our viewController inherited with the UIImagePickerControllerDelegate and UINavigationControllerDelegate, do not forget the UINavigationControllerDelegate.
Now, we have got the image, and we may need to upload this image(will be discussed in the following posts, please check my blog often) to our server or display that image.
Get the image we want
The following code is for didFinishPickingImage, the argument image is the image we get, in this example, I replace the userIcon(UIImageViewController)’s image with the image I just get and store our image into the coreData. The image for the coreData is a NSData so do not forget to write UIImageJPEGRepresentation, I find that the picture iPhone take is jpeg.