Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

I don't really grasp about NSData, NSMutableData, NSString in iOS, what should I learn?

hi,

I actually a beginner in iOS development, I am trying to make method that upload an image to a server. I understand the server side scripting in PHP, but when I am following a tutorial to upload an image in xcode, i don't really grasp about NSData, NSObject, NSMutableData, NSString, it seems the tutorial don't really explain about NSData, NSMutableData, NSString

what kind of topic in iOS development that I should learn to really understand about these things step by step? it seems that I never learn specifically about these things

``` func createBodyWithParameters(parameters: [String: String]?, filePathKey: String?, imageDataKey: NSData, boundary: String) -> NSData { let body = NSMutableData();

    if parameters != nil {
        for (key, value) in parameters! {
            body.appendString("--\(boundary)\r\n")
            body.appendString("Content-Disposition: form-data; name=\"\(key)\"\r\n\r\n")
            body.appendString("\(value)\r\n")
        }
    }

            let filename = "user-profile.jpg"
            let mimetype = "image/jpg"

            body.appendString("--\(boundary)\r\n")
            body.appendString("Content-Disposition: form-data; name=\"\(filePathKey!)\"; filename=\"\(filename)\"\r\n")
            body.appendString("Content-Type: \(mimetype)\r\n\r\n")
            body.appendData(imageDataKey)
            body.appendString("\r\n")



    body.appendString("--\(boundary)--\r\n")

    return body
}



func generateBoundaryString() -> String {
    return "Boundary-\(NSUUID().UUIDString)"
}

} extension NSMutableData {

func appendString(string: String) {
    let data = string.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: true)
    appendData(data!)
}

}