Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Stinky_Pete posted:

you mean template classes?

Generic programming.

Adbot
ADBOT LOVES YOU

Space Whale
Nov 6, 2014
In a SQL Database, what's a good way to ensure idempotency for altering a table, creating a table, and inserting values only if they do not already exist in a table.

Especially in the later case, I want to make sure I'm following best practices.

If there's a SQL/DB thread I'll happily go there but I couldn't find it.

raminasi
Jan 25, 2005

a last drink with no ice

Space Whale posted:

In a SQL Database, what's a good way to ensure idempotency for altering a table, creating a table, and inserting values only if they do not already exist in a table.

Especially in the later case, I want to make sure I'm following best practices.

If there's a SQL/DB thread I'll happily go there but I couldn't find it.

SELECT * FROM Questions WHERE Type = 'Stupid'

Space Whale
Nov 6, 2014

JFC I'm living up to the name :downs:

I ctrl f'd for sql/db/data

LOOK I AM A TURTLE
May 22, 2003

"I'm actually a tortoise."
Grimey Drawer

Jsor posted:

What's the term for being able to make arbitrary "type-level" data structures? E.G. a compile-time function that works on an arbitrary sized list or tuple of types (but more general than just something like a variadic parameterization)? Is that what Higher-Kinded Types are for?

I can't really answer your question, but I can tell you that this is not what higher-kinded types are for -- at least not in terms of Haskell terminology. Higher-kinded types are parameterized types whose type parameters are also parameterized types. They're the type-level equivalent of higher-order functions.

I'll give a brief explanation of kinds in case it helps you find what you're looking for. In Haskell kind notation the symbol * is used to mean "type", and the symbol -> is used to separate parameters from each other and from the output type. Concrete types that take no parameters (e.g. Int, Bool) have the kind *, types that take a single type parameter (e.g. the list type) have the kind * -> *, types that take two type parameters (e.g. the map type, which has a key type and a value type) have the kind * -> * -> *, etc. Many languages support types with an arbitrary number of type parameters.

An example of a higher-kinded type would be something like the Monad typeclass, which has the kind (* -> *) -> *. Unlike the map type it only takes a single type parameter, but unlike the list type it stipulates that that type parameter must itself take a type parameter. A list may be parameterized with a type that has the kind * -> *, but Monad must be parameterized with such a type. It's like a function that takes a function as input, but on the type level.

As far as I know only a few widely used languages, such as Haskell and Scala, have general support for higher-kinded types.

Pie Colony
Dec 8, 2006
I AM SUCH A FUCKUP THAT I CAN'T EVEN POST IN AN E/N THREAD I STARTED

fosborb posted:

On a hosted app, we have a user who logged in and saw someone else's data. Logs show they both had the same JSESSIONID.

The vendor is claiming "lolrandom" but holy poo poo no way.

So, only 500 concurrent users at that time and excluding malicious action (it was self reported), any thoughts on what would cause a duplicate session id?

I'd guess it's some state being shared between threads that shouldn't be shared.

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

baka kaba posted:

Yeah and these are fantastic and important skills to learn, but when you're just starting with a language (especially if you're new to programming) you just want some small problems to tackle. I feel like PE quickly runs into stuff that's impossible to succeed at unless you do it the 'correct' way, like calculating large primes or adding ridiculously large numbers together. Good puzzles to think about, and deepen your understanding of a language and the tools available to it, but it just doesn't feel like a good fit for beginners. To me anyway :shobon:

Your point is well taken. I admit I did find Project Euler to be pretty damned difficult as a beginner (as I'm sure I would now if I went slightly deeper into it), but the struggle of reasoning through problems taught me a lot, I think. It may just come down to your learning style.

Gravity Pike
Feb 8, 2009

I find this discussion incredibly bland and disinteresting.

fosborb posted:

On a hosted app, we have a user who logged in and saw someone else's data. Logs show they both had the same JSESSIONID.

The vendor is claiming "lolrandom" but holy poo poo no way.

So, only 500 concurrent users at that time and excluding malicious action (it was self reported), any thoughts on what would cause a duplicate session id?

If I had to guess, I'd expect that this is some sort of mistake around ThreadLocal. Either they used private static Something instead of private static ThreadLocal<Something>, or they have code that touches a ThreadLocal running inside some sort of Executor, breaking the "one thread per HTTP request" expectation that a lot of services have.

Argyle Gargoyle
Apr 1, 2009

ABSTRACT SHAPES CREW

updated problem below

Argyle Gargoyle fucked around with this message at 00:43 on Sep 26, 2016

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line
It's not entirely clear from your post, but are you #including your hangman.h header file in your hangman.cpp file?

e: also you can just post your code here in-thread - just use the [ code] and [/ code] tags (absent the spaces)

JawKnee fucked around with this message at 07:20 on Sep 25, 2016

Stinky_Pete
Aug 16, 2015

Stinkier than your average bear
Lipstick Apathy
Are you not allowed to change the header? Sounds like it just needs include guards

JawKnee
Mar 24, 2007





You'll take the ride to leave this town along that yellow line

Argyle Gargoyle posted:

JawKnee, the assignment tells us to write the two definitions, so I'm not sure if putting #include "hangman.h" at the top of hangman.cpp is okay, but shouldn't it have the same effect as having that at the top of the main test.cpp which is compiled first? I'm throwing 4 errors with that include only in test.cpp but when I also put it at the top of hangman.cpp it turns into 19 errors.

Your errors likely have to do with other problems in your playHangman function (there are quite a few, so you'll need to dig in) rather than a dependency issue (although if you want to use cout your hangman.cpp file is going to need access to <iostream>. It seems like you're not entirely sure what's going on when you include something in a particular file, and I'm probably not the best person to explain it, but here goes (doubtless someone else will correct me if I'm wrong or using incorrect language or whatever):

When you include a header file you've written (or a standard library include like <iostream>) you are (generally) providing access to that header's classes and functions to the file that has the #include statement in it, and also to any file that is #including the file with that initial #include statement. Think of that availability as moving downstream through files via those statements.

As an example, just in case I've confused you:

code:
//here is a file called A.h
//assume that the functions here have been defined in A.cpp
#include <iostream>

int doSomethingA(int);
code:
//here is a file called B.h
//assume that the functions here have been defined in B.cpp
#include "A.h"

int doSomethingB(int);
code:
//finally here is a file called my_main.cpp
#include "B.h"

int main(int argc, char** argv) {
	int input_to_a = 10;
	int input_to_b = 20;
	int a = doSomethingA(input_to_a);
	int b = doSomethingB(input_to_b);
	std::cout << a << ", " << b << std::endl;
}
note that I've called my two functions doSomethingA and doSomethingB from my_main.cpp - this is fine, because my_main is #including B.h, which in turn is including A.h, so my_main has access to doSomethingA via B.h. Also note that I'm using cout in my_main.cpp, even though I haven't #included <iostream> - this is also available through A.h.

Still with me? Then let's define another 2 files here:

code:
//This is the file named no_includes.h

int doSomethingC(int);
code:
//This is the file named no_includes.cpp
int doSomethingC(int c){
	int ret_val = c + 50;
	std::cout << ret_val << std::endl;
	return ret_val;
}
and let's alter our my_main.cpp file like so:

code:
//finally here is a file called my_main.cpp
#include "B.h"
[b]#include "no_includes.h"[/b]

int main(int argc, char** argv) {
	int input_to_a = 10;
	int input_to_b = 20;
	int a = doSomethingA(input_to_a);
	int b = doSomethingB(input_to_b);
	[b]int c = doSomethingC( 10 );[/b]
	std::cout << a << ", " << b << std::endl;
}
We run into some errors when we try to compile this into something we can run; this is because even though we've #included no_includes.h in my_main.cpp, the availability of the code in "my_main.cpp" is not visible to "no_includes.cpp". This isn't actually a problem for the functions we defined in no_includes.cpp being called in my_main.cpp - they should be able to be called - the main problem is that our no_includes.cpp file doesn't have access to the files we've included in A.h (namely, to <iostream>). In fact, even if we put #include <iostream> in no_includes.h our code in no_includes.cpp still wouldn't have access to it (and worse, our my_main.cpp would now have access to <iostream> twice via B.h <- A.h, and we run into errors there too).

So the reason I asked whether you've included your hangman.h file in your hangman.cpp file is that you've included <string> there, and your hangman.cpp file cannot access <string> merely by being itself included in test.cpp - dependencies don't flow in that direction.

Hopefully someone with more knowledge than me will clean up my description here, as I don't think I've properly gotten across why the particular problem you first stated is happening. However, as I noted above, you do have a number of other errors in your code that are not caused by this particular problem.

JawKnee fucked around with this message at 18:37 on Sep 25, 2016

denzelcurrypower
Jan 28, 2011
Is there a mobile development/android thread?

Anyone have suggestions on getting Android Studio emulator to work with AMD processors? I tried using the ARM system image and it took about an hour to boot up before giving a bunch of errors and crashing.

Stinky_Pete
Aug 16, 2015

Stinkier than your average bear
Lipstick Apathy
#include literally instructs the compiler to copy and paste the contents of the file to where the include statement is

Argyle Gargoyle
Apr 1, 2009

ABSTRACT SHAPES CREW

Okay, so I have to have #include "hangman.h" in hangman.cpp for the functions in hangman.cpp to have access to <string> (via hangman.h), despite hangman.h being #included at the top of the main. Right?

What I am confused about now is how do I give hangman.cpp access to <iostream> if I can't #include <iostream> at the top of it because, as you say, that would give the main access to it twice which will not work?
Is it correct, then, that C++ allows you to give the main access to an individual file multiple times (here, hangman.h via main and hangman.cpp), while also disallowing you from doing this with libraries?

I am assuming my hangman.cpp does not have access to <iostream> because when I attempt to compile the below code (test.cpp and hangman.cpp) I get this error:

code:
hangman.cpp: In function 'bool playHangman(std::__cxx11::string, unsigned int)':

hangman.cpp:32:3: error: 'cout' is not a member of 'std'
   std::cout << "You have made " << (startingGuesses - maxWrong) << " incorrect guess(es)," << '\n';
   ^
e: removed walls of code

Argyle Gargoyle fucked around with this message at 05:15 on Sep 26, 2016

Fergus Mac Roich
Nov 5, 2008

Soiled Meat

Argyle Gargoyle posted:

Okay, so I have to have #include "hangman.h" in hangman.cpp for the functions in hangman.cpp to have access to <string> (via hangman.h), despite hangman.h being #included at the top of the main. Right?

What I am confused about now is how do I give hangman.cpp access to <iostream> if I can't #include <iostream> at the top of it because, as you say, that would give the main access to it twice which will not work?
Is it correct, then, that C++ allows you to give the main access to an individual file multiple times (here, hangman.h via main and hangman.cpp), while also disallowing you from doing this with libraries?

I am assuming my hangman.cpp does not have access to <iostream> because when I attempt to compile the below code (test.cpp and hangman.cpp) I get this error:
<debugging>

This is the key:


Stinky_Pete posted:

#include literally instructs the compiler to copy and paste the contents of the file to where the include statement is

So if hangman.cpp is including hangman.h, where should <iostream> come from?

Argyle Gargoyle
Apr 1, 2009

ABSTRACT SHAPES CREW

Fergus Mac Roich posted:

So if hangman.cpp is including hangman.h, where should <iostream> come from?

I really don't know. I guess you're hinting that <iostream> should come from hangman.h but this must be flying over my head.
Doesn't that still give the main access to <iostream> twice when test.cpp and hangman.cpp are compiled together (as per 'g++ test.cpp hangman.cpp -o hangman')?
#include "hangman.h" at the top of hangman.cpp will just copy-paste the contents of hangman.h there.

hangman.h was provided to us for this assignment and we were only told to write the functions playHangman and guessLetter in the file hangman.cpp, so I believe that adding to the header file might not be the intended way to solve this, if the problem I stated above were otherwise resolved.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

Argyle Gargoyle posted:

I really don't know. I guess you're hinting that <iostream> should come from hangman.h but this must be flying over my head.
Doesn't that still give the main access to <iostream> twice when test.cpp and hangman.cpp are compiled together (as per 'g++ test.cpp hangman.cpp -o hangman')?
#include "hangman.h" at the top of hangman.cpp will just copy-paste the contents of hangman.h there.

hangman.h was provided to us for this assignment and we were only told to write the functions playHangman and guessLetter in the file hangman.cpp, so I believe that adding to the header file might not be the intended way to solve this, if the problem I stated above were otherwise resolved.

OK, so there's a few things I think will help you here:

First, test.cpp and hangman.cpp are not compiled together. They are unrelated, and do not affect each other. They are separate things. It just so happens that after being compiled, the results are getting put together to result in a complete program. But nothing you change in one will affect how the other is compiled.

Second, you can include <iostream> as many times as you want and it will act exactly the same as only including it once. System headers have guards that prevent them from misbehaving if included multiple times.

Third, there is no difference between including something in a .cpp file, and including something in a .h file which is included by that .cpp file. You should include headers in whatever files use things from those headers. You should put includes in header files if any use of that header would require also using the included header, because it makes it a little easier to avoid stupid mistakes.

Finally, this is something that's a lot easier to understand if you see what the preprocessor is actually doing. I'd strongly recommend making an appointment with your TA or professor and asking them to show you some examples of what the preprocessor does with a few simple files, independently of any of the C++ aspects of your assignment. You can play with the preprocessor on your own with "g++ -E", but I suspect you'll get a lot more out of a short guided example.

Argyle Gargoyle
Apr 1, 2009

ABSTRACT SHAPES CREW

Thanks a lot everybody, you greatly improved my understanding. It took my weekend but I've now got the program working beautifully and learned a great deal about C++.

I think I've uncovered a love of programming. :getin:

well why not
Feb 10, 2009




I've been staring at this Javascript issue for ages and I suspect I've lost all perspective on it. I'm making something along the lines of a dressup game (you pick clothes / skin colour / accessories and they show on an image [no it is not anime] ) and you're able to select items, but all the content in the object resets every time you select an item. Here's the relevant JS:

code:

	function selectorChoice (value, type, member, gender) {

		var gender = gender;

		path = 'm';

		// Define item and it's path

		// var itemID = 

		var itemSelection = './images/' + path + '/' + type + '-' + value + '.svg' ;

		var itemSelection = itemSelection;			

		// console.log(itemSelection);

		Creator(gender, itemSelection, value, type);


	}

function Creator(gender, itemSelection, value, type) {
	
		// Build an object

		var build = [{
			skin: 1,
			hair: 1,
			brows: 1,
			eyes: 1,
			nose: 1,
			mouth: 1
		}];

		
		var updateType = type;
		var updateValue = value;

		var update = [{
			type: value
		}]

		// Update the object via extend - this puts the new values into 'build'.
		for (var i = build.length - 1; i >= 0; i--) {
	
			if (key = updateType) {
				build[i][type] = updateValue
				
				console.log(type + ' -> ' + updateValue )

			}
			
		}

So, when the use selects hair 2 it logs out the object with hair 2 selected. If they then go on to select say, eyes 3, hair 1 is in the object. How can I make the values inside the object persist? I'm guessing I have to update the object, rather than replace it altogether.

nielsm
Jun 1, 2009



code:
if (key = updateType) {
This changes the value of "key" to be that of "updateType", then chooses the branch if the value assigned is truthy.

I think you meant to write:
code:
if (key == updateType) {
which will compare the two variables instead of assigning.

well why not
Feb 10, 2009




hey! thanks. Except now, i get 'key is not defined'.

Kuule hain nussivan
Nov 27, 2008

well why not posted:

hey! thanks. Except now, i get 'key is not defined'.
That seems to be a straightforward case of not having defined 'key'. What is it supposed to be?

nielsm
Jun 1, 2009



Yeah lots of things look very suspicious about your code, and I'd suggest you start out with describing the purpose of each and every variable and function.

well why not
Feb 10, 2009




nielsm posted:

Yeah lots of things look very suspicious about your code, and I'd suggest you start out with describing the purpose of each and every variable and function.

Yeah, like I said, this is getting overcooked in my brain! Appreciate the eyes on it. I've added some extra comments explaining what I'd expect to be happening at each stage of the main function.

code:
	// Build the person with the gender, itemSelection, value & type.  
	function Creator(gender, itemSelection, value, type) {
	
		// Build as an object - these are the default attributes that will be replaced when an update is run.

		var build = [{
			skin: 1,
			hair: 1,
			brows: 1,
			eyes: 1,
			nose: 1,
			mouth: 1
		}];

		// These vars define what's changing about the person.
		
		var updateType = type;
		var updateValue = value;

		// Step through each value or 'attribute' of the build. Eyes, skin, hair etc.
		for (var i = build.length - 1; i >= 0; i--) {
	
			// Compare the values with what's being updated, replace the value with the new content.
			if (build[i] == updateType) {
				build[i][type] = updateValue;

			}
			
		}

Dr. Stab
Sep 12, 2010
👨🏻‍⚕️🩺🔪🙀😱🙀
So, it looks like what you're trying to do is something like this.

code:
var build = {
	skin: 1,
	hair: 1,
	brows: 1,
	eyes: 1,
	nose: 1,
	mouth: 1
};
build[type] = value;
But given that this is an create function and not an "initialize all to default values except for one entry and then not return anything" function, This probably isn't entirely what you want.

e: to clarify what you were doing: You initialized build to an array with one element, that element being a dictionary defining your attributes. Then, you iterated over that one element, checked to see if your type parameter was the dictionary, then added a copy of the dictionary as a key to the dictionary, with the value being whatever you passed into value.

e2: Looking back at your original post. It sounds like you're having trouble with making this persist. Where are you storing the state of your current build? Because right now, that function defines a local variable and doesn't return anything, so that build doesn't exist outside the life of that function.

Dr. Stab fucked around with this message at 17:46 on Sep 26, 2016

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

well why not posted:

I've been staring at this Javascript issue for ages and I suspect I've lost all perspective on it

I've had this one problem that I've been trying to solve for literally probably 8 years. For the past few years I've spent a 10-20 hours/week for a few weeks out of each year hoping I'll make some headway on it after spending some time away and learning new stuff.

I think this week I finally figured it out!

I'm too embarrassed to describe the actual problem because I've always known it was because of my weak formal CS background. Anyway, my point is not so much for you exactly, but just to highlight for anyone who cares that if you bang your head against something long enough you might come up with a solution!

(also I'm just excited to have made progress on this thing finally)

Klades
Sep 8, 2011

well why not posted:

Yeah, like I said, this is getting overcooked in my brain! Appreciate the eyes on it. I've added some extra comments explaining what I'd expect to be happening at each stage of the main function.

code:
	// Build the person with the gender, itemSelection, value & type.  
	function Creator(gender, itemSelection, value, type) {
	
		// Build as an object - these are the default attributes that will be replaced when an update is run.

		var build = [{
			skin: 1,
			hair: 1,
			brows: 1,
			eyes: 1,
			nose: 1,
			mouth: 1
		}];

		// These vars define what's changing about the person.
		
		var updateType = type;
		var updateValue = value;

		// Step through each value or 'attribute' of the build. Eyes, skin, hair etc.
		for (var i = build.length - 1; i >= 0; i--) {
	
			// Compare the values with what's being updated, replace the value with the new content.
			if (build[i] == updateType) {
				build[i][type] = updateValue;

			}
			
		}

Disclaimer: I'm not super great at JavaScript

Is there a particular reason you're making a totally new object instead of just making one and updating it? That seems like it would be much more straightforward than this.
Something like
code:
function Person() {
  this.skin = 1;
  this.hair = 1;
// etc.
}
Then somewhere you do
code:
var currentPerson = new Person();
And to update you can just
code:
currentPerson["hair"] = someValue;

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
Oh coding experts please help me!

I am doing my first app in Swift and have an issue with an image picker. I have (finally) managed to get the bloody thing to compile and got to the stage where I select the image. The problem is that I want to set the UIimageView I have in the storyboard to the image. Currently it just closes the picker and leaves me with no change at all.

I know the code is ugly but you gotta learn somewhere right?

code:
import UIKit

class RegistrationController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
  
    
    // Getting Registration Details
    
    @IBOutlet weak var imagePicked: UIImageView!
    @IBOutlet weak var lastNameInput: UITextField!
    @IBOutlet weak var firstNameInput: UITextField!
    @IBOutlet weak var passwordInput: UITextField!
    @IBOutlet weak var emailInput: UITextField!

    
    
    // Hiding the NavBar
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.navigationController?.setNavigationBarHidden(true, animated: true)
        
    }
    
    //Image Picker Code



    @IBAction func openCameraButton(_ sender: AnyObject) {
        
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
            let imagePicker = UIImagePickerController()

            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
            imagePicker.allowsEditing = false
            self.present(imagePicker, animated: true, completion: nil)
        }
    }
    
    @IBAction func openPhotoLibraryButton(_ sender: AnyObject) {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
            imagePicker.allowsEditing = true
            self.present(imagePicker, animated: true, completion: nil)
        }
    }

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        imagePicked.image = image
        self.dismiss(animated: true, completion: nil);
    }
    
    
    //End of Image Picker Code

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    
    }

    
    
}

well why not
Feb 10, 2009




thanks for all the help guys, I'l dip in and see how I go. Appreciate the eyes on this.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

thegasman2000 posted:

Oh coding experts please help me!

I am doing my first app in Swift and have an issue with an image picker. I have (finally) managed to get the bloody thing to compile and got to the stage where I select the image. The problem is that I want to set the UIimageView I have in the storyboard to the image. Currently it just closes the picker and leaves me with no change at all.

I know the code is ugly but you gotta learn somewhere right?

code:
import UIKit

class RegistrationController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
    
  
    
    // Getting Registration Details
    
    @IBOutlet weak var imagePicked: UIImageView!
    @IBOutlet weak var lastNameInput: UITextField!
    @IBOutlet weak var firstNameInput: UITextField!
    @IBOutlet weak var passwordInput: UITextField!
    @IBOutlet weak var emailInput: UITextField!

    
    
    // Hiding the NavBar
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        
        self.navigationController?.setNavigationBarHidden(true, animated: true)
        
    }
    
    //Image Picker Code



    @IBAction func openCameraButton(_ sender: AnyObject) {
        
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.camera) {
            let imagePicker = UIImagePickerController()

            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.camera;
            imagePicker.allowsEditing = false
            self.present(imagePicker, animated: true, completion: nil)
        }
    }
    
    @IBAction func openPhotoLibraryButton(_ sender: AnyObject) {
        if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
            let imagePicker = UIImagePickerController()
            imagePicker.delegate = self
            imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
            imagePicker.allowsEditing = true
            self.present(imagePicker, animated: true, completion: nil)
        }
    }

func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
        imagePicked.image = image
        self.dismiss(animated: true, completion: nil);
    }
    
    
    //End of Image Picker Code

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
    
    }

    
    
}

Have you connected your UIImageView to your IBOutlet? It should appear under referencing outlets when you right-click the image view on the storyboard.

e: I'm also seeing that imagePickerController:didFinishPickingImage:editingInfo is deprecated, maybe try replacing it with imagePickerController(_:didFinishPickingMediaWithInfo:)? https://developer.apple.com/reference/uikit/uiimagepickercontrollerdelegate/1619126-imagepickercontroller

carry on then fucked around with this message at 21:18 on Sep 26, 2016

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
Yep its linked as

@IBOutlet weak internal var imagePicked: UIImageView!

I just don't get how to assign the image picked to that view.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

thegasman2000 posted:

Yep its linked as

@IBOutlet weak internal var imagePicked: UIImageView!

I just don't get how to assign the image picked to that view.

And that link shows up as a filled circle in the margin next to that line of code? Not accusing you of anything, just doing the same double checking I would do with my own because I have made that mistake before.

I'm not in front of Xcode at the moment, but I think you're doing the right thing in terms of assigning it to the UIImageView's image property. I'm not sure you're getting what you're expecting. passed into the method though...

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
No I appreciate it! This is a screenshot of the viewcontroller and the storyboard. Seems all linked up.

http://imgur.com/a/vpg0C

As I say I am new to this... Its all very hacky and having no tutorials in Swift 3.0 makes it more confusing as xcode is changing everything I paste in.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

thegasman2000 posted:

No I appreciate it! This is a screenshot of the viewcontroller and the storyboard. Seems all linked up.

http://imgur.com/a/vpg0C

As I say I am new to this... Its all very hacky and having no tutorials in Swift 3.0 makes it more confusing as xcode is changing everything I paste in.

Hmm okay. Nothing looks outright wrong there. Do you know for sure that the image is coming in, and that the code is getting inside the if let to set the imagePicked.image?

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

carry on then posted:

Hmm okay. Nothing looks outright wrong there. Do you know for sure that the image is coming in, and that the code is getting inside the if let to set the imagePicked.image?

I don't to be honest. I get into the photo library and select the image, then it reloads the view and nothing is different. Perhaps adding a few prints will show me where it falling over?

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

thegasman2000 posted:

I don't to be honest. I get into the photo library and select the image, then it reloads the view and nothing is different. Perhaps adding a few prints will show me where it falling over?

That would work, or you can use the debugger. Set a breakpoint by clicking in the left margin (I see you have one or two there already) and if execution gets to that line, it'll pause. So if you put one on the imagePicked.image = image line, it'd stop if it was getting in there and you could inspect your variables at that time.

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:
Ok so its not finishing the

code:
private func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
        if let pickedImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            imagePicked.contentMode = .scaleAspectFit
            imagePicked.image = pickedImage
            print("imagePickerController completed")
        }

As I don't see the print I added. I accidentally add breakpoints all the time :( I don't fully know how to use the debugger tbh.

carry on then
Jul 10, 2010

by VideoGames

(and can't post for 10 years!)

Okay, good. Now we know that what you're getting out of info for UIImagePickerControllerOriginalImage is nil, because it doesn't pass the if let. So for some reason there is no original image coming back. When you are doing this, are you using the camera or picking from your library?

Adbot
ADBOT LOVES YOU

thegasman2000
Feb 12, 2005
Update my TFLC log? BOLLOCKS!
/
:backtowork:

carry on then posted:

Okay, good. Now we know that what you're getting out of info for UIImagePickerControllerOriginalImage is nil, because it doesn't pass the if let. So for some reason there is no original image coming back. When you are doing this, are you using the camera or picking from your library?

Picking from the library. I was under the impression the simulator doesn't like activating the camera so just testing the library for now.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply