Swift 3 Fun Algorithms: Wrapping an Array

Поділитися
Вставка
  • Опубліковано 8 січ 2025

КОМЕНТАРІ • 70

  • @SuadBayramoglu
    @SuadBayramoglu 8 років тому +10

    This is just great! Especially because you did not show just a regular algorithm but a real application of an algorithm in a real application.
    Thank you very much Brian,
    You are just Awesome!

    • @Ilyesbensalem91
      @Ilyesbensalem91 8 років тому +5

      I totally agree, especially in a real application.

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +12

      Thanks guys, you'll notice this theme of real application programming most of my videos. I try not to present things unless there is a good context in which you can understand the topic. Hope you guys enjoy another algorithms video next week.

  • @kennygunderman
    @kennygunderman 8 років тому +6

    This is awesome. That would be sweet if you made a Spotify remake tutorial, I've always been intrigued by that app

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +6

      Thanks, I'll try to put up a Spotify series sometime in February or March.

    • @thinkoreans
      @thinkoreans 8 років тому

      Please. I wish I could learn that nice dragging up menu from the master. So smooth interaction.
      And please consider putting it up on your website after Kindle Basic Training. It’s too good a skill to be handed out free.

  • @mirsha3054
    @mirsha3054 8 років тому

    I just came from school very tired, but seeing you posted another video made my day man, thank you so much, Cheers!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +1

      Glad I could brighten up your day from the misery that is school. Hope you make it through, as I had tough times in college myself.

  • @cinquain0
    @cinquain0 6 років тому

    These swift algorithm videos are pure fire!

  • @joycelu962
    @joycelu962 8 років тому

    Your tutorials are always the BEST!! Thank you so very much!!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Thanks a bunch Joyce, always glad to see you poking in to check out the videos.

  • @fabianhaglund5792
    @fabianhaglund5792 8 років тому

    Always enjoy these algorithm videos! Also would love to see you do one on binary tree data structure. Looking forward to next week!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +1

      Thanks Fabian, I'm considering doing a Binary Search algorithm next week. Stay tuned.

  • @pboabang
    @pboabang 8 років тому

    Sir you are a simply a legend, keep up the good work.

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Hey Phil, thanks a lot. More algorithms next week.

  • @cloudytuesdays
    @cloudytuesdays 8 років тому

    #1 Fan I watch every video keep the amazing work!!!! Can't wait to finish the twitter app!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Thanks Matthew, hopefully next tuesday I'll be able to put up another twitter episode.

  • @DW-cg8vy
    @DW-cg8vy 4 роки тому +1

    Impressed by your video. I have a question
    Can someone explain how when you add ‘ || playlist.count > 0 ‘ an “e” gets appended to playlist variable ? Doesn’t an if statement check its conditions first before it executes what’s inside the bracket ? How does swift allow this ? What am I missing ?

    • @dre5671
      @dre5671 2 роки тому

      Super late, but playlist.count will begin at 0, so that condition will be false until the first condition “track == selectedTrack” is true.
      When that first condition is true, then “playlist” will append, and the count is now 1.
      So now, that second condition will always be true, appending every track.

  • @dre5671
    @dre5671 2 роки тому

    That “playlist.count > 0” is genius!

  • @cinquain0
    @cinquain0 2 роки тому

    You need to bring the algorithm series back Brian.

  • @andreychirkov1904
    @andreychirkov1904 8 років тому

    Hi, Brian! How are you doing? Very interesting video! I like swift algorithms series very much. It is very helpful when you go to the next stage from view representation to program logic. Thank you!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      +Andrey Chirkov great to know these videos are helping a lot of people out there, more to come this Friday

  • @brahimelmssilha7234
    @brahimelmssilha7234 7 років тому

    Maaan I love your videos, keep up

  • @rafaelrincon3109
    @rafaelrincon3109 7 років тому

    You can break this into separate lines, of course, but it is possible to make a one-line function to handle this task.
    import UIKit
    func wrappedArray(array: [Any], beginningIndex: Int) -> [Any] {
    return [Any](array.suffix(array.count - beginningIndex)) + array.prefix(beginningIndex)
    }
    let ogTracks = ["a", "b", "c", "d", "e"]
    print(ogTracks)
    print(wrappedArray(array: ogTracks, beginningIndex: ogTracks.index(of: "d")!))
    print(wrappedArray(array: ogTracks, beginningIndex: 0))
    print(wrappedArray(array: ogTracks, beginningIndex: ogTracks.count - 1))

  • @bcyourself
    @bcyourself 8 років тому +1

    Can we get more algorithm videos please!

  • @jonahwitcig2628
    @jonahwitcig2628 8 років тому

    could you do a video on how you keep your code clean? best practices and things of that sort?

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Hi Jonah, I'd like to do more of these high level coding videos but its difficult to find good examples.

  • @owenmoore3782
    @owenmoore3782 8 років тому

    +LetsBuildThatApp Under what condition do you use a guard statement?

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +2

      To safely unwrap an optional, I would use an "if let" or "guard let" statement. I would use guards 95% of the time to avoid the pyramid of braces.

  • @imherelul
    @imherelul 8 років тому

    hey brian, for the iOS basic course on your website is their any presumed programming knowledge required?

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Hello imherelul, for the basic course you need to know how to open up Xcode and run the simulator. I walk you through each line of code starting from the first episode so you should be able to follow along if these youtube videos are ok for you.

  • @michaelai1742
    @michaelai1742 8 років тому

    Hi Brian, I had a question about appending array elements, For example in an app where we get data from the web and append the data into an empty array to display for the user, is this bad for the memory? Because if elements keep getting added then the size of the array will become too large. What is the best way to do this?

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      If you're just starting out, you don't need to worry about the complexities of memory management. Just have fun.

  • @sami790311
    @sami790311 7 років тому

    Great videos, Brian! I watch them every morning with my coffee, before work :)
    Regarding the algorithm. What if I keep the index of the current track and just increment it as the new track starts playing. If the index == tracks.count -1 then index = 0. Would that work the same way?

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому +1

      Seems like resetting the index should work that way, or you can use modular math to convert the index.

  • @superwsuperw
    @superwsuperw 8 років тому

    Great video!
    Why is calling suffix method includes the track "d" while prefix does not?

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Suffix works by omitting the from index element.

  • @fawadfarooq
    @fawadfarooq 8 років тому

    xcellent Brian ! you are super guy !

  • @misc.2331
    @misc.2331 8 років тому

    What if we had an array of elements where the same element could show up 2 (or more) times, would a solution be to store the index of the last occurrence of the element and then wrap back around to the beginning of the array up to the index of that element? Just a thought experiment. I love these kinds of problems.
    BTW, I recently found your channel and am really enjoying the content! Cheers.

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +1

      Good question, I didn't run into this scenario when building out my audio app. Depending on how the UI works, you might be able to attain the element index from the UI and you wouldn't have to worry about duplicates.

  • @discopotato7380
    @discopotato7380 8 років тому

    oh okay and also do I need to learn c++ before java
    are they related in anyway

  • @hanisster
    @hanisster 8 років тому

    Hi Brian how about doing a video on how to design code that are ARC memory friendly? Cause right now I'm having problems memory not releasing after dismissing or pop, especially on image slideshow/carousel..
    Btw thanks to your video I'm now able to develop VCs in code not using storyboard at all 🙂

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      As long as you are careful of retain cycles and use weak references when possible, you should be ok.

  • @donpaulpm
    @donpaulpm 8 років тому +1

    more complex algorithms... i have ask for how offline and online works i.e.. i have registered but no network but I should store the value and move next and when I come online ,automatically, upload datas.... so user will not feel distracted for registration purpose..😍 pls tell me how to solve that .. hope you will ans

    • @madmax1786
      @madmax1786 8 років тому +2

      I think theres a framework that can help you, its called Reachability. It keeps listening for network availability and then you can upload data whenever the user gets online.

    • @donpaulpm
      @donpaulpm 8 років тому

      Gabriel den Hartog name of the frame work....😊

  • @Weiwuzu
    @Weiwuzu 5 років тому

    Anybody know if the time complexity of getting prefix and suffix is O(1)?

  • @liamnewgen7619
    @liamnewgen7619 7 років тому

    Dude this was awesome =)

  • @Seb16291629
    @Seb16291629 7 років тому

    How do you come up with that! That s amazing, I dont know how I could come up with such solution. Do you find it by trying out for hours or these are things your learn from experience? Thanks, Seb

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому +1

      Usually these exercises come from projects that I've worked on and because I find them interesting I provide a small exercise based on it.

  • @mexicanguy6041
    @mexicanguy6041 7 років тому

    Hey would you say its important today to learn obj-c and swift? Or there is no real need to learn obj-c anymore?

    • @LetsBuildThatApp
      @LetsBuildThatApp  7 років тому

      I think you can learn Swift to land a junior iOS job, and then you might need to learn ObjC syntax on the job.

  • @top3d337
    @top3d337 8 років тому

    Hey Brian!
    Can you make a tutorial on how to make an algorythm to summarize text? I am searching so long for something like that!
    It would really help me out.
    Lars,

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      If you can give me a clear example, I can put up a video on this.

    • @top3d337
      @top3d337 8 років тому

      I mean a function that summarizes a text automatically by its paragraphs and sentences. This is an example: github.com/hyharryhuang/SwiftSummary
      Thanks!

  • @discopotato7380
    @discopotato7380 8 років тому

    hey @lets build that app
    where do you work right now ?!

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +1

      Hello disco, I currently do not work full time. All my time is occupied with contracting and keeping this youtube channel alive along with my website.

  • @taylormaxwell1277
    @taylormaxwell1277 5 років тому

    Very helpful

  • @washemas8272
    @washemas8272 8 років тому +1

    import UIKit
    var array = ["1","2","3","4","5","6"]
    var newArray = [String]()
    let selectedItem = "5"
    let selectedIndex = array.index(of: selectedItem)
    var newIndex = selectedIndex
    for index in 1...array.count {
    newArray.append(array[newIndex!])
    if newIndex == array.count - 1 {
    newIndex = 0
    } else {
    newIndex! += 1
    }
    }

  • @iamwaseem99
    @iamwaseem99 8 років тому

    awesome bro

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому +2

      Thanks waseem, more algorithms next week.

    • @iamwaseem99
      @iamwaseem99 8 років тому

      Lets Build That App i am waiting 😍😍

  • @Dj_Realest
    @Dj_Realest 5 років тому

    func wrapArray(array: [String], splitAtIndex: Int) -> [String] {
    if splitAtIndex >= 0 && splitAtIndex

  • @pysuhayb15
    @pysuhayb15 8 років тому

    python is my language

    • @LetsBuildThatApp
      @LetsBuildThatApp  8 років тому

      Thats great, I'd like to get better at python myself.

  • @vinzent3864
    @vinzent3864 8 років тому

    Do you like Taylor Swift?