Xcode error- expected declaration in UIViewHow to “add existing frameworks” in Xcode 4?Version vs build in XcodeHow to download Xcode DMG or XIP file?UIScrollView Scrollable Content Size AmbiguityXcode process launch failed: SecurityiOS get NSInvalidArgumentException when implementing Auto Layout programmaticallyXcode error “Could not find Developer Disk Image”Xcode 7 error: “Missing iOS Distribution signing identity for …”Issues with casting celltypes to dequeueThe view hierarchy is not prepared for the constraint inside init with frame initializer
How can I prevent Bash expansion from passing files starting with "-" as argument?
How to plot a surface from a system of equations?
Why favour the standard WP loop over iterating over (new WP_Query())->get_posts()?
Why aren't satellites disintegrated even though they orbit earth within earth's Roche Limits?
Richard's Favourite TV Programme
Why does the U.S military use mercenaries?
On a piano, are the effects of holding notes and the sustain pedal the same for a single chord?
Is a reptile with diamond scales possible?
In Dutch history two people are referred to as "William III"; are there any more cases where this happens?
What's is the easiest way to purchase a stock and hold it
Is it wise to pay off mortgage with 401k?
Does science define life as "beginning at conception"?
What does this 'x' mean on the stem of the voice's note, above the notehead?
Warped chessboard
In How Many Ways Can We Partition a Set Into Smaller Subsets So The Sum of the Numbers In Each Subset Is Equal?
What were the "pills" that were added to solid waste in Apollo 7?
Bash Array of Word-Splitting Headaches
Why is so much ransomware breakable?
Can I have a delimited macro with a literal # in the parameter text?
What should I wear to go and sign an employment contract?
How to fix "webpack Dev Server Invalid Options" in Vuejs
Is it possible to view all the attribute data in QGIS
Would it be possible to set up a franchise in the ancient world?
Can a problematic AL DM/organizer prevent me from running a separatate AL-legal game at the same store?
Xcode error- expected declaration in UIView
How to “add existing frameworks” in Xcode 4?Version vs build in XcodeHow to download Xcode DMG or XIP file?UIScrollView Scrollable Content Size AmbiguityXcode process launch failed: SecurityiOS get NSInvalidArgumentException when implementing Auto Layout programmaticallyXcode error “Could not find Developer Disk Image”Xcode 7 error: “Missing iOS Distribution signing identity for …”Issues with casting celltypes to dequeueThe view hierarchy is not prepared for the constraint inside init with frame initializer
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to make something using Swift playgrounds and am confused with auto layouts. I tried to use auto layouts but am ending up with an error "Expected declaration"
Here is my code - I've only added the parts that are relevant
import Foundation
import UIKit
import SpriteKit
public class GameView : UIView{
// let GameView : UIView!
override public init(frame: CGRect)
super.init(frame: CGRect(x: 0, y: 0, width: 1500, height: 1000))
GameView.translatesAutoresizingMaskIntoConstraints = false
public override func addConstraints(_ constraints: [NSLayoutConstraint])
self.addConstraints([
NSLayoutConstraint(item: GameView.self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: GameView.self, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0),
])
ios swift xcode
add a comment |
I'm trying to make something using Swift playgrounds and am confused with auto layouts. I tried to use auto layouts but am ending up with an error "Expected declaration"
Here is my code - I've only added the parts that are relevant
import Foundation
import UIKit
import SpriteKit
public class GameView : UIView{
// let GameView : UIView!
override public init(frame: CGRect)
super.init(frame: CGRect(x: 0, y: 0, width: 1500, height: 1000))
GameView.translatesAutoresizingMaskIntoConstraints = false
public override func addConstraints(_ constraints: [NSLayoutConstraint])
self.addConstraints([
NSLayoutConstraint(item: GameView.self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: GameView.self, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0),
])
ios swift xcode
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
I see you are placingGameView
constraints insideGameView
. While this *may work, why not put these in theUIViewController
that instantiatesGameView
? If thisUIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement ofGameView
in it.And to be honest? Those last 2 constraints make no sense. You're settingGameView
to be centered too... itself. (At least by the code you posted.) Good luck!
– dfd
Mar 23 at 21:31
add a comment |
I'm trying to make something using Swift playgrounds and am confused with auto layouts. I tried to use auto layouts but am ending up with an error "Expected declaration"
Here is my code - I've only added the parts that are relevant
import Foundation
import UIKit
import SpriteKit
public class GameView : UIView{
// let GameView : UIView!
override public init(frame: CGRect)
super.init(frame: CGRect(x: 0, y: 0, width: 1500, height: 1000))
GameView.translatesAutoresizingMaskIntoConstraints = false
public override func addConstraints(_ constraints: [NSLayoutConstraint])
self.addConstraints([
NSLayoutConstraint(item: GameView.self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: GameView.self, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0),
])
ios swift xcode
I'm trying to make something using Swift playgrounds and am confused with auto layouts. I tried to use auto layouts but am ending up with an error "Expected declaration"
Here is my code - I've only added the parts that are relevant
import Foundation
import UIKit
import SpriteKit
public class GameView : UIView{
// let GameView : UIView!
override public init(frame: CGRect)
super.init(frame: CGRect(x: 0, y: 0, width: 1500, height: 1000))
GameView.translatesAutoresizingMaskIntoConstraints = false
public override func addConstraints(_ constraints: [NSLayoutConstraint])
self.addConstraints([
NSLayoutConstraint(item: GameView.self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: GameView.self, attribute: .centerX, relatedBy: .equal, toItem: self, attribute: .centerX, multiplier: 1.0, constant: 0),
NSLayoutConstraint(item: GameView.self, attribute: .centerY, relatedBy: .equal, toItem: self, attribute: .centerY, multiplier: 1.0, constant: 0),
])
ios swift xcode
ios swift xcode
asked Mar 23 at 18:43
Uditi Uditi
263
263
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
I see you are placingGameView
constraints insideGameView
. While this *may work, why not put these in theUIViewController
that instantiatesGameView
? If thisUIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement ofGameView
in it.And to be honest? Those last 2 constraints make no sense. You're settingGameView
to be centered too... itself. (At least by the code you posted.) Good luck!
– dfd
Mar 23 at 21:31
add a comment |
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
I see you are placingGameView
constraints insideGameView
. While this *may work, why not put these in theUIViewController
that instantiatesGameView
? If thisUIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement ofGameView
in it.And to be honest? Those last 2 constraints make no sense. You're settingGameView
to be centered too... itself. (At least by the code you posted.) Good luck!
– dfd
Mar 23 at 21:31
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
I see you are placing
GameView
constraints inside GameView
. While this *may work, why not put these in the UIViewController
that instantiates GameView
? If this UIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement of GameView
in it.And to be honest? Those last 2 constraints make no sense. You're setting GameView
to be centered too... itself. (At least by the code you posted.) Good luck!– dfd
Mar 23 at 21:31
I see you are placing
GameView
constraints inside GameView
. While this *may work, why not put these in the UIViewController
that instantiates GameView
? If this UIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement of GameView
in it.And to be honest? Those last 2 constraints make no sense. You're setting GameView
to be centered too... itself. (At least by the code you posted.) Good luck!– dfd
Mar 23 at 21:31
add a comment |
1 Answer
1
active
oldest
votes
I think you're overriding the view's addConstraints
function but it's never being called. I think if you remove it and add this code to the end of your initialiser it should set up the constraints properly.
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64)
])
(The last two constraints, the center X and Y, aren't doing anything because it's constraining the center X of the view to itself. Also I think you mean self
where you have GameView.self
)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317191%2fxcode-error-expected-declaration-in-uiview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think you're overriding the view's addConstraints
function but it's never being called. I think if you remove it and add this code to the end of your initialiser it should set up the constraints properly.
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64)
])
(The last two constraints, the center X and Y, aren't doing anything because it's constraining the center X of the view to itself. Also I think you mean self
where you have GameView.self
)
add a comment |
I think you're overriding the view's addConstraints
function but it's never being called. I think if you remove it and add this code to the end of your initialiser it should set up the constraints properly.
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64)
])
(The last two constraints, the center X and Y, aren't doing anything because it's constraining the center X of the view to itself. Also I think you mean self
where you have GameView.self
)
add a comment |
I think you're overriding the view's addConstraints
function but it's never being called. I think if you remove it and add this code to the end of your initialiser it should set up the constraints properly.
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64)
])
(The last two constraints, the center X and Y, aren't doing anything because it's constraining the center X of the view to itself. Also I think you mean self
where you have GameView.self
)
I think you're overriding the view's addConstraints
function but it's never being called. I think if you remove it and add this code to the end of your initialiser it should set up the constraints properly.
self.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
NSLayoutConstraint(item: self, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .width, multiplier: 1.0, constant: 64),
NSLayoutConstraint(item: self, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .height, multiplier: 1.0, constant: 64)
])
(The last two constraints, the center X and Y, aren't doing anything because it's constraining the center X of the view to itself. Also I think you mean self
where you have GameView.self
)
answered Mar 23 at 20:31
Tom PearsonTom Pearson
28917
28917
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55317191%2fxcode-error-expected-declaration-in-uiview%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Looks to me like you need to learn more about two things - a view controller's "life cycle" or "the sequence of events being fired" and how to use auto layout. (On the latter, I much prefer anchor-based code instead of your style, but either should work.) I have one more suggestions involving how both of these tie together....
– dfd
Mar 23 at 21:25
I see you are placing
GameView
constraints insideGameView
. While this *may work, why not put these in theUIViewController
that instantiatesGameView
? If thisUIView
has subviews, that's the constraints you want to put inside there. (And please, do it on initialization. No sense in doing repeated work!) It's the view controller that should know things like the size of it's view and the placement ofGameView
in it.And to be honest? Those last 2 constraints make no sense. You're settingGameView
to be centered too... itself. (At least by the code you posted.) Good luck!– dfd
Mar 23 at 21:31