I'm a beginner in programming.
Please refer to the code on the website below to study swift. https://youtachannel.com/swift-storyboard-size/
I was creating a code that separates the storyboard by device.
I was putting a lot of additional codes in the original, but an error code came out.
Work has been interrupted.
If you know how to remove this error, I would appreciate your help.
Just in case, I have returned the screenshot showing the error, so I have attached this image as well.
I'm very sorry, but I appreciate your cooperation.
error codes:Expected declaration (line 34)
import UIKit
@UIAapplicationMain
![Enter image description here][1][1]classAppDelegate:UIResponder,UIApplicationDelegate{
var window —UIWindow?
func application(application:UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) ->Bool{
let storyboard —UIStoryboard=self.grabStoryboard()
iflet window = window {
window.rootViewController=storyboard.instantiateInitialViewController()
}
self.window?makeKeyAndVisible()
return true
}
func grabStoryboard()->UISstoryboard{
_=UIStoryboard()
_=UISscreen.mainScreen().bounds.size.height
// iPhone 6
}; else if height == 667 {
storyboard = UIStoryboard (name: "6S", bundle:nil)
// iPhone 6 Plus
} else if height == 736 {
storyboard = UIStoryboard (name: "6SPlus", bundle:nil)
// iPhone 4s
} else if height == 480 {
storyboard = UIStoryboard (name: "4S", bundle:nil)
// iPhone 5, 5s, 5c
} else if height == 568 {
storyboard = UIStoryboard (name: "5S_5C", bundle:nil)
// iPad
} else if height == 1024 {
storyboard=UIStoryboard(name: "iPad", bundle:nil)
// iPad Pro
} else if height == 1366 {
storyboard=UIStoryboard(name: "iPad_Pro", bundle:nil)
return storyboard
}
func applicationWillResignActive (application:UIApplication) {
// Sent when the application is about to move from active to inactive state. This can account for certificate of temporary interventions (succ as an incoming phone call or SMS message) or when the user quits the application and it starts the transition to the background state.
// Use this method to pauseongoing tasks, disable timers, and throttle down OpenGLES frame rates. Games should use this method to pause the game.
}
func applicationDidEnterBackground(application:UIApplication){
// Use this method to release shared resources, save user data, invalidate timers, and store through application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called installed of applicationWillTerminate: when the user quits.
}
func applicationWillEnterForeground (application:UIApplication) {
// Called as part of the transition from the background to the inactive state; here you can do many of the changes made on entering the background.
}
func applicationDidBecomeActive(application:UIApplication){
// Restart any tasks that were pressed (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
US>func applicationWillTerminate (application:UIApplication) {
// Called when the application is about to terminate.Save data if approve.See also applicationDidEnterBackground:.
}
}
I think it's necessary to get people to see and hit the code that contains the bad points, but I think the code you're presenting now has too many places to hit and too many things to get into your head at once.Before you start working on the actual app, I think it would be better to start the Swift language once again (this is Japanese and it's hard to find good resources…) properly.
Also, switching the storyboard finely to match the pixel size of each device is not Apple's recommended solution.Apple recommends that you use Auto Layout and Size Class (in this case, class is not what we call an object-oriented programming language, but just a rough classification), so you should learn how to deal with it (after a little more learning).
(When developing an app in Japan, the layout design may come down as a requirement for each pixel, so you may eventually need to separate the Storyboard by device, but you can only deal with such a special situation after you start working on it.)
This is not the answer, so let's just go back to your code.
"Your code is ""I made a wrong code correction first"" → ""I became more and more strange because I followed Xcode's not accurate."""It is more difficult to correct each grammatical error when it gets this bad.
Let's undo it.
(If you haven't learned the functions of the source code management system such as git, you should learn them.If you have a habit of committing frequently.It's easy to get back to the old state.)
func grabStoryboard()
of the original code presented at the link contains bad writing methods that beginners do not want to copy, so
var storyboard=UIStoryboard()//<- Creating an unused instance
Let's start from around here where we fixed it.
// Separate Storyboard
func grabStoryboard()->UISstoryboard{
let storyboard:UIStoryboard
let height = UISscreen.mainScreen().bounds.size.height
// iPhone 6
if height == 667 {
storyboard = UIStoryboard (name: "6S", bundle:nil)
// iPhone 6 Plus
} else if height == 736 {
storyboard = UIStoryboard (name: "6SPlus", bundle:nil)
// iPhone 4s
} else if height == 480 {
storyboard = UIStoryboard (name: "4S", bundle:nil)
// iPhone 5, 5s, 5c
} else{
storyboard = UIStoryboard (name: "5S_5C", bundle:nil)
}
return storyboard
}
(The name of the storyboard has been matched to your code.)
"The following phrase in the article from which you are referring, ""By the way, if you want to support your iPad, add the following code before else"" says ""before else"", so you have to do this after adding it."
func grabStoryboard()->UIStoryboard{
let storyboard:UIStoryboard
let height = UISscreen.mainScreen().bounds.size.height
// iPhone 6
if height == 667 {
storyboard = UIStoryboard (name: "6S", bundle:nil)
// iPhone 6 Plus
} else if height == 736 {
storyboard = UIStoryboard (name: "6SPlus", bundle:nil)
// iPhone 4s
} else if height == 480 {
storyboard = UIStoryboard (name: "4S", bundle:nil)
// iPad
} else if height == 1024 {
storyboard=UIStoryboard(name: "iPad", bundle:nil)
// iPhone 5, 5s, 5c
} else{
storyboard = UIStoryboard (name: "5S_5C", bundle:nil)
}
return storyboard
}
I will leave the part to add the code for iPad_Pro as your homework.
I will not write about each error, but please correct it while checking where and what grammatical errors were.(If you have any questions next time, it would be better to show the code for the condition before it gets this bad... before accepting Xcode Suggestion without knowing what it means.)
Again, if you can't fix this kind of grammatical error yourself, it would be much more beneficial to learn how to use Constraint in Auto Layout before learning to handle special situations such as "Code to separate Storyboards by device."
© 2024 OneMinuteCode. All rights reserved.